Project

General

Profile

Revision 220

gunner collisions

View differences:

ent.c
5 5
#include "graph.h"
6 6
#include "sprite.h"
7 7

  
8
#include <math.h>
9

  
8 10
static double scale = 1.0;
9 11
static int16_t x_origin = 0;
10 12
static int16_t y_origin = 0;
......
133 135
}
134 136
int16_t (map_get_x_screen)(const map_t *p){ return (-x_origin)*scale; }
135 137
int16_t (map_get_y_screen)(const map_t *p){ return (-y_origin)*scale; }
136
int (map_collides)(const map_t *p, double x, double y){
138
int (map_collides_point)(const map_t *p, double x, double y){
137 139
    const uint16_t w = sprite_get_w(p->background), h = sprite_get_h(p->background);
138 140
    int16_t x_ = x, y_ = y;
139 141
    if(x_ < 0 || w <= x_ || y_ < 0 || h <= y_) return 0;
140 142
    uint32_t pos = x_ + y_*w;
141 143
    return p->collide[pos];
142 144
}
145

  
146
int (map_collides_gunner)(const map_t *p, gunner_t *shooter) {
147
    double radius = sprite_get_w(shooter->dude)/2.0;
148
    double shooter_x = gunner_get_x(shooter);
149
    for (double x = shooter_x - radius; x < shooter_x + radius; x += 1) {
150
        double y1 = sqrt(1 - x*x);
151
        double y2 = -y1;
152
        if (map_collides_point(p, x, y1) || map_collides_point(p, x, y2)) return 1;
153
    }
154
    return 0;
155
}
156

  
157
int (map_collides_bullet)(const map_t *p, bullet_t *bullet) {
158
    return 0;
159
}
160

  
143 161
void   (map_draw)(map_t *p){
144 162
    const int16_t x_screen = map_get_x_screen(p);
145 163
    const int16_t y_screen = map_get_y_screen(p);

Also available in: Unified diff