/* Right key pressed movement @argument Tetris_Shape */ bool Board::move_right(Tetris_Shape &shape) { shape.x(shape.x() + 1); if (collision_right(shape)) { shape.x(shape.x() - 1); return false; } return true; }
Collision detect_world_collision(CollisionData c, int map_width) { struct crate* it = crates; Collision collision; collision.type = NONE_COLLISION; collision.x = 0; collision.y = 0; CollisionResult result; // Map boundaries if(c.player_x <= 0) { collision.type |= BLOCKED_LEFT; return collision; } else if(c.player_right >= map_width) { collision.type |= BLOCKED_RIGHT; return collision; } while(it) { c.obstacle_right = it->x + it->width; c.obstacle_height = it->y - it->height; c.obstacle_x = it->x; c.obstacle_y = it->y; result = collision_down(c); if(result.has) { collision.type |= BLOCKED_DOWN; collision.y = result.y; } result = collision_right(c); if(result.has) { collision.type |= BLOCKED_RIGHT; } result = collision_left(c); if(result.has) { collision.type |= BLOCKED_LEFT; } result = collision_up(c); if(result.has) { collision.type |= BLOCKED_UP; } it = it->next; } return collision; }
GemCollision detect_gem_collision(CollisionData c) { Gems *it = gems; GemCollision collision; collision.gem_id = 0; collision.points = 0; CollisionResult result; while(it) { c.obstacle_right = it->x + it->width; c.obstacle_height = it->y - it->height; c.obstacle_x = it->x; c.obstacle_y = it->y; result = collision_down(c); if(result.has) { collision.gem_id = it->gem_id; collision.points = it->points; break; } result = collision_up(c); if(result.has) { collision.gem_id = it->gem_id; collision.points = it->points; break; } result = collision_left(c); if(result.has) { collision.gem_id = it->gem_id; collision.points = it->points; break; } result = collision_right(c); if(result.has) { collision.gem_id = it->gem_id; collision.points = it->points; break; } it = it->next; } return collision; }
int detect_key_collision(CollisionData c) { if(!key) return 0; c.obstacle_right = key->x + key->width; c.obstacle_height = key->y - key->height; c.obstacle_x = key->x; c.obstacle_y = key->y; if(collision_down(c).has) return 1; if(collision_up(c).has) return 1; if(collision_left(c).has) return 1; if(collision_right(c).has) return 1; return 0; }
bool Board::is_collision(const Tetris_Shape &shape) { bool result = false; if (collision_left(shape)) { return true; } if (collision_right(shape)) { return true; } if (collision_below(shape)) { return true; } return result; }
int detect_enemy_collision(CollisionData c) { if(!enemies) return 0; Enemy *it = enemies; while(it) { c.obstacle_right = it->x + it->width; c.obstacle_height = it->y - it->height; c.obstacle_x = it->x; c.obstacle_y = it->y; if(collision_down(c).has) return 1; if(collision_up(c).has) return 1; if(collision_left(c).has) return 1; if(collision_right(c).has) return 1; it = it->next; } return 0; }