Project

General

Profile

Revision 193

forgot files

View differences:

proj/include/ent.h
1
#ifndef ENT_H_INCLUDED
2
#define ENT_H_INCLUDED
3

  
4
#include "sprite.h"
5

  
6
void (ent_set_scale) (double n);
7
void (ent_set_origin)(double x, double y);
8

  
9
double (ent_get_XLength)(void);
10
double (ent_get_YLength)(void);
11

  
12
struct ent;
13
typedef struct ent ent_t;
14

  
15
ent_t* (ent_ctor)(basic_sprite_t *dude, basic_sprite_t *weapon);
16
void   (ent_dtor)(ent_t *p);
17

  
18
void (ent_set_pos)  (ent_t *p, int16_t x, int16_t y);
19
void (ent_set_angle)(ent_t *p, double angle        );
20

  
21
double  (ent_get_x)       (const ent_t *p);
22
double  (ent_get_y)       (const ent_t *p);
23
int16_t (ent_get_x_screen)(const ent_t *p);
24
int16_t (ent_get_y_screen)(const ent_t *p);
25

  
26
void (ent_draw)(ent_t *p);
27

  
28
#endif //ENT_H_INCLUDED
0 29

  
proj/src/ent.c
1
#include <lcom/lcf.h>
2

  
3
#include "ent.h"
4

  
5
#include "graph.h"
6

  
7
static double scale = 1.0;
8
static int16_t x_origin = 0;
9
static int16_t y_origin = 0;
10

  
11
void (ent_set_scale) (double n){ scale = n; }
12
void (ent_set_origin)(double x, double y){ x_origin = x; y_origin = y; }
13

  
14
double (ent_get_XLength)(void){ return graph_get_XRes()/scale; }
15
double (ent_get_YLength)(void){ return graph_get_YRes()/scale; }
16

  
17
struct ent{
18
    double x, y; //real position in meters
19
    sprite_t *dude;
20
    sprite_t *weapon;
21
};
22

  
23
ent_t* (ent_ctor)(basic_sprite_t *dude, basic_sprite_t *weapon){
24
    ent_t *ret = malloc(sizeof(ent_t));
25
    if(ret == NULL) return NULL;
26
    ret->x = 0.0;
27
    ret->y = 0.0;
28
    ret->dude   = sprite_ctor(dude  );
29
    ret->weapon = sprite_ctor(weapon);
30
    if(ret->dude == NULL || ret->weapon == NULL){
31
        ent_dtor(ret);
32
        return NULL;
33
    } else return ret;
34
}
35
void (ent_dtor)(ent_t *p){
36
    if(p == NULL) return;
37
    sprite_dtor(p->dude);
38
    sprite_dtor(p->weapon);
39
    free(p);
40
}
41

  
42
void (ent_set_pos)  (ent_t *p, int16_t x, int16_t y){ p->x = x; p->y = y; }
43
void (ent_set_angle)(ent_t *p, double angle        ){
44
    sprite_set_angle(p->dude  , angle);
45
    sprite_set_angle(p->weapon, angle);
46
}
47

  
48
double  (ent_get_x)       (const ent_t *p){ return p->x; }
49
double  (ent_get_y)       (const ent_t *p){ return p->y; }
50
int16_t (ent_get_x_screen)(const ent_t *p){ return (p->x-x_origin)*scale; }
51
int16_t (ent_get_y_screen)(const ent_t *p){ return (p->y-y_origin)*scale; }
52

  
53
void (ent_draw)(ent_t *p){
54
    const int16_t x_screen = ent_get_x_screen(p);
55
    const int16_t y_screen = ent_get_y_screen(p);
56
    sprite_set_pos  (p->dude  , x_screen, y_screen);
57
    sprite_set_pos  (p->weapon, x_screen, y_screen);
58
    sprite_set_scale(p->dude  , scale);
59
    sprite_set_scale(p->weapon, scale);
60
    sprite_draw     (p->weapon);
61
    sprite_draw     (p->dude  );
62
}
0 63

  
proj/xpm/nothing.h
1
#ifndef NOTHING_H_INCLUDED
2
#define NOTHING_H_INCLUDED
3

  
4
#include "nothing.xpm"
5
#include "sprite.h"
6

  
7
basic_sprite_t* get_nothing(void){
8
    return basic_sprite_ctor((const char **)nothing_xpm, 34, 34);
9
}
10

  
11
#endif //NOTHING_H_INCLUDED
0 12

  
proj/xpm/pistol.h
1
#ifndef PISTOL_H_INCLUDED
2
#define PISTOL_H_INCLUDED
3

  
4
#include "pistol.xpm"
5
#include "sprite.h"
6

  
7
basic_sprite_t* get_pistol(void){
8
    return basic_sprite_ctor((const char **)pistol_xpm, 34, 34);
9
}
10

  
11
#endif //PISTOL_H_INCLUDED
0 12

  

Also available in: Unified diff