bool Bullet::logic(int step) { lifetime -= step; if (lifetime <= 0) return false; dx = speed * cosa * step; dy = speed * sina * step; Entity *c; if (playerOnly) c = getPlayerCollision(); else c = getAllCollision(); if (c && c != shooter) { c->hit(damage); my_play_sample(RES_COLLISION); return false; } Entity::wrap(); if (!Entity::logic(step)) return false; return true; }
Entity *Entity::getAllCollision(void) { Entity *e = getEntityCollision(); if (e) return e; return getPlayerCollision(); }
bool Asteroid::logic(int step) { angle -= da * step; Player *p = (Player *)getPlayerCollision(); if (p) { explode(); p->hit(1); my_play_sample(RES_COLLISION); return false; } dx = speed_x * step; dy = speed_y * step; Entity::wrap(); if (!Entity::logic(step)) return false; return true; }
bool PowerUp::logic(int step) { angle += da * step; x += dx; y += dy; if (x < -radius || x > BB_W+radius || y < -radius || y > BB_H+radius) { return false; } Player *p = (Player *)getPlayerCollision(); if (p) { p->givePowerUp(type); my_play_sample(RES_POWERUP); return false; } if (!Entity::logic(step)) return false; return true; }