コード例 #1
0
ファイル: SFApp.cpp プロジェクト: naruto655/StarshipFontana
/**
 * Handle all events that come from SDL.
 * These are timer or keyboard events.
 */
void SFApp::OnEvent(SFEvent& event) {
  SFEVENT the_event = event.GetCode();
  switch (the_event) {
  case SFEVENT_QUIT:
    is_running = false;
    break;
  case SFEVENT_UPDATE:
    OnUpdateWorld();
    OnRender();
    break;
  case SFEVENT_PLAYER_UP:
    player->GoNorth();
    break;
  case SFEVENT_PLAYER_DOWN:
    player->GoSouth();
    break;
  case SFEVENT_PLAYER_LEFT:
    player->GoWest();
    break;
  case SFEVENT_PLAYER_RIGHT:
    player->GoEast();
    break;
  case SFEVENT_FIRE:
    fire ++;
    FireProjectile();
    break;
  }
}
コード例 #2
0
/**
 * Handle all events that come from SDL.
 * These are timer or keyboard events.
 */
void SFApp::OnEvent(SFEvent& event) {
  SFEVENT the_event = event.GetCode();
  switch (the_event) {
  case SFEVENT_QUIT:
    is_running = false;
    break;
  case SFEVENT_UPDATE:
    OnUpdateWorld();
    OnRender();
    break;
  }
}
コード例 #3
0
/**
 * Handle all events that come from SDL.
 * These are timer or keyboard events.
 */
void SFApp::OnEvent(SFEvent& event) {
  SFEVENT the_event = event.GetCode();
  switch (the_event) {
  case SFEVENT_QUIT:
    is_running = false;
    break;
  case SFEVENT_UPDATE:
    OnUpdateWorld();
    OnRender();
    break;
  case SFEVENT_PLAYER_LEFT:
    left = true;
    break;
  case SFEVENT_PLAYER_RIGHT:  
    right = true;
    break;
  case SFEVENT_PLAYER_UP:
    up = true;
    break;
  case SFEVENT_PLAYER_DOWN:
    down = true;
    break;
  case SFEVENT_PLAYER_LEFT_RELEASED:
    left = false;
    break;
  case SFEVENT_PLAYER_RIGHT_RELEASED:
    right = false;
    break;
  case SFEVENT_PLAYER_UP_RELEASED:
    up = false;
    break;
  case SFEVENT_PLAYER_DOWN_RELEASED:
    down = false;
    break;
  case SFEVENT_FIRE:
    fired = true;
    break;
  case SFEVENT_FIRE_RELEASED:
    fired = false;
    fire = 0;
    break;
  case SFEVENT_LWALL:
    addWall(true);
    break;
  case SFEVENT_RWALL:
    addWall(false);
    break;
  case SFEVENT_RESET:
    Reset();
    break;
  }
}
コード例 #4
0
ファイル: SFApp.cpp プロジェクト: IvanMacukat/StarshipFontana
/**
 * Handle all events that come from SDL.
 * These are timer or keyboard events.
 */
void SFApp::OnEvent(SFEvent& event) {
  SFEVENT the_event = event.GetCode();  
  switch (the_event) {
  case SFEVENT_QUIT:
    is_running = false;
    break;
  case SFEVENT_UPDATE:
    OnUpdateWorld();
    OnRender();
    break;
  case SFEVENT_PLAYER_LEFT_KEYUP:
    player->movingLeft = false;
    break;
  case SFEVENT_PLAYER_RIGHT_KEYUP:
    player->movingRight = false;
    break;
  case SFEVENT_PLAYER_UP_KEYUP:
    player->movingUp = false;
    break;
  case SFEVENT_PLAYER_DOWN_KEYUP:
    player->movingDown = false;
    break;
  case SFEVENT_PLAYER_LEFT_KEYDOWN:
    player->movingLeft = true;
    break;
  case SFEVENT_PLAYER_RIGHT_KEYDOWN:
    player->movingRight = true;
    break;
  case SFEVENT_PLAYER_UP_KEYDOWN:
    player->movingUp = true;
    break;
  case SFEVENT_PLAYER_DOWN_KEYDOWN:
    player->movingDown = true;
    break;
  }
}
コード例 #5
0
ファイル: SFApp.cpp プロジェクト: LeeNorton85/StarshipFontana
/**
 * Handle all events that come from SDL.
 * These are timer or keyboard events.
 */
void SFApp::OnEvent(SFEvent& event) {
  SFEVENT the_event = event.GetCode();
  switch (the_event) {
  case SFEVENT_QUIT:
    is_running = false;
    break;
  case SFEVENT_UPDATE:
    OnUpdateWorld();
    OnRender();
    break;

  case SFEVENT_PLAYER_UP:
    player->GoNorth();

    for(auto w : walls) {
      for(auto c : coins) {
	for(auto a : aliens) {

      if(player->CollidesWith(w)) {
	 player->GoSouth();
	} else if (player->CollidesWith(c)) {

	 std::wstring s1(L"You Win");
	 std::wcout << s1 << std::endl;

	is_running = false;
	} else if (player->CollidesWith(a)) {

	 std::wstring s2(L"You Lose");
	 std::wcout << s2 << std::endl;
	 is_running = false;
	}
	}
    }}
 
    break;
    
  case SFEVENT_PLAYER_DOWN:
    player->GoSouth();

    for(auto w : walls) {
      for(auto c : coins) {
	for(auto a : aliens) {

      if(player->CollidesWith(w)) {
	 player->GoNorth();
	} else if (player->CollidesWith(c)) {

	 std::wstring s1(L"You Win");
	 std::wcout << s1 << std::endl;

	is_running = false;
	} else if (player->CollidesWith(a)) {

	 std::wstring s2(L"You Lose");
	 std::wcout << s2 << std::endl;
	 is_running = false;
	}
	}
    }}
 
    break;
    
  case SFEVENT_PLAYER_LEFT:
    player->GoWest();

    for(auto w : walls) {
      for(auto c : coins) {
	for(auto a : aliens) {

      if(player->CollidesWith(w)) {
	 player->GoEast();
	} else if (player->CollidesWith(c)) {

	 std::wstring s1(L"You Win");
	 std::wcout << s1 << std::endl;

	is_running = false;
	} else if (player->CollidesWith(a)) {

	 std::wstring s2(L"You Lose");
	 std::wcout << s2 << std::endl;
	 is_running = false;
	}
	}
    }}
 
    break;
    
  case SFEVENT_PLAYER_RIGHT:
    player->GoEast();
    
      for(auto w : walls) {
      for(auto c : coins) {
	for(auto a : aliens) {

      if(player->CollidesWith(w)) {
	 player->GoWest();
	} else if (player->CollidesWith(c)) {

	 std::wstring s1(L"You Win");
	 std::wcout << s1 << std::endl;

	is_running = false;
	} else if (player->CollidesWith(a)) {

	 std::wstring s2(L"You Lose");
	 std::wcout << s2 << std::endl;
	 is_running = false;


	}
	}
    }}
 
    break;

// Win/Lose Message seems to be printed a large number of times, but not always the same amount
// I think this may have to do with the collision.
// I needed to abandon a score/points related victory as it seemed that the game was detecting
// multiple hits per projectile, 1 bullet was hitting 10+ times, as it passed through an object coin/alien
// this meant that my scoring threshold for victory was being met in 1-2 shots.
// as the number of times that each target was hit seemed to vary
// i could not use a work around of just increasing the score limit, as sometimes this limit would/would not
// be reached. As such, i opted to make the victory condition simply to collect a coin.
// it appears that the player is comming into contact with the victory coin, many times before the game closes.

   
  case SFEVENT_FIRE:
    fire ++;
    FireProjectile();
    break;

// Unable to figure this out I haven't left myself enough time to have a proper go at it.

/*  case SFEVENT_MOVE1:
  for(auto a : aliens) {
  a->Move1();
  break;
}
  case SFEVENT_MOVE2:
  for(auto a : aliens) { 
  a->Move2();
  break;
}

*/

  }
}