static void flame_collision (PELEMENT ElementPtr0, PPOINT pPt0, PELEMENT ElementPtr1, PPOINT pPt1) { weapon_collision (ElementPtr0, pPt0, ElementPtr1, pPt1); ElementPtr0->state_flags &= ~DISAPPEARING; ElementPtr0->state_flags |= NONSOLID; }
static void howitzer_collision (PELEMENT ElementPtr0, PPOINT pPt0, PELEMENT ElementPtr1, PPOINT pPt1) { if ((ElementPtr0->state_flags & (GOOD_GUY | BAD_GUY)) != (ElementPtr1->state_flags & (GOOD_GUY | BAD_GUY))) weapon_collision (ElementPtr0, pPt0, ElementPtr1, pPt1); }
static void blaster_collision (ELEMENT *ElementPtr0, POINT *pPt0, ELEMENT *ElementPtr1, POINT *pPt1) { HELEMENT hBlastElement; hBlastElement = weapon_collision (ElementPtr0, pPt0, ElementPtr1, pPt1); if (hBlastElement) { ELEMENT *BlastElementPtr; LockElement (hBlastElement, &BlastElementPtr); switch (ElementPtr0->mass_points) { case BLASTER_DAMAGE * 1: BlastElementPtr->life_span = 2; BlastElementPtr->current.image.frame = SetAbsFrameIndex (ElementPtr0->current.image.frame, 0); BlastElementPtr->preprocess_func = NULL; break; case BLASTER_DAMAGE * 2: BlastElementPtr->life_span = 6; BlastElementPtr->current.image.frame = IncFrameIndex (ElementPtr0->current.image.frame); break; case BLASTER_DAMAGE * 3: BlastElementPtr->life_span = 7; BlastElementPtr->current.image.frame = SetAbsFrameIndex (ElementPtr0->current.image.frame, 20); break; } UnlockElement (hBlastElement); } }
static void crystal_collision (ELEMENT *ElementPtr0, POINT *pPt0, ELEMENT *ElementPtr1, POINT *pPt1) { HELEMENT hBlastElement; hBlastElement = weapon_collision (ElementPtr0, pPt0, ElementPtr1, pPt1); if (hBlastElement) { ELEMENT *BlastElementPtr; LockElement (hBlastElement, &BlastElementPtr); BlastElementPtr->current.location = ElementPtr1->current.location; BlastElementPtr->life_span = NUM_SPARKLES; BlastElementPtr->turn_wait = BlastElementPtr->next_turn = 0; { BlastElementPtr->preprocess_func = animate; } BlastElementPtr->current.image.farray = ElementPtr0->next.image.farray; BlastElementPtr->current.image.frame = SetAbsFrameIndex (BlastElementPtr->current.image.farray[0], 2); /* skip stones */ UnlockElement (hBlastElement); } }
static void twin_laser_collision (ELEMENT *ElementPtr0, POINT *pPt0, ELEMENT *ElementPtr1, POINT *pPt1) { if (!(ElementPtr1->state_flags & PLAYER_SHIP) || !(ElementPtr0->state_flags & ElementPtr1->state_flags & (GOOD_GUY | BAD_GUY))) weapon_collision (ElementPtr0, pPt0, ElementPtr1, pPt1); }
void weapon_collision(entity *owner) { int i; if(!owner || !owner->weapon) { slog("Entity or Weapon is NULL. No Collision"); } for(i = 0; i < ENTITY_MAX; i++){ if(!entityList[i].inuse){ continue; } if(!entityList[i].update){ continue; } if(owner == &entityList[i]){ continue; } if(owner->weapon && owner->weapon->active){ switch(owner->weapon->face_dir){ case UP: weapon_collision(owner, &entityList[i], owner->weapon->boundUp); break; case DOWN: weapon_collision(owner, &entityList[i], owner->weapon->boundDown); break; case LEFT: weapon_collision(owner, &entityList[i], owner->weapon->boundLeft); break; case RIGHT: weapon_collision(owner, &entityList[i], owner->weapon->boundRight); break; default: break; } } } }
static void buzzsaw_collision (ELEMENT *ElementPtr0, POINT *pPt0, ELEMENT *ElementPtr1, POINT *pPt1) { weapon_collision (ElementPtr0, pPt0, ElementPtr1, pPt1); if (ElementPtr0->state_flags & DISAPPEARING) { ElementPtr0->state_flags &= ~DISAPPEARING; ElementPtr0->state_flags |= NONSOLID | CHANGING; ElementPtr0->life_span = 5; ElementPtr0->next.image.frame = SetAbsFrameIndex (ElementPtr0->current.image.frame, 2); ElementPtr0->preprocess_func = splinter_preprocess; } }
static void pump_up_collision (ELEMENT *ElementPtr0, POINT *pPt0, ELEMENT *ElementPtr1, POINT *pPt1) { RECT r; BYTE old_thrust_wait; HELEMENT hBlastElement; GetFrameRect (ElementPtr0->next.image.frame, &r); old_thrust_wait = ElementPtr0->thrust_wait; ElementPtr0->blast_offset = r.extent.width >> 1; hBlastElement = weapon_collision (ElementPtr0, pPt0, ElementPtr1, pPt1); // This new section kills suspended blaster pulses after sustaining massive burst damage. if (ElementPtr1->mass_points >= ElementPtr0->mass_points) { ElementPtr0->postprocess_func = 0; ElementPtr0->thrust_wait = 0; ElementPtr0->state_flags |= DISAPPEARING; } else ElementPtr0->thrust_wait = old_thrust_wait; if (hBlastElement) { ELEMENT *BlastElementPtr; LockElement (hBlastElement, &BlastElementPtr); BlastElementPtr->life_span = MIN_PUMPITUDE_ANIMS + (ElementPtr0->turn_wait & ~REVERSE_DIR); BlastElementPtr->turn_wait = BlastElementPtr->next_turn = 0; { BlastElementPtr->preprocess_func = animate; } BlastElementPtr->current.image.farray = ElementPtr0->next.image.farray; BlastElementPtr->current.image.frame = SetAbsFrameIndex (BlastElementPtr->current.image.farray[0], MAX_PUMP * NUM_PUMP_ANIMS); UnlockElement (hBlastElement); } }
static void blazer_collision (ELEMENT *ElementPtr0, POINT *pPt0, ELEMENT *ElementPtr1, POINT *pPt1) { #define BLAZER_OFFSET (10 << RESOLUTION_FACTOR) // JMS_GFX BYTE old_offs; COUNT old_crew_level; COUNT old_life; old_crew_level = ElementPtr0->crew_level; old_life = ElementPtr0->life_span; old_offs = ElementPtr0->blast_offset; ElementPtr0->blast_offset = BLAZER_OFFSET; ElementPtr0->mass_points = BLAZER_DAMAGE; weapon_collision (ElementPtr0, pPt0, ElementPtr1, pPt1); ElementPtr0->mass_points = BLAZER_MASS; ElementPtr0->blast_offset = old_offs; ElementPtr0->life_span = old_life; ElementPtr0->crew_level = old_crew_level; ElementPtr0->state_flags &= ~(DISAPPEARING | NONSOLID); collision (ElementPtr0, pPt0, ElementPtr1, pPt1); }
static void cannon_collision (ELEMENT *ElementPtr0, POINT *pPt0, ELEMENT *ElementPtr1, POINT *pPt1) { weapon_collision (ElementPtr0, pPt0, ElementPtr1, pPt1); if ((ElementPtr1->state_flags & PLAYER_SHIP) && ElementPtr1->crew_level && !GRAVITY_MASS (ElementPtr1->mass_points + 1)) { COUNT angle; SIZE cur_delta_x, cur_delta_y; STARSHIP *StarShipPtr; GetElementStarShip (ElementPtr1, &StarShipPtr); StarShipPtr->cur_status_flags &= ~(SHIP_AT_MAX_SPEED | SHIP_BEYOND_MAX_SPEED); angle = FACING_TO_ANGLE ( GetFrameIndex (ElementPtr0->next.image.frame) ); DeltaVelocityComponents (&ElementPtr1->velocity, COSINE (angle, RECOIL_VELOCITY), SINE (angle, RECOIL_VELOCITY)); GetCurrentVelocityComponents (&ElementPtr1->velocity, &cur_delta_x, &cur_delta_y); if ((long)cur_delta_x * (long)cur_delta_x + (long)cur_delta_y * (long)cur_delta_y > (long)MAX_RECOIL_VELOCITY * (long)MAX_RECOIL_VELOCITY) { angle = ARCTAN (cur_delta_x, cur_delta_y); SetVelocityComponents (&ElementPtr1->velocity, COSINE (angle, MAX_RECOIL_VELOCITY), SINE (angle, MAX_RECOIL_VELOCITY)); } } }
static void pump_up_collision (ELEMENT *ElementPtr0, POINT *pPt0, ELEMENT *ElementPtr1, POINT *pPt1) { RECT r; BYTE old_thrust_wait; HELEMENT hBlastElement; GetFrameRect (ElementPtr0->next.image.frame, &r); old_thrust_wait = ElementPtr0->thrust_wait; ElementPtr0->blast_offset = r.extent.width >> 1; hBlastElement = weapon_collision (ElementPtr0, pPt0, ElementPtr1, pPt1); ElementPtr0->thrust_wait = old_thrust_wait; if (hBlastElement) { ELEMENT *BlastElementPtr; LockElement (hBlastElement, &BlastElementPtr); BlastElementPtr->life_span = MIN_PUMPITUDE_ANIMS + (ElementPtr0->turn_wait & ~REVERSE_DIR); BlastElementPtr->turn_wait = BlastElementPtr->next_turn = 0; { BlastElementPtr->preprocess_func = animate; } BlastElementPtr->current.image.farray = ElementPtr0->next.image.farray; BlastElementPtr->current.image.frame = SetAbsFrameIndex (BlastElementPtr->current.image.farray[0], MAX_PUMP * NUM_PUMP_ANIMS); UnlockElement (hBlastElement); } }
void player_attack(SDL_Event *e){ Vec2d p; if(!e){ fprintf(stdout,"Player_Move sdl event e is null"); return; } switch(e->type){ case SDL_MOUSEBUTTONDOWN: if(selecting_struct) { selecting_struct = false; set_hud_state(HUD_state::inventory1); structure_place(); } break; case SDL_KEYDOWN: switch( e->key.keysym.sym ) { case SDLK_q: slog("Q press"); p.y = player->position.y + player->sprite->frameH * 3 / 4; p.x = player->position.x; particle_em_add(player->p_em, PARTICLE_SPELLCAST, p); break; case SDLK_i: set_hud_state(HUD_state::inventory1); break; case SDLK_b: in_build_mode_01 = set_hud_state(HUD_state::build1); break; case SDLK_v: if(in_build_mode_01) { structure_select(struct_type::main_base01); selecting_struct =!selecting_struct; } case SDLK_m: if(in_build_mode_01) { structure_select(struct_type::wall_01); selecting_struct =!selecting_struct; } case SDLK_t: if(in_build_mode_01) { structure_select(struct_type::tower_01); selecting_struct =!selecting_struct; } case SDLK_f: slog("Press F"); if(animCurrent != SLASH && player_tree_collision()) { animCurrent = SLASH; player->sprite->fpl = playerBody.image_slash->fpl; player->sprite = playerBody.image_slash; player->frame_horizontal = 0;//reset it; } break; } break; default: break; } switch( e->key.keysym.sym ) { case SDLK_SPACE: //if(player_struct.weapon == WEAP_SWORD) if(animCurrent != SLASH) { animCurrent = SLASH; PlayerEquip.fpl = PlayerEquip.weapon->fpl; player->sprite->fpl = PlayerEquip.fpl; player->frame_horizontal = 0;//reset it; player->sprite = playerBody.image_slash; //used for collision player->weapon->active = true; weapon_collision(player); } break; default: break; } }