本文整理汇总了C++中Enemy::Update方法的典型用法代码示例。如果您正苦于以下问题:C++ Enemy::Update方法的具体用法?C++ Enemy::Update怎么用?C++ Enemy::Update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Enemy
的用法示例。
在下文中一共展示了Enemy::Update方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Update
// Update: draw background
update_status ModuleEnemy::Update()
{
p2List_item<Enemy*>* tmp = active.getFirst();
p2List_item<Enemy*>* tmp_next = active.getFirst();
while (tmp != NULL)
{
Enemy* p = tmp->data;
tmp_next = tmp->next;
if (p->Update() == false)
{
delete p;
active.del(tmp);
}
else
{
App->renderer->Blit(graphics, p->position.x, p->position.y, &(p->current_anim->GetCurrentFrame()));
if (p->fx_played == false)
{
p->fx_played = true;
App->audio->PlayFx(p->fx);
}
}
tmp = tmp_next;
}
return UPDATE_CONTINUE;
}
示例2: Update
void EnemyManager::Update()
{
for (int i = 0; i < m_enemies->size(); i++)
{
Enemy* e = m_enemies->at(i);
if (e->hp < 0)
{
delete e;
m_enemies->erase(m_enemies->begin() + i);
i--;
continue;
}
e->Update();
}
}
示例3: Update
void Game::Update( void* gameInst, Entity** entities, int startIndex, int numEntities, double deltaTime )
{
Game* game = (Game*)gameInst;
int maxIndex = startIndex + numEntities;
for (int i = startIndex; i < maxIndex; ++i)
{
Enemy* enemy = dynamic_cast<Enemy*>(entities[i]);
Player* player = dynamic_cast<Player*>(entities[i]);
if (enemy)
{
if ( (enemy->behavior.tasks[enemy->currentTaskIndex])->DoTask( enemy, deltaTime ) )
{
enemy->currentTaskIndex = (enemy->currentTaskIndex + 1) % enemy->behavior.tasks.size();
}
enemy->Update( deltaTime );
}
else if (player)
{
float horizontalSpeed = 0;
float verticalSpeed = 0;
if (Input::InputDown(KeyCode::KEY_W))
{
verticalSpeed = -1;
}
else if (Input::InputDown(KeyCode::KEY_S))
{
verticalSpeed = 1;
}
if (Input::InputDown(KeyCode::KEY_D))
{
horizontalSpeed = 1;
}
else if (Input::InputDown(KeyCode::KEY_A))
{
horizontalSpeed = -1;
}
player->MoveVertically(verticalSpeed);
player->MoveHorizontally(horizontalSpeed);
}
}
}
示例4: wmain
int wmain()
{
#pragma region Other Stuff
// Hide cursor
SDL_ShowCursor(0);
gameState = PLAY;
//The window we'll be rendering to
SDL_Window* window = NULL;
//The surface contained by the window
SDL_Surface* screenSurface = NULL;
//SDL
Renderer r = Renderer(SCREEN_WIDTH, SCREEN_HEIGHT);
AudioManager::GetInstance()->Init();
AudioManager::GetInstance()->LoadMedia();
AudioManager::GetInstance()->PlaySoundEffect(1);
SDL_Point ePos;
ePos.x = 100;
ePos.y = 100;
Enemy en = Enemy(200, 200, 62 / 3, 77 / 3, r, 0);
Enemy en1 = Enemy(400, 100, 62 / 3, 77 / 3, r, 0);
Level lvl = Level(r);
// MENU
SDL_Point bPos;
bPos.x = 0;
bPos.y = 0;
Menu background = Menu(bPos, SCREEN_WIDTH, SCREEN_HEIGHT, r, 0, "background");
SDL_Point pPos;
pPos.x = SCREEN_WIDTH / 3;
pPos.y = SCREEN_HEIGHT / 4;
Menu playBtn = Menu(pPos, 263, 44, r, 0, "playBtn");
SDL_Point e2Pos;
e2Pos.x = (SCREEN_WIDTH / 2) - 50;
e2Pos.y = (SCREEN_HEIGHT / 2) - 20;
Menu exitBtn = Menu(e2Pos, 111, 45, r, 0, "exitBtn");
// Player
SDL_Point playerPos;
playerPos.x = SCREEN_WIDTH / 2 - 25;
playerPos.y = SCREEN_HEIGHT / 2 - 10;
Player player = Player(playerPos, 44, 32, r, 0);
// THREADS \\
// Run the thread
//Player * p = (); // pointer to object
void * pv = &player; // pointer to void
Player * p2 = static_cast<Player *>(pv); // pointer to the same object
int data;
SDL_Thread* threadID = SDL_CreateThread(renderThreadFunction, "RenderThread", (void*)p2);
// THREADS \\
#pragma endregion
#pragma region SDL STUFF
bool quit = false;
float oldTime = SDL_GetTicks();
float delta = 0.f;
float newTime = 0.f;
SDL_Event e;
fpsTimer.start();
while (!quit)
{
while (SDL_PollEvent(&e) != 0)
{
InputManager::GetInstance()->UpdatePolledEvents(e);
}
if (e.button.button == SDL_SCANCODE_ESCAPE)
quit = true;
// THREADS \\
// THREADS \\
//controls gameState added in game menu feature
r.Begin();
switch (gameState)
{
case MENU:
//detect button click
if (e.type == SDL_MOUSEBUTTONDOWN)
{
//If the left mouse button was pressed
if (e.button.button == SDL_BUTTON_LEFT)
{
//Get the mouse offsets
//.........这里部分代码省略.........
示例5: update
void BasicApp::update()
{
if (game_state == Game_Demo)
{
for (list<Asteroid>::iterator itr = asteroids.begin(); itr!=asteroids.end(); itr++)
{
itr->Update();
}
}
else if(game_state == GAME_Play)
{
for (list<Asteroid>::iterator itr = asteroids.begin(); itr!=asteroids.end(); itr++)
{
itr->Update();
}
for (list<Bullet>::iterator itr_bullet = currentShip.m_Bullets.begin(); itr_bullet!=currentShip.m_Bullets.end();)
{
for (list<Asteroid>::iterator itr_astroid = asteroids.begin(); itr_astroid!=asteroids.end();)
{
if(checkCollision(itr_bullet->getCenter(),itr_astroid->getCenter(), itr_bullet->getRadius(), itr_astroid->getRadius()))
{
particleManager.Start_Explosion(itr_astroid->getCenter(),10,1.0f,1.0f);
engine->play2D("explode_high.wav");
if(itr_astroid->m_size >= 0.5)
{
Asteroid asteroid_1, asteroid_2;
asteroid_1.m_state = Asteroid_Medium;
asteroid_1.Init(rand()%2+1, 0.3);
asteroid_1.m_Vel.y = -itr_astroid->m_Vel.y*1.5;
asteroid_1.m_Vel.x = -itr_astroid->m_Vel.x*1.5;
asteroid_1.m_Pos = itr_astroid->m_Pos;
asteroid_2.m_state = Asteroid_Medium;
asteroid_2.Init(rand()%2+1, 0.3);
asteroid_2.m_Vel.y = itr_astroid->m_Vel.y*1.5;
asteroid_2.m_Vel.x = itr_astroid->m_Vel.x*1.5;
asteroid_2.m_Pos = itr_astroid->m_Pos;
asteroids.push_back(asteroid_1);
asteroids.push_back(asteroid_2);
itr_astroid = asteroids.erase(itr_astroid);
itr_astroid->m_bHit = true;
score +=100;
}
else if(itr_astroid->m_state == Asteroid_Medium)
{
Asteroid asteroid_1, asteroid_2;
asteroid_1.m_state = Asteroid_Small;
asteroid_1.Init(rand()%2+1, 0.1);
asteroid_1.m_Vel.y = -itr_astroid->m_Vel.y*2;
asteroid_1.m_Vel.x = -itr_astroid->m_Vel.x*2;
asteroid_1.m_Pos = itr_astroid->m_Pos;
asteroid_2.m_state = Asteroid_Small;
asteroid_2.Init(rand()%2+1, 0.1);
asteroid_2.m_Vel.y = itr_astroid->m_Vel.y*2;
asteroid_2.m_Vel.x = itr_astroid->m_Vel.x*2;
asteroid_2.m_Pos = itr_astroid->m_Pos;
asteroids.push_back(asteroid_1);
asteroids.push_back(asteroid_2);
itr_astroid = asteroids.erase(itr_astroid);
itr_astroid->m_bHit = true;
score +=100;
}
else
{
score +=50;
itr_astroid->m_bHit = true;
itr_astroid = asteroids.erase(itr_astroid);
}
itr_bullet->m_Hit = true;
break;
}
else
{
itr_astroid++;
}
}
if(itr_bullet->m_Hit)
//.........这里部分代码省略.........
示例6: main
int main()
{
int shotsFired = 0;
fstream out;
out.open("shotsFired.txt");
fstream in;
string filename = "GameName.txt";
in.open(filename.c_str());
string windowName;
if(!in.fail()){
windowName = accessStream(in, true);
}
World world;
Player * player = new Player();
PlayerProjectile projectile;
PlayerProjectile chargePro(1);
Enemy * enemy = new Enemy();
sf::Music music;
if(!music.openFromFile("assets/sound/level0.wav")){
cout << "Failed to open music file" << endl;
}
music.setVolume(25);
music.play();
//Floor* street = new Floor("street");
sf::Sprite background;
sf::Texture bgScene;
bgScene.loadFromFile("assets/art/background.png");
bgScene.setSmooth(false);
background.setTexture(bgScene);
background.scale(bgScaleFactor, bgScaleFactor);
sf::RenderWindow window(sf::VideoMode(screenWidth, screenHeight), windowName);
//window.setVerticalSyncEnabled(true);
window.setFramerateLimit(60);
sf::Sprite EnemyObject;
EnemyObject.scale(scaleFactor, scaleFactor);
sf::Sprite PlayerObject;
PlayerObject.scale(scaleFactor, scaleFactor);
EnemyObject.setTexture(enemy->Update());
sf::Vector2f pStart(400, 50);
sf::Vector2f eStart(200, 230);
EnemyObject.move(eStart);
PlayerObject.setTexture(player->Update());
PlayerObject.move(pStart);
vector<sf::Sprite> ObjsInView;
vector<PlayerProjectile> ProjsInView;
vector<Enemy*> EnemiesInView;
//vector<Floor*> TilesInView;
ObjsInView.push_back(PlayerObject);
for(unsigned i = 0; i < world.TileMap.size(); i++){
for(unsigned j = 0; j < world.TileMap[i].length(); ++j){
if(world.TileMap[i][j] == 'S') {
Floor* f = new Floor("street", j, i);
world.TilesInView.push_back(f);
}
}
}
sf::RectangleShape floorCollider(sf::Vector2f(800.f, 45.f));
floorCollider.setPosition(0.f, 370.f);
floorCollider.setFillColor(sf::Color::Transparent);
floorCollider.setOutlineColor(sf::Color::Red);
// Start the game loop
while (window.isOpen())
{
window.clear();
// Process events
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed) {
window.close();
}
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::X)){
if(player->Shoot()){
PlayerProjectile lemon = projectile;
if(player->getPlayerState() == Player::idleRight
|| player->getPlayerState() == Player::jumpRight
|| player->getPlayerState() == Player::runRight
|| player->getPlayerState() == Player::fallRight) {
lemon.setVelocity(7);
lemon.setSprite(PlayerProjectile::right);
} else {
//lemonSprite.setTexture(projectile.lemonLeft);
lemon.setVelocity(-7);
lemon.setSprite(PlayerProjectile::left);
}
lemon.setPosition(PlayerObject.getPosition());
ProjsInView.push_back(lemon);
}
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::C)){
if(player->Shoot()){
PlayerProjectile lemon = chargePro;
if(player->getPlayerState() == Player::idleRight
//.........这里部分代码省略.........
示例7: update
// Update game5
void update( ESContext* ctx, float deltaTime )
{
if(getKeyState(KeyCodes::KEY_ESCAPE))
{
deinit(ctx);
exit(0);
}
if(player.isHeJumping == true)
{
PlayHop();
}
int number = button1.Update(deltaTime);
switch(gameState)
{
case 0:
menu.background->setPosition(0,0);
insertText.background->setPosition(400,400);
dead.background->setPosition(400,400);
//gameState = 1;
button1.buttons->setPosition(-6, 1);
switch (number)
{
case 1:
gameState = 1;
break;
case 2:
break;
case 3:
break;
}
break;
case 1:
switch (letterState)
{
case 0:
insertText.background->setPosition(0,0.35f);
button1.buttons->setPosition(-400, 400);
insertText.background->setPosition(0,0.35f);
score->m_nameText1->setText( to_string(score->letters[score->lindex]));
score->nameText1->setPosition(-0.5f,0);
break;
case 1:
score->m_nameText2->setText( to_string(score->letters[score->lindex]));
score->nameText2->setPosition(0,0);
break;
case 2:
score->m_nameText3->setText( to_string(score->letters[score->lindex]));
score->nameText3->setPosition(0.5f,0);
break;
case 3:
//gameState = 2;
//button1.buttons->setPosition(4, 4);
if(getKeyState(KeyCodes::KEY_RETURN))
{
menu.background->setPosition(400,400);
insertText.background->setPosition(400,400);
score->nameText1->setPosition(-0.5f,-5);
score->nameText2->setPosition(0,-5);
score->nameText3->setPosition(0.5f,-5);
gameState = 2;
}
break;
}
if(isButtonPressed == false)
{
if(getKeyState(KeyCodes::KEY_DOWN))
{
score->lindex++;
isButtonPressed = true;
if (score->lindex > 25)
{
score->lindex = 25;
}
}
if(getKeyState(KeyCodes::KEY_UP))
{
score->lindex--;
isButtonPressed = true;
if (score->lindex < 0)
{
score->lindex = 0;
}
}
if(getKeyState(KeyCodes::KEY_RETURN))
{
letterState++;
scoreList.push_back(score->letters[score->lindex]);
isButtonPressed = true;
//.........这里部分代码省略.........
示例8: main
int main()
{
sf::RenderWindow AppWindow(sf::VideoMode(g_WndWidth, g_WndHeight), "Mario by Roman P.");
sf::Texture tx;
tx.loadFromFile("..\\Data\\Mario_tileset.png");
//tx.loadFromFile("..\\Data\\fang.png");
sf::Sprite MapTiles(tx);
float fCurrentFrame = 0.0f;
Player player(tx);
Enemy enemy;
enemy.Set(tx, 750, 208);
sf::SoundBuffer sb;
sb.loadFromFile("..\\Data\\Jump.ogg");
sf::Sound soundJump(sb);
sf::Music music;
music.openFromFile("..\\Data\\Mario_Theme.ogg");
music.setLoop(true);
music.play();
sf::Clock clock;
//sf::RectangleShape RecShape(sf::Vector2f(SIZE_TILE, SIZE_TILE));
g_fOffsetY = player.FRect.top - g_WndHeight/ 2;
while (AppWindow.isOpen())
{
float time = (float)clock.getElapsedTime().asMicroseconds();
clock.restart();
time = time / 700;
sf::Event ev;
while (AppWindow.pollEvent(ev))
{
if (ev.type == sf::Event::Closed)
AppWindow.close();
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
player.dx = -0.1f;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
player.dx = 0.1f;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
if (player.bOnGround)
{
player.dy = -0.25f;
player.bOnGround = false;
soundJump.play();
}
}
player.Update(time);
enemy.Update(time);
if (player.FRect.intersects(enemy.FRect))
{
if (enemy.bLife)
{
if (player.dy > 0)
{
enemy.dx = 0;
player.dy = -0.2f;
enemy.bLife = false;
}
else
player.SSprite.setColor(sf::Color::Red);
}
//player.SSprite.setColor(sf::Color::Red);
}
if (player.FRect.left > g_WndWidth / 2)
g_fOffsetX = player.FRect.left - g_WndWidth/2;
//if (player.FRect.top > g_WndHeight/ 2)
// g_fOffsetY = player.FRect.top - g_WndHeight / 2;
AppWindow.clear(sf::Color(107, 140, 255, 255));
// load map
for (int i = 0; i < H; i++)
{
for (int j = 0; j < W; j++)
{
if (TileMap[i][j] == 'P')
MapTiles.setTextureRect(sf::IntRect(96, 112, SIZE_TILE, SIZE_TILE));
if (TileMap[i][j] == 'r')
MapTiles.setTextureRect(sf::IntRect(112, 112, SIZE_TILE, SIZE_TILE));
if (TileMap[i][j] == 'k')
//.........这里部分代码省略.........