EDirect Collision::GetCollisionDir(RECT _rect1, RECT _rect2) { if (IsCollision(_rect1, _rect2)) { float top = abs(_rect1.top - _rect2.bottom); float botom =abs(_rect1.bottom - _rect2.top); float left = abs(_rect1.left - _rect2.right); float right = abs(_rect1.right - _rect2.left); float rs = min(min(right, left), min(top,botom)); if (rs == top) { return Top; } if (rs == botom) { return Bottom; } if (rs == left) { return Left; } if (rs == right) { return Right; } } return None; }
void Board::MoveDown() { y++; if (IsCollision()) { y--; } }
void Board::Rotate_CounterClockwise() { currentShape.Rotate(false); if (IsCollision()) { Rotate_Clockwise(); } }
void Board::MoveRight() { x++; if (IsCollision()) { x--; } }
void Board::MoveLeft() { x--; if (IsCollision()) { x++; } }
BBox Intersect(BBox rhs) { if (!IsCollision(rhs)) { return {0, 0, 0, 0}; } BBox ret; ret.x = std::max(x, rhs.x); ret.y = std::max(y, rhs.y); ret.w = std::min(x+w, rhs.x+rhs.w) - ret.x; ret.h = std::min(y+h, rhs.y+rhs.h) - ret.y; return ret; }
void GameManager::CheckCollide(Collider* collider, Vector<Target*>& targets) { bool isCollisionChecked = false; //현재 충돌중인 타겟이 있는지 체크 -> lastTarget을 유지할 필요가 있는지 체크 for (Target* target : targets) { if (collider->IsBullet()) { Bullet* bullet = static_cast<Bullet*>(collider); if (IsCollision(target, bullet)) { isCollisionChecked = true; if (bullet->m_currentCollidingTarget == target) { continue; } target->ApplyCollisionEffect(collider); bullet->m_currentCollidingTarget = target; if (target->IsMirror()) { break; } } } else { Explosion* explosion = static_cast<Explosion*>(collider); const float explosionRadius = explosion->GetBoundingRadius(); const Vec2 explosionPosition = explosion->getPosition(); const Rect targetBoundingBox = target->GetBoundingArea(); if ( targetBoundingBox.intersectsCircle( explosionPosition, explosionRadius) ) { target->ApplyCollisionEffect(explosion); } } } //for문 끝 if (!isCollisionChecked) { if (collider->IsBullet()) { Bullet* bullet = static_cast<Bullet*>(collider); if (bullet != nullptr) { bullet->m_currentCollidingTarget = nullptr; } } } }
void ribi::bnkn::SpriteNonMoving::Collision( const SpriteNonMoving& obstacle, SpriteMoving& moving ) { if (!IsCollision(obstacle,moving)) return; /* O - | | dy (in this case > 0) | M - |---| dx (in this case > 0) */ const double dx = moving.getX() - obstacle.getX(); const double dy = moving.getY() - obstacle.getY(); //const double collision_distance // = boost::numeric_cast<double>(obstacle.m_size + moving.m_size) / 2.0; //Obtain the relative angle between the players /* O \ \ \ M angle_players in this case 135 degrees */ const double angle_players = Geometry().GetAngleClockScreen(dx,dy); //Obtain the moving sprite's current impulse double moving_angle = moving.CalcImpulseAngle(); double moving_speed = moving.CalcImpulseSpeed(); //Obstacles have opposite impulse const double pi = boost::math::constants::pi<double>(); double obstacle_angle = moving_angle + pi; double obstancle_speed = moving_speed; //Obtain the new impulses DoPerfectElasticCollision( angle_players, obstacle_angle,obstancle_speed,moving_angle,moving_speed ); //Set the player's new impulse const double dx2 = std::sin(moving_angle) * moving_speed; const double dy2 = -std::cos(moving_angle) * moving_speed; moving.SetSpeed(dx2,dy2); //Let the player move again moving.Move(); }
void Board::Update() { io_service io; deadline_timer t(io, boost::posix_time::milliseconds(lines_info.back().first)); t.wait(); y++; if (IsCollision()) { y--; SaveToBoard(currentShape, x, y); NextShape(); } LineClear(); if(lines_toNextLevel == 0) { lines_info.pop_back(); level++; lines_toNextLevel = lines_info.back().second; speed = lines_info.back().first; } }
EMoveOperations TWayGraph::FindCollisionDirection( const TSegment& point, size_t direction ) const { auto next = point.Slide(EMoveOperations::SLIDE_EAST); if (IsCollision(next, direction)) { return EMoveOperations::SLIDE_EAST; } next = point.Slide(EMoveOperations::SLIDE_WEST); if (IsCollision(next, direction)) { return EMoveOperations::SLIDE_WEST; } next = point.Slide(EMoveOperations::SLIDE_SOUTHEAST); if (IsCollision(next, direction)) { return EMoveOperations::SLIDE_SOUTHEAST; } next = point.Slide(EMoveOperations::SLIDE_SOUTHWEST); if (IsCollision(next, direction)) { return EMoveOperations::SLIDE_SOUTHWEST; } size_t newdirection = direction; if (direction == 0) { newdirection = TurnDirections - 1; } if (IsCollision(point, newdirection)) { return EMoveOperations::ROTATE_CLOCKWISE; } if (direction == TurnDirections - 1) { newdirection = 0; } if (IsCollision(point, newdirection)) { return EMoveOperations::ROTATE_ANTI_CLOCKWISE; } throw TException("Collision direction not found"); return EMoveOperations::COUNT; }
//update the character and ball motions void AnimateFrame(){ //------------------------- //animate the purple player //------------------------- purple_player.x -= purple_player.direction_x * 5; purple_player.y -= purple_player.direction_y * 5; //limit the purple player to the edge of the left goal post if(purple_player.x < 40){ purple_player.x = 40; } //limit the purple player to the edge of the right goal post if(purple_player.x > ( (screen->w)-40-30) ){ purple_player.x = (screen->w)-40-30; } //Keep the purple player off the top of the screen if(purple_player.y < 0 ){ purple_player.y = 0; } //Keep the purple player off the bottom of the screen if(purple_player.y > ( screen->h - purple_player.h) ){ purple_player.y = screen->h - purple_player.h; } //------------------------- //animate the yellow player //------------------------- yellow_player.x -= yellow_player.direction_x * 5; yellow_player.y -= yellow_player.direction_y * 5; //limit the yellow player to the edge of the left goal post if(yellow_player.x < (40+20)){ yellow_player.x = (40+20); } //limit the yellow player to the edge of the right goal post if(yellow_player.x > ( (screen->w)-30-(yellow_player.w) ) ){ yellow_player.x = (screen->w)-30-(yellow_player.w); } //Keep the yellow player off the top of the screen if(yellow_player.y < 0 ){ yellow_player.y = 0; } //Keep the yellow player off the bottom of the screen if(yellow_player.y > ( screen->h - yellow_player.h) ){ yellow_player.y = screen->h - yellow_player.h; } //-------------------------------------- //Check for player to player collisions //-------------------------------------- //Check if the players have collided if(IsCollision(purple_player.x, purple_player.y, purple_player.w, purple_player.h, yellow_player.x, yellow_player.y, yellow_player.w, yellow_player.h) ){ //reset the players to their previous positions if they collide yellow_player.x = yellow_player.prev_x; yellow_player.y = yellow_player.prev_y; purple_player.x = purple_player.prev_x; purple_player.y = purple_player.prev_y; } //------------------------- //Animate the ball //------------------------- //The ball hit the left side of the screen if(ball.x < 5){ ball.direction_x = -1; ~ball.direction_y; } //The ball hit the right side of the screen else if(ball.x > ((screen->w)-ball.w) ){ ball.direction_x = 1; ~ball.direction_y; } //The ball hit the top of the screen if(ball.y < 5){ ball.direction_y = -1; ~ball.direction_x; } //The ball hit the bottom of the screen else if(ball.y > ((screen->h)-ball.h) ){ ball.direction_y = 1; ~ball.direction_x; } //Reset the ball speed on a wall bounce if( (ball.prev_direction_x != ball.direction_x) || (ball.prev_direction_y != ball.direction_y) ){ //ball.x_speed = BALL_X_MAX_SPEED; //ball.y_speed = BALL_Y_MAX_SPEED; } //Slow the ball sprite down over time if((frame_counter % 8) == 1){ //Check if the ball is going the min x speed if(ball.x_speed > BALL_X_MIN_SPEED){ ball.x_speed--; } //Check if the ball is going the min y speed if(ball.y_speed > BALL_Y_MIN_SPEED){ ball.y_speed--; } } //keep the ball X speed above the minimum if(ball.x_speed < BALL_X_MIN_SPEED){ ball.x_speed = BALL_X_MIN_SPEED; } //keep the ball Y speed above the minimum if(ball.y_speed < BALL_Y_MIN_SPEED){ ball.y_speed = BALL_Y_MIN_SPEED; } //------------------------------------ //Check for goals //------------------------------------ //Check if the ball is by left goalpost if((ball.x-(ball.w/2)+(ball.w/2)) < left_goal_rect.x){ //Check if the ball is inside the goalpost section if( (ball.y > left_goal_rect.y+1) && ((ball.y+ball.h) < (left_goal_rect.y+left_goal_rect.h)) ){ //The purple player scored a goal yellow_player.score++; //Reset the ball position ResetLevel(); } } //Check if the ball is by right goalpost if((ball.x+(ball.w)-(ball.w/2)) > right_goal_rect.x){ //Check if the ball is inside the goalpost section if( (ball.y > (right_goal_rect.y+1) ) && ((ball.y+ball.h) < (right_goal_rect.y+right_goal_rect.h)) ){ //The purple player scored a goal purple_player.score++; //Reset the ball position ResetLevel(); } } //------------------------------------ //Check for player to ball collisions //------------------------------------ //Check if the ball hit the yellow player if(IsCollision(ball.x,ball.y, ball.w, ball.h, yellow_player.x, yellow_player.y, yellow_player.w, yellow_player.h) ){ ball.direction_x = 1; //Bounce ball back //~ball.direction_y; //Check if the ball hit the left shoulder of the player if( (yellow_player.y+top_side) > (ball.y+(ball.h/2)) ){ ball.direction_y = 1; } //Check if the ball hit the right shoulder of the player else if( (yellow_player.y+lower_side) < (ball.y+(ball.h/2)) ){ ball.direction_y = -1; } //The ball hit the player staight on else{ ball.direction_y = 0; } //printf("Yellow Player Bounce\n"); //printf("ball_x: %d, ball_y: %d\n", ball.x,ball.y); //printf("player x: %d, player y: %d\n", yellow_player.x, yellow_player.y); ball.x_speed = BALL_X_MAX_SPEED; ball.y_speed = BALL_Y_MAX_SPEED; } //Check if the ball hit the purple player if(IsCollision(ball.x,ball.y, ball.w, ball.h, purple_player.x, purple_player.y, purple_player.w, purple_player.h) ){ ball.direction_x = -1; //~ball.direction_y; //Check if the ball hit the left shoulder of the player if( (purple_player.y+top_side) > (ball.y+(ball.h/2)) ){ ball.direction_y = 1; } //Check if the ball hit the right shoulder of the player else if( (purple_player.y+lower_side) < (ball.y+(ball.h/2)) ){ ball.direction_y = -1; } //The ball hit the player staight on else{ ball.direction_y = 0; } //printf("Purple Player Bounce\n"); //printf("ball_x: %d, ball_y: %d\n", ball.x,ball.y); //printf("player x: %d, player y: %d\n", purple_player.x,purple_player.y); ball.x_speed = BALL_X_MAX_SPEED; ball.y_speed = BALL_Y_MAX_SPEED; } ball.x -= ball.direction_x * ball.x_speed; ball.y -= ball.direction_y * ball.y_speed; //Sprite low bounds check if(ball.x < 0){ ball.x= 0; screen_dirty = 1; } if(ball.y < 0){ ball.y= 0; screen_dirty = 1; } //Sprite high bounds check if(ball.x > screen->w){ ball.x = screen->w; screen_dirty = 1; } if(ball.y > screen->h){ ball.y = screen->h; screen_dirty = 1; } //------------------------- //Animate the ball spin rate //------------------------- if(ball.direction_x == -1){ //Medium-High Speed ball animation if(ball.x_speed > 6){ ball.frame--; } else if( (ball.x_speed > 3) && ( (frame_counter % 2) == 0 )){ ball.frame--; } else if( (ball.x_speed > 1) && ( (frame_counter % 4) == 0 )){ ball.frame--; } //do nothing if the ball x speed is zero //printf("Current Frame: %d, ball frame%d\n", frame_counter, ball.frame); // } else{ //Medium-High Speed ball animation if(ball.x_speed > 6){ ball.frame++; } else if( (ball.x_speed > 3) && ( (frame_counter % 2) == 0 )){ ball.frame++; } else if( (ball.x_speed > 1) && ( (frame_counter % 4) == 0 )){ ball.frame++; } //do nothing if the ball x speed is zero //printf("Current Frame: %d, ball frame%d\n", frame_counter, ball.frame); } //Set the frame limits if(ball.frame < 0){ ball.frame=TOTAL_SOCCER_BALL_FRAMES-1; } if(ball.frame >= TOTAL_SOCCER_BALL_FRAMES){ ball.frame=0; } //------------------------- //Update the game object rects //------------------------- yellow_guy_rect.w = yellow_player.w; yellow_guy_rect.h = yellow_player.h; yellow_guy_rect.x = yellow_player.x; yellow_guy_rect.y = yellow_player.y; purple_guy_rect.w = purple_player.w; purple_guy_rect.h = purple_player.h; purple_guy_rect.x = purple_player.x; purple_guy_rect.y = purple_player.y; yellow_guy_clear_rect.w = yellow_player.w; yellow_guy_clear_rect.h = yellow_player.h; yellow_guy_clear_rect.x = yellow_player.prev_x; yellow_guy_clear_rect.y = yellow_player.prev_y; purple_guy_clear_rect.w = purple_player.w; purple_guy_clear_rect.h = purple_player.h; purple_guy_clear_rect.x = purple_player.prev_x; purple_guy_clear_rect.y = purple_player.prev_y; ball_clear_rect.w = ball.w; ball_clear_rect.h = ball.h; ball_clear_rect.x = ball.prev_x; ball_clear_rect.y = ball.prev_y; //Left Goal post drawing rect left_goal_rect.w = goalPost->w; left_goal_rect.h = goalPost->h; left_goal_rect.x = 22; left_goal_rect.y = (screen->h/2)-(goalPost->h/2); //Right Goal post drawing rect right_goal_rect.w = goalPost->w; right_goal_rect.h = goalPost->h; right_goal_rect.x = screen->w-22; right_goal_rect.y = (screen->h/2)-(goalPost->h/2); }
// Determines the flight path of the projectile void project(double theta,double beta,int tank) { double projx,projz; phy=1; const double fg=1; struct vector { double i,j,m; }; vector P; if (turn==1) { p1mode=1; P.m=s1; } if (turn==2) { p2mode=1; P.m=s2; } P.i=P.m*dcos(theta); P.j=P.m*dsin(theta); printf("%f\n",P.i); if (tank==1) { projx=tank1x; height=tank1y; projz=tank1z; } else { projx=tank2x; height=tank2y; projz=tank2z; } // Delete the previous LL linelist *prev,*now=listf; while (now!=NULL) { prev=now; now=now->next; delete prev; } listf=new linelist; liste=new linelist; listf=liste; listf->next=liste; liste->next=NULL; do { projx+=(P.m*dcos(theta)*dsin(beta))/500; projz+=(P.m*dcos(theta)*dcos(beta))/500; height+=P.j/500; P.j-=fg; linelist *mlist=new linelist; mlist->xl=projx; mlist->yl=height; mlist->zl=projz; liste->next=mlist; liste=mlist; } while (!IsCollision(projx,projz)); liste->next=NULL; xe=liste->xl; ze=liste->zl; if (tank==1) if ((xe>(tank2x-5)) && (xe<(tank2x+5)) && (ze>(tank2z-5)) && (ze<(tank2z+5))) win=1; if (tank==2) if ((xe>(tank1x-5)) && (xe<(tank1x+5)) && (ze>(tank1z-5)) && (ze<(tank1z+5))) win=2; }
void GameReferee::DropShapeComplete(Shape * curShape) { while(!IsCollision(1, 0, curShape)) MoveShapeDown(curShape); }
void Input::HandleEventPlz( Game *game, Character *player, LevelManager *lev, NpcManager *npc, Dialog *dialogBox, LuaManager *luaScript, SoundManager *sound, MenuManager *menu, BattleSystem *battleSys ) { /* TEMP DEBUG */ if ( GetKey( SDLK_b ) && keyTimer <= 0 ) //enter battle { battleSys->SetupBattle( "orc", luaScript, player ); game->State( BATTLE ); keyTimer = 10; } else if ( game->State() == BATTLE && GetKey( 27 ) && keyTimer <= 0 ) //exit battle { game->State( INGAME ); keyTimer = 10; } if ( GetKey( SDLK_1 ) && keyTimer <= 0 ) //enable clipping mode { if ( player->Debug() ) player->Debug( false ); else player->Debug( true ); keyTimer = 10; } if ( GetKey( SDLK_9 ) && keyTimer <= 0 ) //go to next map { lev->NextLevel(); sound->StartSong( lev->CurrentLevel().songID ); keyTimer = 10; } else if ( GetKey( SDLK_0 ) && keyTimer <= 0 ) //go to next map { lev->PrevLevel(); sound->StartSong( lev->CurrentLevel().songID ); keyTimer = 10; } /* BATTLE COMMANDS */ if ( game->State() == BATTLE ) { if ( GetKey( SDLK_a ) ) //attack { battleSys->GetBattleCommand( luaScript, "ATTACK" ); } else if ( GetKey( SDLK_w ) ) //wait { battleSys->GetBattleCommand( luaScript, "WAIT" ); } else if ( GetKey( SDLK_i ) ) //item { battleSys->GetBattleCommand( luaScript, "ITEM" ); } else if ( GetKey( SDLK_r ) ) //run { battleSys->GetBattleCommand( luaScript, "RUN" ); } else if ( GetKey( 27 ) ) { game->State( INGAME ); } } //if ( game->State() == BATTLE ) /* UNIVERSAL COMMANDS */ if ( GetKey( SDLK_F4 ) || GetKey( SDLK_q ) ) // quit game { game->Done( true ); } if ( GetKey( SDLK_F6 ) ) // toggle fullscreen { game->ToggleFullscreen(); } /* TITLE SCREEN COMMANDS */ if ( game->State() == TITLE ) { if ( GetKey( SDLK_RETURN ) ) { game->State( INGAME ); } } //if ( game->State() == TITLE ) /* MENU COMMANDS */ else if ( game->State() == MENU ) { if ( GetKey( 27 ) && keyTimer <= 0 ) //ESC { //back to game Mix_PlayChannel( -1, sound->errorSound, 0 ); //channel (-1 = first unused one), chunk (sample), loop (-1 = infinite) game->State( INGAME ); keyTimer = 10; } if ( GetKey( SDLK_UP ) && keyTimer <= 0 ) { //Navigate through options // menu->MoveCursor( UP ); keyTimer = 10; Mix_PlayChannel( -1, sound->cursorSound, 0 ); //channel (-1 = first unused one), chunk (sample), loop (-1 = infinite) } else if ( GetKey( SDLK_DOWN ) && keyTimer <= 0 ) { //Navigate through options // menu->MoveCursor( DOWN ); keyTimer = 10; Mix_PlayChannel( -1, sound->cursorSound, 0 ); //channel (-1 = first unused one), chunk (sample), loop (-1 = infinite) } else if ( GetKey( SDLK_RETURN ) && keyTimer <= 0 ) { //Select option keyTimer = 10; Mix_PlayChannel( -1, sound->confirmSound, 0 ); //channel (-1 = first unused one), chunk (sample), loop (-1 = infinite) /* to be moved into other area */ // if ( menu->CursorY() == 440 ) // { // game-> // Done( true ); // } } else if ( GetKey( 27 ) && keyTimer <= 0 ) { //Go back an option keyTimer = 10; } } //if ( game->State() == MENU ) /* INGAME COMMANDS */ else if ( game->State() == INGAME ) { //SYSTEM KEYS if ( GetKey( 27 ) && keyTimer <= 0 ) //ESC { //play noise Mix_PlayChannel( -1, sound->confirmSound, 0 ); //channel (-1 = first unused one), chunk (sample), loop (-1 = infinite) game->State( MENU ); keyTimer = 10; // menu->CursorY( 40 ); } //PLAYER KEYS if ( GetKey( SDLK_RSHIFT ) || GetKey( SDLK_LSHIFT ) ) // Run { player->Run( true ); } else { player->Run( false ); } if ( dialogBox->DialogShown() == false ) // can't move while talking. { if ( GetKey( SDLK_UP ) ) // Move up { player->Move( UP ); if ( player->Debug() == false && IsCollision( player, &lev->CurrentLevel() ) ) player->Correct( DOWN ); } else if ( GetKey( SDLK_DOWN ) ) // Move down { player->Move( DOWN ); if ( player->Debug() == false && IsCollision( player, &lev->CurrentLevel() ) ) player->Correct( UP ); } else if ( GetKey( SDLK_LEFT ) ) // Move left { player->Move( LEFT ); if ( player->Debug() == false && IsCollision( player, &lev->CurrentLevel() ) ) player->Correct( RIGHT ); } else if ( GetKey( SDLK_RIGHT ) ) // Move right { player->Move( RIGHT ); if ( player->Debug() == false && IsCollision( player, &lev->CurrentLevel() ) ) player->Correct( LEFT ); } // Check for a warp point // lev->CheckForWarpTile( luaScript, player->X(), player->Y() ); } if ( GetKey( SDLK_RETURN ) ) { if ( keyTimer <= 0 ) { if ( dialogBox->DialogShown() == false ) { // Open dialog box if there's something to say string message = npc->TryInteraction( player, luaScript ); // interact with NPC or object if ( message != "NULL" ) { Mix_PlayChannel( -1, sound->talkSound, 0 ); //channel (-1 = first unused one), chunk (sample), loop (-1 = infinite) dialogBox->SetCurrentDialog( message ); keyTimer = 10; dialogBox->ShowDialog( true ); } } else { // Close dialog box dialogBox->ShowDialog( false ); keyTimer = 10; } } } } //if ( game->State() == INGAME ) if ( keyTimer > 0 ) keyTimer -= 1; }
void GameReferee::PlayGame() { //Event Handler SDL_Event e; Shape* curShape = new Shape(); srand(time(0)); curShape->CreateShape(rand() % 7); m_board->SetCurrentShape(curShape); //If idle time is about 1 second auto drop block m_idleTime = SDL_GetTicks(); //Game Loop bool quit = false; while(!quit) { uint32_t curTime = SDL_GetTicks(); if(curTime - m_idleTime > 1200) { m_idleTime = SDL_GetTicks(); if(!IsCollision(1, 0, curShape)) MoveShapeDown(curShape); else { //Block done dropping m_board->AddShapeToBoard(); int rowFinished = IsLineComplete(); while(rowFinished != -1) { //remove line and push down m_board->RemoveAndDropRow(rowFinished); rowFinished = IsLineComplete(); Draw(); sleep(1); } curShape = new Shape(); curShape->CreateShape(rand() % 7); m_board->SetCurrentShape(curShape); if(IsCollision(1, 0, curShape)) { printf("Game is Over!"); return; } } } //Event Handlers FOR KEY PRESSES while(SDL_PollEvent( &e ) != 0) { //User wants to quit if(e.type == SDL_QUIT) { quit = true; } else if(e.type == SDL_KEYDOWN) { int ** rotatedTetroid; switch(e.key.keysym.sym) { //Reference for keypresses case SDLK_UP: rotatedTetroid = curShape->RotateShape(); if(!IsRotateCollision(rotatedTetroid, curShape->m_startRow, curShape->m_startCol)) { curShape->SetTetroid(rotatedTetroid); } break; case SDLK_DOWN: if(!IsCollision(1, 0, curShape)) MoveShapeDown(curShape); break; case SDLK_LEFT: if(!IsCollision(0, -1, curShape)) MoveShapeLeft(curShape); break; case SDLK_RIGHT: if(!IsCollision(0, 1, curShape)) MoveShapeRight(curShape); break; case SDLK_SPACE: DropShapeComplete(curShape); break; default: break; } } } Draw(); } }
void Enemy::Update( Character players[2], int soundTimer, int soundTimer2, float gameTimer, SAMPLE* sndAttack, SAMPLE* sndDamage, int MaxText, TextEffect txteffect[] ) { if ( deadTimer > 0 ) { deadTimer -= 0.1; if ( deadTimer <= 0 ) { Reset(); } } if ( exists ) { collisionRegion.X( position.x + 5 ); collisionRegion.Y( position.y + 5 ); collisionRegion.W( 24 ); collisionRegion.H( 24 ); if ( atkCounter > 0 ) { atkCounter -= 0.5; } else { atkCounter = -1; action = WALKING; } for ( int p = 0; p < 2; p++ ) { if ( Exists() == true && players[p].Exists() && IsCollision( &players[p] ) ) { if ( players[p].Is() == ATTACKING ) { if ( soundTimer <= 0 ) { play_sample( sndAttack, 255, 128, 1000, false ); soundTimer = 5.0; ChangeHP( players[p].StrengthFloat() ); if ( hp <= 0 ) { players[p].Exp( Exp() ); } bool foundText = false; //Setup fancy text crap for ( int j=0; j<MaxText; j++ ) { if ( foundText == false ) { if ( txteffect[j].inUse == false ) { txteffect[j].Setup( players[p].StrengthString().c_str(), X()+3, Y(), 255, 100, 75 ); foundText = true; } } } } }//attacking //enemy attack if ( soundTimer2 <= 0 && gameTimer > 20 ) { play_sample( sndDamage, 255, 128, 1000, false ); soundTimer2 = 10.0; players[p].AddHP( -0.1 ); bool foundText = false; //Setup fancy text crap for ( int j=0; j<MaxText; j++ ) { if ( foundText == false ) { if ( txteffect[j].inUse == false ) { txteffect[j].Setup( "-2", players[p].X()+3, players[p].Y(), 255, 0, 0 ); foundText = true; } } } }//not attacking }//if ( enemy[i].Exists() == true && IsCollision( &player, &enemy[i] ) ) } if ( hp <= 0 ) { exists = false; SetDeadTimer(); } } }