コード例 #1
0
ファイル: Game.cpp プロジェクト: anneomcl/MyGame
void Game::start_loss()
{
	if (_gameState != Uninitialized)
		return;

	game_victory = 0;
	_mainWindow.create(sf::VideoMode(1024, 768, 32), "Anne McLaughlin Demo");
	_view.reset(sf::FloatRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
	_view.setViewport(sf::FloatRect(0, 0, 1.0f, 1.0f));

	PlayerCharacter * player = (PlayerCharacter *)_gameObjectManager.getByTypeSingle("PlayerCharacter");
	player->setPosition(500, 1000);
	player->coins = 0;
	player->lives = 0;
	player->grounded = true;


	reset_mystery_blocks();


	_gameState = Game::ShowingSplashLoss;

	while (!isExiting())
	{
		gameLoop();
	}
	_mainWindow.close();
}
コード例 #2
0
// ------------------------------------------------------------------------------------------------
void PlayerCharacterView :: DrawHUD() {
    DrawScoreBoard();

	if(pc->TargetId() != INVALID_ID) {
		PlayerCharacter* target = game->GetCharacter(pc->TargetId());
		targetRingSceneNode->setPosition(target->Pos());
		targetRingSceneNode->setVisible(true);
			/*
			// Draw target health:
			DrawText(	target->Pos().x - camPos.x - surfaceTargetRing->w/2 - 10,
						target->Pos().y - camPos.y - surfaceTargetRing->h/2 - 20,
						ToString(target->Health()));
			*/
	}
	else {
		targetRingSceneNode->setVisible(false);
	}

		/*
		vector3df charScreenPos = myPc->Pos() - camPos;

		// Draw health:
		DrawText(charScreenPos.x - 10, charScreenPos.y - 20, ToString(myPc->Health()));
		*/
} // ----------------------------------------------------------------------------------------------
コード例 #3
0
void PlayerSpawner::spawnPlayer(float x, float y, float z, uint32_t player_id, uint32_t team_id, uint32_t version, bool is_pinto)
{
	bool self = false;

	if(player_id == NetworkManager::instance()->player_id)
		self = true;

	PlayerCharacter *player = new PlayerCharacter(self, scene, "PixelMan.mesh",
            x, y + 50, z,
            0, 0, 0, 1,
            10, 10, 10,
            player_id, version, is_pinto);
	player->team_id = team_id;
	if(player->team_id == BLUE_TEAM)
	{
		player->switchToBlueTeam();
	}

	GameState::instance()->players[player_id] = player;

	if(self)
	{
		GameState::instance()->player = player;
	}
}
コード例 #4
0
ファイル: PlayerCharacter.cpp プロジェクト: smarmy/DPOC
PlayerCharacter* PlayerCharacter::create(const std::string& name, const std::string& className, int level)
{
  PlayerCharacter* character = new PlayerCharacter;

  character->m_name = name;
  character->m_class = player_class_ref(className);

  character->m_faceTexture = cache::loadTexture(character->m_class.faceTexture);
  character->m_textureRect = character->m_class.textureRect;

  character->m_status.push_back(get_status_effect("Normal"));

  character->m_attributes["level"] = make_attribute(0);
  character->m_attributes["exp"] = make_attribute(0);

  for (int i = 1; i <= level; i++)
  {
    character->setLevel(i, false);

    if (i < level)
    {
      // Gain enough exp for the current level.
      character->getAttribute("exp").max = character->expForLevel();
      reset_attribute(character->getAttribute("exp"));
    }
  }

  reset_attribute(character->m_attributes["hp"]);
  reset_attribute(character->m_attributes["mp"]);

  return character;
}
コード例 #5
0
Ogre::Vector3 PlayerSpawner::spawnPlayer(uint32_t player_id, bool is_pinto)
{
	Ogre::Vector3 position;
	if(GameState::instance()->team_mode == FFA || GameState::instance()->game_mode == PINTO)
	{
		position = free_positions[RAND_RANGE(0, free_positions.size())];
	}
	else
	{
		float rand_x = RAND_RANGE(0, SPAWN_RAND_RADIUS_MAX) - SPAWN_RAND_RADIUS_MAX;
		float rand_z = RAND_RANGE(0, SPAWN_RAND_RADIUS_MAX) - SPAWN_RAND_RADIUS_MAX;
		if(NetworkManager::instance()->player_team_id_map[player_id] == RED_TEAM)
		{
			position = red_position;
			position.x = position.x + rand_x;
			position.z = position.z + rand_z;
		}
		else
		{
			position = blue_position;
			position.x = position.x + rand_x;
			position.z = position.z + rand_z;
		}
	}
	
	bool self = false;

	if(player_id == NetworkManager::instance()->player_id)
	{
		self = true;
	}

	uint32_t version = RAND_RANGE(0, 5);

	PlayerCharacter *player = new PlayerCharacter(self, scene, "PixelMan.mesh",
            position.x, position.y + 50, position.z,
            0, 0, 0, 1,
            10, 10, 10,
            player_id, version, is_pinto);

	player->team_id = NetworkManager::instance()->player_team_id_map[player_id];
	if(player->team_id == BLUE_TEAM)
	{
		player->switchToBlueTeam();
	}

	GameState::instance()->players[player_id] = player;

	if(self)
	{
		GameState::instance()->player = player;
	}

	NetworkManager::instance()->vital->setPlayerRespawn(position.x, position.y, position.z, 
				player_id, NetworkManager::instance()->player_team_id_map[player_id], version, is_pinto);

	return position;
}
コード例 #6
0
void AddSkillExperience(ActorValueInfo * info, float points)
{
    if(info) {
        UInt32 actorValue = LookupActorValueByName(info->name);
        if(actorValue < ActorValueList::kNumActorValues) {
            PlayerCharacter* pPC = (*g_thePlayer);
            pPC->AdvanceSkill(actorValue, points, 0, 0);
        }
    }
}
コード例 #7
0
ファイル: LuaPlayerCharacter.cpp プロジェクト: noam-c/EDEn
static int PlayerCharacterL_Remove(lua_State* luaVM)
{
   PlayerCharacter* playerCharacter = luaW_check<PlayerCharacter>(luaVM, 1);
   if (playerCharacter == nullptr)
   {
      return lua_error(luaVM);
   }

   playerCharacter->removeFromMap();

   return 0;
}
コード例 #8
0
static bool Cmd_SetPlayerSkeletonPath_Execute(COMMAND_ARGS)
{
	*result = 0.0;

	char skelliePath[kMaxMessageLength];
	PlayerCharacter* pc = *g_thePlayer;
	if (pc)
	{
		if (ExtractArgs(PASS_EXTRACT_ARGS, skelliePath)) {
			*result = pc->SetSkeletonPath(skelliePath) ? 1.0 : 0.0;
		}
	}

	return true;
}
コード例 #9
0
void Battle::addEntity( Entity *entity )
{
	PlayerCharacter *playerCharacter = dynamic_cast<PlayerCharacter*>(entity);
	EnemyCharacter *enemyCharacter = dynamic_cast<EnemyCharacter*>(entity);

	if (playerCharacter != NULL) {
		myPlayerCharacters.push_back(playerCharacter);
		playerCharacter->setBattle(this);
	} else if (enemyCharacter != NULL) {
		myEnemyCharacters.push_back(enemyCharacter);
		enemyCharacter->setBattle(this);
	} else {
		myOtherEntities.push_back(entity);
	}
}
コード例 #10
0
static int PlayerCharacterL_Remove(lua_State* luaVM)
{
   int nargs = lua_gettop(luaVM);
   
   switch(nargs)
   {
      case 1:
      {
         PlayerCharacter* playerCharacter = luaW_check<PlayerCharacter>(luaVM, 1);
         if (playerCharacter)
         {
            playerCharacter->removeFromMap();
         }
         break;
      }
   }
   return 0;
}
コード例 #11
0
ファイル: Game.cpp プロジェクト: anneomcl/MyGame
void Game::handleCamera()
{
	PlayerCharacter * player = (PlayerCharacter *)_gameObjectManager.get("PlayerCharacter");

	float pos_x = player->getPosition().x + 10 - (SCREEN_WIDTH / 2);
	float pos_y = player->getPosition().y + 10 - (SCREEN_HEIGHT / 2);

	if (pos_x < 0)
	{
		pos_x = 0;
	}

	if (pos_y < 0)
	{
		pos_y = 0;
	}

	_view.reset(sf::FloatRect(pos_x, pos_y, SCREEN_WIDTH, SCREEN_HEIGHT));
}
コード例 #12
0
static int PlayerCharacterL_SetLocation(lua_State* luaVM)
{
   int nargs = lua_gettop(luaVM);
   
   switch(nargs)
   {
      case 3:
      {
         PlayerCharacter* playerCharacter = luaW_check<PlayerCharacter>(luaVM, 1);
         if (playerCharacter)
         {
            int x = lua_tointeger(luaVM, 2);
            int y = lua_tointeger(luaVM, 3);
            playerCharacter->setLocation(shapes::Point2D(x, y));
         }
         break;
      }
   }
   return 0;
}
コード例 #13
0
ファイル: Game.cpp プロジェクト: anneomcl/MyGame
void Game::start_victory(void)
{
	if (_gameState != Uninitialized)
		return;

	game_victory = 0;
	_mainWindow.create(sf::VideoMode(1024, 768, 32), "Anne McLaughlin Demo");
	_view.reset(sf::FloatRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
	_view.setViewport(sf::FloatRect(0, 0, 1.0f, 1.0f));

	PlayerCharacter * player = (PlayerCharacter *) _gameObjectManager.getByTypeSingle("PlayerCharacter");
	player->setPosition(500, 1000);
	player->coins = 0;
	player->lives = 0;
	player->grounded = true;


	reset_mystery_blocks();

	/*Background * bg = new Background();
	level_width = bg->getSprite().getGlobalBounds().width;
	level_height = bg->getSprite().getGlobalBounds().height;

	createFloor();

	_gameObjectManager.add("Background", bg);

	createLevelBlocks();

	rigidBodyCoords = findRigidBodies();*/

	_gameState = Game::ShowingSplashVictory;

	while (!isExiting())
	{
		gameLoop();
	}
	_mainWindow.close();
}
コード例 #14
0
ファイル: movable.cpp プロジェクト: Techie123/book
void Bullet::hit( Movable *m )
{

    Movable *shooter = g_app->getMovable(shooterID);
    if( !shooter ){
        toDelete = true;
        return;
    }
    
    if( shooter->typeID == MOVABLE_HUMAN ){
        if( m=g_app->m_floor->hitMovableType( coord, MOVABLE_ENEMY ) ){
            toDelete = true;
            Enemy *e = static_cast<Enemy*>(m);
            e->attacked(3, static_cast<Character*>(shooter));
        }
    } else if( shooter->typeID == MOVABLE_ENEMY ){
        if( m=g_app->m_floor->hitMovableType( coord, MOVABLE_HUMAN ) ){
            toDelete = true;
            PlayerCharacter *pc = static_cast<PlayerCharacter*>(m);
            pc->attacked(3,static_cast<Character*>(shooter));
        }
    }
}
コード例 #15
0
ファイル: LuaPlayerCharacter.cpp プロジェクト: noam-c/EDEn
static int PlayerCharacterL_SetLocation(lua_State* luaVM)
{
   PlayerCharacter* playerCharacter = luaW_check<PlayerCharacter>(luaVM, 1);
   if (playerCharacter == nullptr)
   {
      return lua_error(luaVM);
   }

   int x;
   if(!ScriptUtilities::getParameter(luaVM, 2, 1, "x", x))
   {
      return lua_error(luaVM);
   }

   int y;
   if(!ScriptUtilities::getParameter(luaVM, 2, 2, "y", y))
   {
      return lua_error(luaVM);
   }

   playerCharacter->setLocation({ x, y });

   return 0;
}
コード例 #16
0
void Battle::privPlayerCharacterLogic()
{
	for (int i = 0; i < (int)myPlayerCharacters.size(); i++)
	{
		PlayerCharacter* p = myPlayerCharacters[i];
		p->onLogic();
		if (p->isReadyForAction() && !privIsPlayerCharacterInActionQueue(p))
		{
			myPlayerCharacterActionQueue.push_back(p);
		}
	}

	while(myPlayerCharacterActionQueue.size() > 0)
	{	
		PlayerCharacter* p = myPlayerCharacterActionQueue.front();
		if (!p->isReadyForAction() || p->isDead())
		{
			myPlayerCharacterActionQueue.pop_front();
		}
		else
		{
			myPlayerCharacterWithActionChoice = p;
			break;
		}
	}


	if (myPlayerCharacterActionQueue.size() == 0)
	{
		myPlayerCharacterWithActionChoice = 0;
	}

	std::vector<PlayerCharacter *>::iterator it;
	for (it = myPlayerCharacters.begin(); it != myPlayerCharacters.end();)
	{
		if ((*it)->isToBeDestroyed())
		{
			it = myPlayerCharacters.erase(it);
		}
		else
		{
			++it;
		}
	}
}
コード例 #17
0
ファイル: Game.cpp プロジェクト: anneomcl/MyGame
void Game::handleSurfaces()
{
	PlayerCharacter * player = (PlayerCharacter *)_gameObjectManager.get("PlayerCharacter");
	RigidSurface_Brick * v_block = (RigidSurface_Brick *)_gameObjectManager.get("block_victory");

	if (player->getSprite().getGlobalBounds().intersects(v_block->getSprite().getGlobalBounds()))
	{
		game_victory = 1;
	}

	if (display_coin)
	{
		coin_animation_frames--;
		if (coin_animation_frames <= 0)
		{
			display_coin = false;
			Coin * coin = (Coin *) _gameObjectManager.getByTypeSingle("Coin");
			coin->isVisible = false;
			coin_animation_frames = 150;
		}
	}

	for (int i = 0; i < rigidBodyCoords.size(); ++i)
	{
		if (player->getSprite().getGlobalBounds().intersects(rigidBodyCoords[i]->getSprite().getGlobalBounds()))
		{
			if (rigidBodyCoords[i]->getType() == "RigidSurface_Mystery")
			{
				RigidSurface_Mystery * block = (RigidSurface_Mystery *) rigidBodyCoords[i];
				if (block->times_hit < 3)
				{
					display_coin = true;
					Coin * new_coin = new Coin();
					initObject(new_coin,
						sf::Vector2f(rigidBodyCoords[i]->getSprite().getGlobalBounds().left, rigidBodyCoords[i]->getSprite().getGlobalBounds().top - 100)
						, "coin" + std::to_string(player->coins));
					player->coins++;
					block->times_hit++;
					std::cout << "Coins: "  << player->coins << std::endl;
					std::cout << "Lives: " << player->lives << std::endl;
					if (player->coins % 10 == 0)
					{
						player->lives++;
					}
				}
				else
				{
					//block is dead
				}

				player->velocity.x = -player->velocity.x;
				if (player->velocity.y < 0)
				{
					player->velocity.y = -2* player->velocity.y;
				}

				if (player->velocity.y > 0)
				{
					player->setPosition(player->getPosition().x, player->getPosition().y - 1);
					player->grounded = true;
				}
			}

			else
			{
				if (player->velocity.y > 0)
				{
					player->setPosition(player->getPosition().x, player->getPosition().y - 1);
					//player->velocity.x = -player->velocity.x;
					//TO-DO: Distinguish between bumping horizontally and landing vertically on blocks.
					//TO-DO: Make kitty stop floating
					player->grounded = true;
				}
				else
				{
					player->velocity.x = -player->velocity.x;
				}
				
			}
		}
	}
}
コード例 #18
0
ファイル: GrenadePickup.cpp プロジェクト: hawncho/zombiegame
void GrenadePickup::ActivateEffect(PlayerCharacter& player)
{
	player.AddGrenade();
}
コード例 #19
0
ファイル: Game.cpp プロジェクト: anneomcl/MyGame
void Game::gameLoop()
{
	sf::Event currentEvent;
	_mainWindow.pollEvent(currentEvent);

	switch (_gameState)
	{
		case Game::ShowingMenu:
		{
			showMenu();
			break;
		}

		case Game::ShowingSplash:
		{
			showSplashScreen("C:/Users/Anne/Documents/Visual Studio 2013/Projects/MyGame/Graphics/MyGameScreen.png");
			break;
		}

		case Game::ShowingSplashVictory:
		{
			showSplashScreen("C:/Users/Anne/Documents/Visual Studio 2013/Projects/MyGame/Graphics/Victory.png");
			break;
		}

		case Game::ShowingSplashLoss:
		{
			showSplashScreen("C:/Users/Anne/Documents/Visual Studio 2013/Projects/MyGame/Graphics/Loss.png");
			break;
		}

		case Game::Playing:
		{
			rigidBodyCoords = findRigidBodies();
			_gameObjectManager.updateAll();
			//_mainWindow.draw(*coinstring);
			_gameObjectManager.drawAll(_mainWindow);


			PlayerCharacter * player = (PlayerCharacter *)_gameObjectManager.get("PlayerCharacter");

			if (player->getPosition().y > 2000)
			{
				if (player->lives > 0)
				{
					player->lives--;
					start_again();
				}

				else
				{
					_gameState = Loss;
					start_loss();
					break;
				}
			}

			handleSurfaces();

			handleCamera();

			_mainWindow.setView(_view);

			_mainWindow.display();


			if (currentEvent.type == sf::Event::Closed) _gameState = Game::Exiting;

			if ((currentEvent.type == sf::Event::KeyPressed) && (currentEvent.key.code == sf::Keyboard::Escape))
				showMenu();

			if(game_victory != 0)
			{
				_gameState = Game::Victory;
			}

			break;
		}

		case Game::Victory:
		{
			_gameState = Game::Uninitialized;
			start_victory();
			break;
		}

		case Game::Loss:
		{
			_gameState = Game::Uninitialized;
			start_loss();
			break;
		}
	}
}
コード例 #20
0
ファイル: Game.cpp プロジェクト: anneomcl/MyGame
void Game::start_again()
{
	PlayerCharacter * player = (PlayerCharacter *)_gameObjectManager.getByTypeSingle("PlayerCharacter");
	player->setPosition(500, 1000);
	player->grounded = true;
}