void weapon_collide(Entity *ent, cpArbiter *arb) { cpBody *body = entity_body(ent); cpBody *other = physics_arbiter_get_other(body, arb); Entity *other_ent = cpBodyGetUserData(other); //only damage players if (!entity_valid(other_ent) || entity_type(other_ent) != &PlayerEntity) { return; } //only damage enemies if (entity_owner(ent) != connection_get_user_id() || entity_owner(other_ent) == connection_get_user_id()) { return; } float speed = cpvlength(cpBodyGetVelocity(body)); if (speed < WEAPON_HURT_THRESHOLD) { return; } player_hurt(entity_owner(other_ent), WEAPON_DAMAGE * speed, entity_owner(ent)); }
void player_kick(int dx, int dy) { struct map_square *sq; sq = map_square(player.level->map, player.x + dx, player.y + dy); if(!sq) return; if(sq->monster) { msg_printf("You kick the %s!", monster_name(sq->monster)); return; } switch(sq->tile) { case TILE_DOOR_CLOSED: if(test_stat(&player.stats, STAT_STR, 0)) { sq->tile = TILE_DOOR_BORKED; msg_printf("The door crashes open!"); } else msg_printf("You kick the door hard, but it won't budge."); exercise_stat(&player.stats_exe, STAT_STR, 1); break; case TILE_WALL_HORIZ: case TILE_WALL_VERT: msg_printf("You kick the wall. Ouch!"); player_hurt(5); break; default: msg_printf("You kick at empty space."); exercise_stat(&player.stats_exe, STAT_DEX, -1); break; } }
// This is the kitten's callback, // all its actions take place here void kitten_move(gpointer kittyp) { Kitten * kitty; Entity * player; Level world; TimeTracker * time; EntitySet * others; float x, y; float px, py; float dx, dy; unsigned int dir; Entity * body; Player * dude; kitty = (Kitten *) kittyp; player = kitty->player; world = kitty->world; time = kitty->time; others = kitty->others; body = kitty->body; entity_position(body, &x, &y); entity_position(player, &px, &py); dir = look(x, y, px, py); dx = px - x; dy = py - y; entity_set_direction(body, dx, dy); entity_move(body, world, time, others); entity_get_direction(body, &dx, &dy); if (collision(body, x + dx, y + dy, others) == player) { if (expired(kitty->claw_timer)) { play_wav(kitty->claw); } if (expired(kitty->attack_timer)) { dude = entity_user_data(player); player_hurt(dude); } if (dir == LEFT) { set_animation(body, "attack_left"); } else if (dir == RIGHT) { set_animation(body, "attack_right"); } else if (dir == UP) { set_animation(body, "attack_up"); } else if (dir == DOWN) { set_animation(body, "attack_down"); } } else if (dir == LEFT) { set_animation(body, "left"); } else if (dir == RIGHT) { set_animation(body, "right"); } else if (dir == UP) { set_animation(body, "up"); } else if (dir == DOWN) { set_animation(body, "down"); } }