Project

General

Profile

Revision 216

many changes. implemented collision detection

View differences:

proj.c
24 24
#include "pistol.h"
25 25
#include "nothing.h"
26 26
#include "bullet.h"
27
#include "map.h"
27
#include "map1.h"
28 28

  
29 29
int main(int argc, char* argv[]) {
30 30

  
......
59 59
    }
60 60

  
61 61
    /// Load stuff
62
    basic_sprite_t *bsp_crosshair = NULL;
63
    basic_sprite_t *bsp_shooter   = NULL;
64
    basic_sprite_t *bsp_pistol    = NULL;
65
    basic_sprite_t *bsp_nothing   = NULL;
66
    sprite_t       *sp_crosshair  = NULL;
62
    basic_sprite_t       *bsp_crosshair = NULL;
63
    basic_sprite_t       *bsp_shooter   = NULL;
64
    basic_sprite_t       *bsp_pistol    = NULL;
65
    basic_sprite_t       *bsp_nothing   = NULL;
66
    map_t                *map1      = NULL;
67
    sprite_t             *sp_crosshair  = NULL;
67 68
    {
68 69
        graph_clear_screen();
69 70
        text_t *txt = text_ctor(consolas, "Loading...");
......
75 76
        bsp_shooter   = get_shooter  (); if(bsp_shooter   == NULL) printf("Failed to get shooter\n");
76 77
        bsp_pistol    = get_pistol   (); if(bsp_pistol    == NULL) printf("Failed to get pistol\n");
77 78
        bsp_nothing   = get_nothing  (); if(bsp_nothing   == NULL) printf("Failed to get nothing\n");
79
        map1          = get_map1     (); if(map1          == NULL) printf("Failed to get map1\n");
78 80

  
79 81
        sp_crosshair = sprite_ctor(bsp_crosshair); if(sp_crosshair == NULL) printf("Failed to get crosshair sprite\n");
80 82
    }
......
109 111
    #endif
110 112

  
111 113
    #ifdef TELMO
112
        ent_set_scale(10.0);
114
        ent_set_scale(DEFAULT_SCALE);
113 115

  
114 116
        gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol); if(shooter1 == NULL) printf("Failed to get shooter1\n");
115 117
        gunner_set_pos(shooter1, 0, 0);
......
120 122
        bullet_t *bullet = bullet_ctor(get_bullet());
121 123
        bullet_set_pos(bullet, 400, 400);
122 124

  
123
        ent_set_origin(bullet_get_x(bullet)-ent_get_XLength()/2.0,
124
                       bullet_get_y(bullet)-ent_get_YLength()/2.0);
125
        ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
126
                       gunner_get_y(shooter1)-ent_get_YLength()/2.0);
125 127

  
126
        graph_clear_screen();
127
        gunner_draw(shooter1);
128
        sprite_draw(sp_crosshair);
129
        graph_draw();
130

  
131 128
        uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
132

  
133
        basic_sprite_t *bsp_pink = get_map();
134
        sprite_t *pink = sprite_ctor(bsp_pink);
135
        basic_sprite_dtor(bsp_pink);
136 129
    #endif
137 130

  
138 131
    /// loop stuff
......
161 154
                            if (i == 0) {
162 155
                                if (no_interrupts % refresh_count_value == 0) {
163 156
                                    update_movement(shooter1);
157

  
158
                                    if(map_collides(map1, gunner_get_x(shooter1), gunner_get_y(shooter1))){
159
                                        printf("COLLIDING\n");
160
                                    }
161

  
164 162
                                    update_scale();
165 163

  
166
                                    ent_set_origin(bullet_get_x(bullet)-ent_get_XLength()/2.0,
167
                                                   bullet_get_y(bullet)-ent_get_YLength()/2.0);
164
                                    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
165
                                                   gunner_get_y(shooter1)-ent_get_YLength()/2.0);
168 166

  
169 167
                                    sprite_set_pos(sp_crosshair, get_mouse_X(), get_mouse_Y());
170 168
                                    double angle = get_mouse_angle(shooter1);
......
173 171

  
174 172
                                    clock_t t = clock();
175 173

  
176
                                    sprite_draw(pink);
174
                                    map_draw   (map1);
177 175
                                    gunner_draw(shooter2);
178 176
                                    gunner_draw(shooter1);
179 177
                                    bullet_draw(bullet);
......
207 205

  
208 206
    #ifdef TELMO
209 207
        gunner_dtor(shooter1); shooter1 = NULL;
210
        sprite_dtor(pink); pink = NULL;
208
        gunner_dtor(shooter2); shooter2 = NULL;
209
        bullet_dtor(bullet); bullet = NULL;
211 210
    #endif
212 211

  
213
    basic_sprite_dtor(bsp_crosshair); bsp_crosshair = NULL;
214
    basic_sprite_dtor(bsp_shooter  ); bsp_shooter   = NULL;
215
    sprite_dtor      (sp_crosshair ); sp_crosshair  = NULL;
216
    font_dtor        (consolas     ); consolas      = NULL;
212
    basic_sprite_dtor      (bsp_crosshair); bsp_crosshair = NULL;
213
    basic_sprite_dtor      (bsp_shooter  ); bsp_shooter   = NULL;
214
    sprite_dtor            (sp_crosshair ); sp_crosshair  = NULL;
215
    basic_sprite_dtor      (bsp_pistol   ); bsp_pistol    = NULL;
216
    basic_sprite_dtor      (bsp_nothing  ); bsp_nothing   = NULL;
217
    map_dtor               (map1         ); map1          = NULL;
218
    font_dtor              (consolas     ); consolas      = NULL;
217 219

  
218 220
    // Unsubscribe interrupts
219 221
    if (unsubscribe_all()) {

Also available in: Unified diff