Example #1
0
int Generate()
{
  int attempts = 0;
  int i;
  int correct_dist = 0;
  int maxdist = 0;
  rdir = rand()%4;
  NewRoom(map.w / 2 - 20 / 2, map.h / 2 - 15 / 2, 20, 15, -1);
	
  for (attempts = 0; attempts < 100000; attempts++) {
    assert(map.w == 512);
    AddChild(rndval(rndval(0, total_rooms-1), total_rooms-1));
    if (total_rooms % 100 == 99) {
      LoadingScreen(0, (float)total_rooms / (float) NUM_ROOMS);
    }
    if (total_rooms == NUM_ROOMS) break;
  }
	
  if ((total_rooms < NUM_ROOMS)||(DoRepeat == 1)) {
    DoRepeat = 0;
    ResetLevel();
    return 0;
  }
	
  RecurseSetDist();
	
  for (i = 0; i < NUM_ROOMS; i++) {
    if (map.rooms[i].s_dist > maxdist) {
      maxdist = map.rooms[i].s_dist;
    }
		
    if (map.rooms[i].s_dist >= 50) {
      correct_dist = 1;
    }
  }
	
  if (correct_dist == 0) {
    /*printf("Dist fail (only %d)\n", maxdist);*/
    DoRepeat = 0;
    ResetLevel();
    return 0;
  }
	
  /*printf("Rooms: %d\n", total_rooms);*/
	
  MakeSpecialRooms();
	
  map.totalRooms = total_rooms;
  return 1;
}
void DunGen::Load(int xCap,int yCap)
{
    ResetLevel();

    levelXCap = xCap;
    levelYCap = yCap;

    //Also load from file
    //Scratched. Just here for historical purposes.
}
void TreeCommon::ResetLevel(CNode* node, int level) {
	if (node == NULL) return;
	node->set_level(level);
	if (level > max_level_) max_level_ = level;

	if (node->type() == CNode::BRANCH) {
		CBranch* branch = dynamic_cast<CBranch*>(node);
		if (branch != NULL) {
			for (int i = 0; i < branch->linked_nodes.size(); ++i)
				ResetLevel(branch->linked_nodes[i], level + 1);
		}
	}
}
Example #4
0
void GameLogicComponent::ProcessEvent( GameEvent const& i_event)
{
  switch ( i_event )
  {
    case ( GameEvent::e_ballHitsAIGoalLine ):
    {
      m_playerScore += 1;
      m_messenger.Post({0},{1,m_playerScore});
      ResetLevel();
      break;
    }
    case ( GameEvent::e_ballHitsPlayerGoalLine ):
    {
      m_aiScore += 1;
      m_messenger.Post({0},{2,m_aiScore});
      ResetLevel();
      break;
    }
    default:
    {
      assert(false);
    }
  }
}
//TODO: This function still lacks the functionality to set the camera to the correct place when level changes (or however the levels are implemented)
void CAppStateGame::OnLevelChange() {

	CurrentLevelNumber++;

	//If we have survived the last level (TODO:next state should be end credits or something?)
	
	if (CurrentLevelNumber == 1) {
		debug("Area 1 loading start", 1);
		if(CArea::AreaControl.OnLoad(PATH_MAPS PATH_AREA1) == false) {
			return;
		}
	}
	else if (CurrentLevelNumber == 2) {
		debug("Area 2 loading start", 1);
		if(CArea::AreaControl.OnLoad(PATH_MAPS PATH_AREA2) == false) {
			return;
		}
	}
	else if(CurrentLevelNumber > 2) {
		NextState = APPSTATE_MAINMENU;
		levelBeginningScores = 0;
		GameOver = true;
		CheckHighScores();
		return;
	}

	std::string LevelInfoFile = "level"+IntToString(CurrentLevelNumber)+"info.txt";
	
	//Loading of new level information
	Level = GetCurrentLevelInfo (LevelInfoFile);

	debug("Changed to level" + IntToString(CurrentLevelNumber));

	//Let's set the new level ending point
	LevelEndingPoint = Level.back().ActiveXPosition;

	std::string LevelMusicID = "Level"+IntToString(CurrentLevelNumber) + "Music";

	//Play the level music
	CSoundBank::SoundControl.Play(CSoundBank::MUSIC, LevelMusicID, false, 70);

	levelBeginningScores = Player->Points;
	keepOldGun = true;

	ResetLevel();

}
void NeuroSandCube::Update()
{

	m_spCommandController->PollCommands();

	if (player->levelRestart)
	{
		ResetLevel();
	}

	StateDistributor::GetInstance().Distribute();
	
	m_spIOService->Update();
	ResetFrame();

	
}
Example #7
0
//Reset the game
void ResetGame(){
    
    //Reset the frame counter 
    frame_counter = 0;
    
    //Reset the score
    yellow_player.score = 0;
    purple_player.score = 0;
    
    yellow_player.prev_score = 0;
    purple_player.prev_score = 0;
    
    //-------------------------
    //Init sprite positions
    //-------------------------
      
    //Reset the ball position  
    ResetLevel();
    
}
void DunGen::Generate(int xCap,int yCap,int difficulty)
{

    srand(time(NULL));

    //blankTexture.loadFromFile("sprites/dungeon_sprites/emptytile.png");
    //lvlTexture.loadFromFile("sprites/dungeon_sprites/room.png");
    //stairTexture.loadFromFile("sprites/dungeon_sprites/dstair.png");

    ResetLevel();

    Tunnels(xCap,yCap,difficulty,3);

    Rooms(xCap,yCap,difficulty,4);

    PlaceChest(difficulty);

    SpriteGenerate();


}
Example #9
0
void LevelEditor () {
	int i=0;
	int j=0;
	if (Panel==0) {
		if ((Key=='d' || Arrow=='M') && Tile_X<399) Tile_X++;
		if ((Key=='a' || Arrow=='K') && Tile_X>0) Tile_X--;
		if ((Key=='s' || Arrow=='P') && Tile_Y<8) Tile_Y++;
		if ((Key=='w' || Arrow=='H') && Tile_Y>0) Tile_Y--;
		if ((Key==' ' || Arrow==28)) {
			if (Tile_Type==5) {
				for (i=0; i<LEVEL_MAXLEN; i++) if (*(Levels[CURRENT_LEVEL]+0*LEVEL_MAXLEN+i)==5) *(Levels[CURRENT_LEVEL]+0*LEVEL_MAXLEN+i)=0;
				*(Levels[CURRENT_LEVEL]+0*LEVEL_MAXLEN+Tile_X)=5;
			} else {
				*(Levels[CURRENT_LEVEL]+Tile_Y*LEVEL_MAXLEN+Tile_X)=Tile_Type;
			}
		}
	}
	if (Panel==1) {
		if ((Key=='s' || Arrow=='P') && Tile_Type<5) Tile_Type++;
		if ((Key=='w' || Arrow=='H') && Tile_Type>0) Tile_Type--;
	}
	if (Panel==2) {
		if ((Key=='s' || Arrow=='P') && Q_SELECTED<5) Q_SELECTED++;
		if ((Key=='w' || Arrow=='H') && Q_SELECTED>0) Q_SELECTED--;
		if ((Key==' ' || Arrow==28) && Q_SELECTED==0) {
			GAME_TYPE=1;
			if (GLOBAL_CHECKPOINT>0) {
				int isCheck=0;
				for (i=0;i<9; i++) {
					int CurBlock=*(Levels[CURRENT_LEVEL]+i*LEVEL_MAXLEN+GLOBAL_CHECKPOINT);
					if (CurBlock==4) {
						SPAWN_Y=(i+1)*43+41+70-DeltaH[HeroSides];
						isCheck=1;
						break;
					}
				}
				if (isCheck==0) {
					DrawText (100,300,"error (checkpoint not found)",GLOBAL_FRONTCOLOR);
					Update();
					_ksys_delay(200);
					GAME_TYPE=3;
					Panel=1;
					return;
				}
				ResetLevel(CURRENT_LEVEL);
				isRestart=0;
				HeroIsDead=0;
				HeroFly=0;
				HeroY=SPAWN_Y;
				if (HeroSides>7) HeroY-=22;
				if (HeroSides%2==0) {
				       HeroAngle=360/(HeroSides*2);
				} else {
				       HeroAngle=0;
				}
			}
		}
		if (Q_SELECTED==1) {
			if ((Key=='d' || Arrow=='M') && GLOBAL_CHECKPOINT<399) GLOBAL_CHECKPOINT++;
			if ((Key=='a' || Arrow=='K') && GLOBAL_CHECKPOINT>0) GLOBAL_CHECKPOINT--;
		}
		if ((Key==' ' || Arrow==28) && Q_SELECTED==2) {
			for (i=0; i<9; i++) {
				for (j=0; j<LEVEL_MAXLEN; j++) {
					*(Levels[CURRENT_LEVEL]+i*LEVEL_MAXLEN+j)=0;
				}
			}
		}
		if ((Key==' ' || Arrow==28) && Q_SELECTED==3) SaveArray();
		if (Q_SELECTED==4) {
			if ((Key=='a' || Arrow=='K') && LevelProps[CURRENT_LEVEL][2]>3) LevelProps[CURRENT_LEVEL][2]--;
			if ((Key=='d' || Arrow=='M') && LevelProps[CURRENT_LEVEL][2]<10) LevelProps[CURRENT_LEVEL][2]++;
			HeroSides=LevelProps[CURRENT_LEVEL][2];
		}
		if ((Key==' ' || Arrow==28) && Q_SELECTED==5) GAME_TYPE=0;
	}
	if (Key=='e') {
		if (Panel==0) {
			Panel=1;
		} else {
			Panel=0;
		}
	}
	if (Key=='q') {
		if (Panel==0) {
			Panel=2;
		} else {
			Panel=0;
		}
	}
	//Draw grid
	for (i=0; i<=10; i++) {
		DrawLine (43*i,0,43*i,43*9,GLOBAL_FRONTCOLOR);
	}
	for (i=0; i<=9; i++) {
		DrawLine (0,43*i,430,43*i,GLOBAL_FRONTCOLOR);
	}
	//Draw panel
	DrawText (450,10,"e_tools",GLOBAL_FRONTCOLOR);
	IntToStr (Tile_X,NUMBER);
	DrawText (450,30,"(",GLOBAL_FRONTCOLOR);
	DrawText (470,30,NUMBER,GLOBAL_FRONTCOLOR);
	DrawText (530,30,"/",GLOBAL_FRONTCOLOR);
	IntToStr (Tile_Y,NUMBER);
	DrawText (550,30,NUMBER,GLOBAL_FRONTCOLOR);
	DrawText (570,30,")",GLOBAL_FRONTCOLOR);

	DrawLine (480,70,530,70,GLOBAL_FRONTCOLOR);
	DrawLine (480,70,480,70+300,GLOBAL_FRONTCOLOR);
	DrawLine (530,70,530,70+300,GLOBAL_FRONTCOLOR);
	for (i=1;i<=6; i++) DrawLine (480,70+50*i,530,70+50*i,GLOBAL_FRONTCOLOR);
	//Empty block
	DrawLine (480+4,70+4,480+42,70+42,GLOBAL_FRONTCOLOR);
	DrawLine (480+4,70+42,480+42,70+4,GLOBAL_FRONTCOLOR);
	DrawBlock (480+4,70+4+50,GLOBAL_FRONTCOLOR);
	DrawPit (480+7,70+4+100,GLOBAL_FRONTCOLOR);
	DrawBatut (480+4,70+4+150,GLOBAL_FRONTCOLOR);
	DrawFlag (480+8,70+4+200,GLOBAL_FRONTCOLOR);
	DrawText (480+14,70+14+250,"f",GLOBAL_FRONTCOLOR);
	DrawText (450,400,TILENAME [Tile_Type],GLOBAL_FRONTCOLOR);

	//Draw properties
	DrawText (10,410,"q_properties",GLOBAL_FRONTCOLOR);
	DrawText (10,430+20,"test level",GLOBAL_FRONTCOLOR);
	DrawText (10,470,"start column <     >",GLOBAL_FRONTCOLOR);
	IntToStr (GLOBAL_CHECKPOINT,NUMBER);
	DrawText (270,470,NUMBER,GLOBAL_FRONTCOLOR);
	DrawText (10,490,"reset level",GLOBAL_FRONTCOLOR);
	DrawText (10,510,"save as 2d array (for developers)",GLOBAL_FRONTCOLOR);
	DrawText (10,530,"hero sides <   >",GLOBAL_FRONTCOLOR);
	IntToStr (LevelProps[CURRENT_LEVEL][2],NUMBER);
	DrawText (230,530,NUMBER,GLOBAL_FRONTCOLOR);
	DrawText (10,550,"back to menu",GLOBAL_FRONTCOLOR);

	if (Panel==0) {
		DrawLine ((Tile_X%10)*43,0,(Tile_X%10)*43,400,HeroColor);
		DrawLine ((Tile_X%10)*43+43,0,(Tile_X%10)*43+43,400,HeroColor);
		DrawLine (0,(Tile_Y%10)*43,440,(Tile_Y%10)*43,HeroColor);
		DrawLine (0,(Tile_Y%10)*43+43,440,(Tile_Y%10)*43+43,HeroColor);
	}
	if (Panel==1) {
		DrawText (450,10,"e_tools",HeroColor);
		DrawLine (480,70+Tile_Type*50,530,70+Tile_Type*50,HeroColor);
		DrawLine (480,70+Tile_Type*50,480,70+50+Tile_Type*50,HeroColor);
		DrawLine (480,70+Tile_Type*50+50,530,70+50+Tile_Type*50,HeroColor);
		DrawLine (530,70+Tile_Type*50,530,70+Tile_Type*50+50,HeroColor);
		DrawText (450,400,TILENAME [Tile_Type],HeroColor);
	}
	if (Panel==2) {
	       DrawText (10,410,"q_properties",HeroColor);
	       if (Q_SELECTED==0) DrawText (10,450,"test level",HeroColor);
	       if (Q_SELECTED==1) DrawText (10,470,"start column <     >",HeroColor);
	       if (Q_SELECTED==2) DrawText (10,490,"reset level",HeroColor);
	       if (Q_SELECTED==3) DrawText (10,510,"save as 2d array (for developers)",HeroColor);
	       if (Q_SELECTED==4) DrawText (10,530,"hero sides <   >",HeroColor);
	       if (Q_SELECTED==5) DrawText (10,550,"back to menu",HeroColor);
	}

	for (i=0; i<10; i++) {
		for (j=0; j<9; j++) {
			int CurBlock=*(Levels[CURRENT_LEVEL]+j*LEVEL_MAXLEN+Tile_X-Tile_X%10+i);
			if (CurBlock==1) DrawBlock (43*i,43*j,GLOBAL_BLOCKCOLOR);
			if (CurBlock==2) DrawPit (43*i,43*j,GLOBAL_PITCOLOR);
			if (CurBlock==3) DrawBatut (43*i,43*j,GLOBAL_BATUTCOLOR);
			if (CurBlock==4) DrawFlag (43*i,43*j,GLOBAL_FLAGCOLOR);

		}
		if (*(Levels[CURRENT_LEVEL]+0*LEVEL_MAXLEN+Tile_X-Tile_X%10+i)==5) {
			for (j=0; j<9;j++) {
				DrawText (43*i+10,43*j+10,"f",GLOBAL_FRONTCOLOR);
			}
		}
	}
	if (Key==27) {
		GAME_TYPE=0;
	}
}
Example #10
0
void GamePlay () {
	DrawLine (0,500,800,500,GLOBAL_FRONTCOLOR);
	if (Objects==0 || DataBase[Objects-1][1]<=Width-40) {
		ReadLevel(CURRENT_LEVEL);
	 }

	 if (HeroIsDead==0) {
		if (isRestart==1) {
			HeroAngle=(HeroAngle+10)%360;
			HeroIsDead=CheckCollision();
			HeroY+=HeroFly;
			DrawHero (125,HeroY, HeroSides, HeroAngle, HeroColor);
		} else {
			DrawHero (125,HeroY,HeroSides,HeroAngle,GLOBAL_FRONTCOLOR);
		}
		if (TO_NEXT_LEVEL>0) {
			DrawText (Width-TO_NEXT_LEVEL,300,"jump to start new level",GLOBAL_FRONTCOLOR);
			if (TO_NEXT_LEVEL<500) {
				TO_NEXT_LEVEL+=2;
			} else {
				if ((Key==' ' || Arrow==28) && TO_NEXT_LEVEL<=504) {
					CURRENT_LEVEL++;
					HeroSides=CURRENT_LEVEL;
					if (CURRENT_LEVEL>MAX_LEVEL) MAX_LEVEL=CURRENT_LEVEL;
					GLOBAL_CHECKPOINT=0;
					TO_NEXT_LEVEL=505;
				}
				if (TO_NEXT_LEVEL>=505) {
					TO_NEXT_LEVEL+=2;
					if (TO_NEXT_LEVEL>1000) TO_NEXT_LEVEL=0;
				}
			}

		}

	  } else {
		GLOBAL_SPEED=0;
		DeltaSpeed=0;
		TO_NEXT_LEVEL=0;
		HeroIsDead++;
		DrawPew (125,HeroY,HeroIsDead,HeroColor);
		if (HeroIsDead>100) {
			 ResetLevel(CURRENT_LEVEL);
			 if (GLOBAL_CHECKPOINT==0) {
				isRestart=1;
				HeroY=100;
			 } else {
				isRestart=0;
				HeroY=SPAWN_Y+41-DeltaH[HeroSides];
				if (HeroSides>7) HeroY-=22;
			 }
			 HeroIsDead=0;
			 HeroFly=0;
			 if (HeroSides%2==0) {
				HeroAngle=360/(HeroSides*2);
			 } else {
				HeroAngle=0;
			 }
		}
	  }
	  if (Key=='f'&& CURRENT_LEVEL<3) {
		int i=0;
		Objects=0;
		for (i=0; i<11; i++) LevelProps[i][0]=0;
		isRestart=1;
		HeroIsDead=0;
		HeroY=100;
		HeroFly=1;
		TO_NEXT_LEVEL=0;
		GAME_TYPE=3;
		Panel=1;
	  }
	  if (Key==27) {
		GLOBAL_CHECKPOINT=0;
		int i=0;
		for (i=0; i<11; i++) ResetLevel (i);
		isRestart=1;
		HeroIsDead=0;
		HeroY=100;
		HeroFly=1;
		TO_NEXT_LEVEL=0;
		if (CURRENT_LEVEL<3) {
			GAME_TYPE=3;
			Panel=1;
			Key=' ';
		} else {
			GAME_TYPE=0;
		}
	  }
}
//=============================================================================
void CAppStateGame::OnActivate() {
	debug("Game initialization start");

	// Loading area
	// Note that area is the whole level which might consist of many maps
	debug("Area loading start", 1);
	if(CArea::AreaControl.OnLoad(PATH_MAPS PATH_AREA1) == false) {
    	return;
    }
	debug("All areas loaded successfully", 1);

	debug("Entity loading start", 1);
	Player = CFactory::Factory.CreatePlayer(PLAYER_STARTING_X, PLAYER_STARTING_Y);

	// TODO: Player2 not needed yet. Make the game support co-op later

	//We would like to start from the first level.
	CurrentLevelNumber = 1;

	//This is mainly for testing purpose in here (of course we usually start from the first level).
	std::string LevelInfoFile = "level"+IntToString(CurrentLevelNumber)+"info.txt";

	//Loading of level information. Level changing feature should be implemented.
	Level = GetCurrentLevelInfo (LevelInfoFile);

	//We start from the first item in the vector
	LevelInfoIndex = 0;

	//Sets the point where the level should be changed (Information is in the last line of the level info file).
	LevelEndingPoint = Level.back().ActiveXPosition;

	debug("Levelendingpoint: "+IntToString(LevelEndingPoint));

	debug("All entities loaded successfully", 1);

	debug("Additional image loading stat", 1);
	if((UIIcons = CSurface::OnLoad(PATH_IMAGES PATH_UI FILENAME_UI_ICONS)) == NULL) {
		error("Couldn't load UI life icon.");
		return;
	}
	if((UItiles = CSurface::OnLoad(PATH_IMAGES PATH_UI FILENAME_UI_TILES)) == NULL) {
		error("Couldn't load UI tilesheet.");
		return;
	}
	if((SpaceBG = CSurface::OnLoad(PATH_IMAGES FILENAME_SPACE_BG_1)) == NULL) {
		error("Couldn't load background image.");
		return;
	}
	BG_offset = BG_WIDTH;
	debug("Additional images loaded successfully", 1);

	// Camera initialization, make it start from 0,0
	CCamera::CameraControl.TargetMode = TARGET_MODE_NORMAL;
	debug("Camera set", 1);

	std::string LevelMusicID = "Level"+IntToString(CurrentLevelNumber) + "Music";

	//Plays the level music
	CSoundBank::SoundControl.Play(CSoundBank::MUSIC, LevelMusicID, false, 70);

	if(!Input.OnLoad(PATH_IMAGES PATH_UI "input_field.png","",WWIDTH/2-165,WHEIGHT/2-55, true)){
		error("Couldn't load input field");
		return;
	}
	Input.Hide();

	debug("Game initialization successful");
	ResetLevel();
}
//-----------------------------------------------------------------------------
void CAppStateGame::OnLoop() {

	if( GameOver ) {
		if( !Input.HasFocus() ) {
			if( Input.State == UI_NORMAL ) {
				CHighScores HighScore;
				HighScore.OnInit();
				HighScore.Add(Input.GetValue(),Player->Points);
			}
			GameOver = false;
			CAppStateManager::SetActiveAppState(NextState);

			CSoundBank::SoundControl.Play(CSoundBank::MUSIC, "MenuMusic");

		}
		return;
	}

	//If the level should change
	//if( CCamera::CameraControl.GetX() >= LevelEndingPoint ) {
	//	OnLevelChange();
	//}

	// Spawn new entities
	//else if( LevelInfoIndex < Level.size() && 
	if( LevelInfoIndex < Level.size() &&
		(unsigned int)CCamera::CameraControl.GetX() >= Level.at(LevelInfoIndex).ActiveXPosition) {

		CAppStateGame::LevelInfo TmpInfo = Level.at(LevelInfoIndex);

		switch(TmpInfo.Type) { 
			case ENTITY_TYPE_ENEMY:
				debug("creating enemy of type: " + IntToString(TmpInfo.SubType));
				CFactory::Factory.CreateEnemy(TmpInfo.SubType, CCamera::CameraControl.GetX()+1000, TmpInfo.YPosition);
				break;
			case ENTITY_TYPE_ITEM:
				CFactory::Factory.CreateItem(TmpInfo.SubType, CCamera::CameraControl.GetX()+1000, TmpInfo.YPosition);
				break;
			case ENTITY_TYPE_SPECIAL_EFFECT:
				// NOTE: y-position is now indicating the ms duration for the slowmo effect

				if (TmpInfo.SubType == ENTITY_SUBTYPE_SPECIAL_EFFECT_SLOWMO_2X) {
					CFactory::Factory.CreateSlowMotion(LEVEL_SLOWMO_2X, TmpInfo.YPosition);
				}
				else if (TmpInfo.SubType == ENTITY_SUBTYPE_SPECIAL_EFFECT_SLOWMO_4X) {
					CFactory::Factory.CreateSlowMotion(LEVEL_SLOWMO_4X, TmpInfo.YPosition);
				}
				else if (TmpInfo.SubType == ENTITY_SUBTYPE_SPECIAL_EFFECT_SLOWMO_8X) {
					CFactory::Factory.CreateSlowMotion(LEVEL_SLOWMO_8X, TmpInfo.YPosition);
				}
				break;
			default:
				break;
		}

		LevelInfoIndex++;
	}

    //--------------------------------------------------------------------------
    // Entities
    //--------------------------------------------------------------------------
    for(unsigned int i = 0;i < CEntity::EntityList.size();i++) {
        if(!CEntity::EntityList[i]) continue;

        CEntity::EntityList[i]->OnLoop();
    }

    //Collision Events
    for(unsigned int i = 0;i < CEntityCol::EntityColList.size();i++) {
        CEntity* EntityA = CEntityCol::EntityColList[i].EntityA;
        CEntity* EntityB = CEntityCol::EntityColList[i].EntityB;

        if(EntityA == NULL || EntityB == NULL) continue;

		/* Pixel precise collision detection */

		// Create rectangle of the possible collision area
		SDL_Rect collisionRect = CEntity::Intersection(EntityA->GetBounds(), EntityB->GetBounds());
		
		// Check if there is even a possible collision
		if(collisionRect.w != 0 && collisionRect.h != 0 ) {
			// Check if there is/are actual pixel overlapping between
			// both entities. If there is...
			if(CEntity::CheckCollision(EntityA, EntityB)) {
				// Let both entities know of the collision
				EntityA->OnCollision(EntityB);
				EntityB->OnCollision(EntityA);
			}
		}
    }

    CEntityCol::EntityColList.clear();

	// Camera movement:
	// Make camera move wanted amount of pixels per second to right
	float moveX = CCamera::CameraControl.speed * CFPS::FPSControl.GetSpeedFactor();

	// If we are not in the boss area
	if ( (CCamera::CameraControl.GetX() + (int)moveX) < LEVEL_LENGTH) {
		CCamera::CameraControl.OnMove(moveX, static_cast<float>(CCamera::CameraControl.GetY()));
	
		// Update BG offset
		BG_offset = BG_offset - BG_SPEED * CFPS::FPSControl.GetSpeedFactor();
		if( BG_offset <= 0 ) {
			BG_offset = BG_WIDTH;
		}
	}
	// When we come to the boss map of the level area
	else {
		CCamera::CameraControl.SetPos(LEVEL_LENGTH, CCamera::CameraControl.GetY());
		CCamera::CameraControl.speed = 0;
		BossFightOn = true;
	}
	

	if (ResetCurrentLevel) {
		ResetLevel();
	}
	else if (BossFightOn && BossDead) {
		OnLevelChange();
	}
}
Example #13
0
//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);
     
}
Example #14
0
 void SceneEditorApp::StopLevel() {
     playLevel = false;
     ResetLevel();
     paused = false;
     //    GetLevelManager().StartLevel(currentLevel,objectParams);
 }