本文整理汇总了C++中Level::Draw方法的典型用法代码示例。如果您正苦于以下问题:C++ Level::Draw方法的具体用法?C++ Level::Draw怎么用?C++ Level::Draw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Level
的用法示例。
在下文中一共展示了Level::Draw方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Draw
void Draw(Core::Graphics& graphics){
if (isEditingSpaceship){
editor.Draw(graphics);
}
else{
graphics.SetColor(defaultColor);
if(!isMainMenu && !isControls){
{
PROFILE("LevelDraw");
lvl.Draw(graphics);
}
{
PROFILE("ParticlesDraw");
manager->Draw(graphics);
}
}
else if (isControls){
Controls::Draw(graphics);
}
else{
menu.Draw(graphics);
}
}
Debug::DrawMemoryState(graphics, SCREEN_HEIGHT);
}
示例2: draw_game
void draw_game(RenderWindow &window, Level &lvl, std::list<Entity*>::iterator &it, std::list<Entity*> &entities, PLAYER &Player, PlayerScores &plScores, int levelNumber)
{
init_font font;
window.clear(Color(107, 140, 255));
lvl.Draw(window);
for (it = entities.begin();it != entities.end();it++)
(*it)->draw(window);
Player.draw(window);
plScores.draw(window, levelNumber);
if (Player.isWin)
{
font.textFinish.setPosition(view.getCenter().x - 120, view.getCenter().y);
window.draw(font.textFinish);
font.textWin.setPosition(view.getCenter().x - 200, view.getCenter().y- 20);
window.draw(font.textWin);
}
else
if (!Player.life)
{
font.textFinish.setPosition(view.getCenter().x - 120, view.getCenter().y);
window.draw(font.textFinish);
font.textDead.setPosition(view.getCenter().x - 40, view.getCenter().y - 20);
window.draw(font.textDead);
}
window.display();
}
示例3: main
int main()
{
RenderWindow window(VideoMode(1200, 800), "sds");
Level lv;
lv.LoadFromFile("Test map.tmx");
std::vector<Object> mapObj;
mapObj = lv.GetObjects("solid");
//Event event;
Texture hero; ///Текстура нашего игрока
hero.loadFromFile("ScarletRun2Right.png");
Texture heroLeft;
heroLeft.loadFromFile("ScarletRun2Left.png");
Animation PlayerAnim[4];
PlayerAnim[0].setSpriteSheet(hero);
PlayerAnim[0].loadFromXml("SkarletMoveRight.xml");
PlayerAnim[1].setSpriteSheet(hero);
PlayerAnim[1].loadFromXml("SkarletMoveRight.xml");
PlayerAnim[2].setSpriteSheet(hero);
PlayerAnim[2].loadFromXml("SkarletMoveRight.xml");
PlayerAnim[3].setSpriteSheet(heroLeft);
PlayerAnim[3].loadFromXml("SkarletMoveLeft.xml");
Hero her;
her.setHeroAnimation(PlayerAnim);
her.setHeroPossition(0, 20);
her.setHeroAnimationSpeed(1.0f);
her.setHeroSpeed(20);
sf::Clock frameClock;// Наши часики
float speed = 80.f;
while (window.isOpen())
{
sf::Time frameTime = frameClock.restart();
window.clear();
lv.Draw(window);
her.updateAndDrawHero(frameTime, mapObj, window);
window.display();
}
return 0;
}
示例4: wmain
//.........这里部分代码省略.........
// 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
int mouse_x = e.button.x;
int mouse_y = e.button.y;
if (playBtn.IsClicked(mouse_x, mouse_y))
{
gameState = PLAY;
}
else if (exitBtn.IsClicked(mouse_x, mouse_y))
{
quit = true;
}
}
}// End detect button click
background.Draw(r);
playBtn.Draw(r);
exitBtn.Draw(r);
break;
case PLAY:
newTime = SDL_GetTicks();
delta = newTime - oldTime;
oldTime = newTime;
en.Update(delta);
lvl.Draw(r);
en.Draw(r);
en1.Update(delta);
en1.Draw(r);
en.Draw(r);
player.Update(r, delta);
player.Draw(r);
//calculateFPS();
break;
}
InputManager::GetInstance()->UpdateState();
r.End();
}
//Remove timer in case the call back was not called
SDL_WaitThread(threadID, NULL);
return EXIT_SUCCESS;
}
示例5: StartGame
//.........这里部分代码省略.........
Object playerObject = lvl.GetObject("player");
Player player(texture, "Player1", playerObject.rect.left, playerObject.rect.top, 32, 32);
player.health = game.health;
player.heart = game.hearts;
while (window.isOpen() && (!game.restart))
{
float time = float(clock.getElapsedTime().asMicroseconds());
clock.restart();
time = time / 800;
Event event;
Vector2i pixelPos = Mouse::getPosition(window);
Vector2f pos = window.mapPixelToCoords(pixelPos);
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed || (Keyboard::isKeyPressed(Keyboard::Escape) && game.isPause))
{
window.close();
game.restart = false;
}
if (event.type == Event::MouseButtonPressed)
{
pos.y = float(player.teleportY);
if ((event.key.code == Mouse::Left) && (player.doesOpenPortal))
{
CreatePortal(portals, game, "blue", pos, texture);
portal.play();
}
else if (event.key.code == Mouse::Right && (player.doesOpenPortal))
{
CreatePortal(portals, game, "yellow", pos, texture);
portal.play();
}
}
if (player.isTeleporting)
{
TeleportPlayer(player, portals);
teleport.play();
}
if (Keyboard::isKeyPressed(Keyboard::Return))
{
game.isPause = false;
}
if (Keyboard::isKeyPressed(Keyboard::P))
{
game.isPause = true;
}
if (Keyboard::isKeyPressed(Keyboard::Tab) && game.isPause)
{
game.restart = true;
}
}
if (player.isExit)
{
if (game.isEndLevel)
{
game.isPause = true;
}
else
{
game.level++;
game.restart = true;
game.health = player.health;
game.hearts = player.heart;
}
}
for (auto *e : enemies)
{
if ((*e).name == "flyEnemy" && (*e).isShoot)
{
CreateBullet(bullets, (*e).GetRect(), player, texture);
shoot.play();
}
}
EntitiesIntersection(player, enemies, portals, bullets, damage);
if (player.alive)
{
setPlayerCoordinateForView(game.camera, player.GetPos().x, player.GetPos().y);
}
if (!game.isPause)
{
UpdateEnemies(objects, enemies, time, player);
UpdatePortals(portals, time);
UpdateBullets(objects, bullets, time);
player.Update(objects, time, pos, game.portalH);
}
window.setView(game.camera);
window.clear();
lvl.Draw(window);
DrawEnemies(window, enemies);
DrawPortals(window, portals);
DrawBullets(window, bullets);
DrawStatistic(window, &game, player, game.camera);
window.draw(player.sprite);
DrawAllMessages(player, game, window);
music.setLoop(true);
window.display();
}
return game.restart;
}
示例6: startGame
//.........这里部分代码省略.........
time = time / 800;
Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
for (it = entities.begin(); it != entities.end();) {
Entity *b = *it;
b->update(time);
if (b->life == false) {
it = entities.erase(it);
delete b;
}
else it++;
}
for (it = entities.begin(); it != entities.end(); it++) {
if (((*it)->name == "MovingPlatform") && ((*it)->getRect().intersects(p.getRect())))
{
Entity *movPlat = *it;
if (p.dy>0)
if (p.y + p.height < movPlat->y + movPlat->height)
{
p.y = movPlat->y - p.height + 3;
p.x += movPlat->dx*time;
p.dy = 0;
p.onGround = true;
}
}
if ((*it)->getRect().intersects(p.getRect())) {
if ((*it)->name == "EasyEnemy" || (*it)->name == "MediumEnemy") {
if ((p.dy>0) && (p.onGround == false) && (p.y + p.height < (*it)->y + (*it)->height)) {
p.dy = -0.3;
(*it)->lives--;
if ((*it)->name == "EasyEnemy")
(*it)->sprite.setTextureRect(IntRect(60, 8, 16, 8));
p.Score++;
}
else {
if (((*it)->lives != 0)) {
deathSound.play();
p.lives--;
lives--;
return false;
}
}
}
if ((*it)->name == "fire") {
deathSound.play();
p.lives--;
lives--;
return false;
}
if ((*it)->name == "coin") {
p.Score++;
coinSound.play();
(*it)->life = false;
}
if ((*it)->name == "exit") {
stageSound.play();
startLevel++;
return false;
}
}
for (it2 = entities.begin(); it2 != entities.end(); it2++) {
if ((*it)->getRect() != (*it2)->getRect())
if (((*it)->getRect().intersects((*it2)->getRect())) && ((*it)->name == "EasyEnemy")) {
(*it)->dx *= -1;
(*it)->sprite.scale(-1.5, 1.5);
}
}
}
p.update(time);
if (Keyboard::isKeyPressed(Keyboard::Escape)) {
lives = 0;
return false;
}
window.setView(view);
window.clear(Color(167, 207, 218));
lvl.Draw(window);
for (it = entities.begin(); it != entities.end(); it++) {
window.draw((*it)->sprite);
}
window.draw(p.sprite);
window.display();
}
return 0;
}
示例7: RunGame
//.........这里部分代码省略.........
if(MegaMan.x > 670 && MegaMan.x <1440){
if(MegaMan.y <907 && MegaMan.y>875){
MegaMan.Health = 0;
MegaMan.hit=true;
}
}
if(MegaMan.Health == 0){
MegaMan.isDead();
death();
window.close();
}
}
for(it=entities.begin();it!=entities.end();it++)
{
//1. враги
if ((*it)->Name=="Enemy")
{
Entity *enemy = *it;
if (MegaMan.getRect().intersects( enemy->getRect() ))
if (MegaMan.dy>0) { enemy->dx=0; MegaMan.dy=-0.2; enemy->Health=0;}
else if (!MegaMan.hit) {
MegaMan.Health-=10; MegaMan.hit=true;
if(MegaMan.Health == 0){
MegaMan.isDead();
death();
window.close();
}
if (MegaMan.dir){
MegaMan.x+=10;
} else{
MegaMan.x-=10;}
}
for (std::list<Entity*>::iterator it2=entities.begin(); it2!=entities.end(); it2++)
{
Entity *bullet = *it2;
if (bullet->Name=="Bullet")
if ( bullet->Health>0)
if (bullet->getRect().intersects( enemy->getRect() ) )
{ bullet->Health=0; enemy->Health-=5;}
}
}
//2. движущиеся платформы
if ((*it)->Name=="MovingPlatform")
{
Entity *movPlat = *it;
if (MegaMan.getRect().intersects( movPlat->getRect() ) )
if (MegaMan.dy>0)
if (MegaMan.y+MegaMan.h<movPlat->y+movPlat->h)
{MegaMan.y=movPlat->y - MegaMan.h + 3; MegaMan.x+=movPlat->dx*time; MegaMan.dy=0; MegaMan.STATE=PLAYER::stay;}
}
//3.. и т.д.
}
/////////////////////отображаем на экран/////////////////////
view.setCenter( MegaMan.x,MegaMan.y);
window.setView(view);
background.setPosition(view.getCenter());
window.draw(background);
lvl.Draw(window);
for(it=entities.begin();it!=entities.end();it++)
(*it)->draw(window);
if(loadlevel == 1){
if(enemyCount >= 7 && MegaMan.x == 28 && MegaMan.y ==534){
window.close();
victory();
}
}
if(loadlevel == 2){
if(enemyCount == 5){
window.close();
victory();
}
}
MegaMan.draw(window);
healthBar.draw(window);
window.display();
//printf("%f %f\n",MegaMan.x, MegaMan.y);
}
}
示例8: mainLevel
//.........这里部分代码省略.........
if(mop.isPlayed == false)
{
mop.intersect("mop", lvl);
mop.move(pos);
}
if(light.isPlayed == false)
{
light.intersect("light", lvl);
light.move(pos);
}
if(ball.isPlayed == true && books.isPlayed == true){
if(mop.isPlayed == true)
key.intersect("key", lvl);
if(key.isPlayed == false)
key.move(pos);
}
if(ball.isPlayed == false && books.isPlayed == true){
if(cat.sprite.getGlobalBounds().intersects(ob.rect))
{
if(cntMeow == 0)
{
ball.falling(event, window, pos, lvl, time);
glass.play();
ball.isPlayed = true;
ball.intersect("ball", lvl);
}
}
}
cat.Update(time);
window.clear(Color::Black);
lvl.Draw(window);
if(cat.room == 0)
window.draw(level);
if(cat.room == 1)
window.draw(level2);
if(cat.room == 2)
window.draw(level3);
window.draw(posters.sprite);
window.draw(bed.sprite);
if(key.isPlayed == true)
window.draw(cabinetEnd.sprite);
else
window.draw(cabinet.sprite);
window.draw(upShelf.sprite);
window.draw(flower.sprite);
if(ball.isPlayed == false)
window.draw(ball.sprite);
else
{
window.draw(brokenBall.sprite);
window.draw(key.sprite);
}
window.draw(books.sprite);
if(mou.isPlayed == false){
window.draw(mou.sprite);
}
else
window.draw(light.sprite);
window.draw(toys.sprite);
示例9: RunGame
//.........这里部分代码省略.........
while (window.isOpen())
{
float time = clock.getElapsedTime().asMicroseconds();
clock.restart();
time = time/500; // здесь регулируем скорость игры
if (time > 40) time = 40;
Event event;
while (window.pollEvent(event))
{
if (event.type == Event::Closed || Keyboard::isKeyPressed(Keyboard::Escape))
window.close();
if (event.type == Event::KeyPressed)
if (event.key.code==Keyboard::Space)
entities.push_back(new Bullet(anim2,lvl,Mario.x+18,Mario.y+18,Mario.dir) );
}
if (Keyboard::isKeyPressed(Keyboard::Left)) Mario.key["L"]=true;
if (Keyboard::isKeyPressed(Keyboard::Right)) Mario.key["R"]=true;
if (Keyboard::isKeyPressed(Keyboard::Up)) Mario.key["Up"]=true;
if (Keyboard::isKeyPressed(Keyboard::Down)) Mario.key["Down"]=true;
if (Keyboard::isKeyPressed(Keyboard::Space)) Mario.key["Space"]=true;
for(it=entities.begin();it!=entities.end();)
{
Entity *b = *it;
b->update(time);
if (b->life==false) { it = entities.erase(it); delete b;}
else it++;
}
Mario.update(time);
healthBar.update(Mario.Health);
for(it=entities.begin();it!=entities.end();it++)
{
//1. враги
if ((*it)->Name=="Enemy")
{
Entity *enemy = *it;
if (enemy->Health<=0) continue;
if (Mario.getRect().intersects( enemy->getRect() ))
if (Mario.dy>0) { enemy->dx=0; Mario.dy=-0.2; enemy->Health=0;}
else if (!Mario.hit) { Mario.Health-=5; Mario.hit=true;
if (Mario.dir) Mario.x+=10; else Mario.x-=10;}
for (std::list<Entity*>::iterator it2=entities.begin(); it2!=entities.end(); it2++)
{
Entity *bullet = *it2;
if (bullet->Name=="Bullet")
if ( bullet->Health>0)
if (bullet->getRect().intersects( enemy->getRect() ) )
{ bullet->Health=0; enemy->Health-=5;}
}
}
//2. движущиеся платформы
if ((*it)->Name=="MovingPlatform")
{
Entity *movPlat = *it;
if (Mario.getRect().intersects( movPlat->getRect() ) )
if (Mario.dy>0)
if (Mario.y+Mario.h<movPlat->y+movPlat->h)
{Mario.y=movPlat->y - Mario.h + 3; Mario.x+=movPlat->dx*time; Mario.dy=0; Mario.STATE=PLAYER::stay;}
}
//3.. и т.д.
}
/////////////////////отображаем на экран/////////////////////
view.setCenter( Mario.x,Mario.y);
window.setView(view);
background.setPosition(view.getCenter());
window.draw(background);
lvl.Draw(window);
for(it=entities.begin();it!=entities.end();it++)
(*it)->draw(window);
Mario.draw(window);
healthBar.draw(window);
window.display();
}
}
示例10: Render
void MyGame::Render(SDL_Surface* pDestSurface) {
debugLevel.Draw( pDestSurface );
player.Draw( pDestSurface );
}
示例11: main
//.........这里部分代码省略.........
while(window.isOpen())
{
sf::Event evt;
while(window.pollEvent(evt))
{
switch(evt.type)
{
case sf::Event::Closed:
window.close();
break;
case sf::Event::KeyPressed:
if(evt.key.code == sf::Keyboard::W && playerBody->GetLinearVelocity().y == 0)
playerBody->SetLinearVelocity(b2Vec2(0.0f, -15.0f));
if(evt.key.code == sf::Keyboard::D)
playerBody->SetLinearVelocity(b2Vec2(5.0f, 0.0f));
if(evt.key.code == sf::Keyboard::A)
playerBody->SetLinearVelocity(b2Vec2(-5.0f, 0.0f));
break;
}
}
world.Step(1.0f / 60.0f, 1, 1);
for(b2ContactEdge* ce = playerBody->GetContactList(); ce; ce = ce->next)
{
b2Contact* c = ce->contact;
for(int i = 0; i < coinBody.size(); i++)
if(c->GetFixtureA() == coinBody[i]->GetFixtureList())
{
coinBody[i]->DestroyFixture(coinBody[i]->GetFixtureList());
coin.erase(coin.begin() + i);
coinBody.erase(coinBody.begin() + i);
}
for(int i = 0; i < enemyBody.size(); i++)
if(c->GetFixtureA() == enemyBody[i]->GetFixtureList())
{
if(playerBody->GetPosition().y < enemyBody[i]->GetPosition().y)
{
playerBody->SetLinearVelocity(b2Vec2(0.0f, -10.0f));
enemyBody[i]->DestroyFixture(enemyBody[i]->GetFixtureList());
enemy.erase(enemy.begin() + i);
enemyBody.erase(enemyBody.begin() + i);
}
else
{
int tmp = (playerBody->GetPosition().x < enemyBody[i]->GetPosition().x)
? -1 : 1;
playerBody->SetLinearVelocity(b2Vec2(10.0f * tmp, 0.0f));
}
}
}
for(int i = 0; i < enemyBody.size(); i++)
{
if(enemyBody[i]->GetLinearVelocity() == b2Vec2_zero)
{
int tmp = (rand() % 2 == 1) ? 1 : -1;
enemyBody[i]->SetLinearVelocity(b2Vec2(5.0f * tmp, 0.0f));
}
}
b2Vec2 pos = playerBody->GetPosition();
view.setCenter(pos.x + screenSize.x / 4, pos.y + screenSize.y / 4);
window.setView(view);
player.sprite.setPosition(pos.x, pos.y);
for(int i = 0; i < coin.size(); i++)
coin[i].sprite.setPosition(coinBody[i]->GetPosition().x, coinBody[i]->GetPosition().y);
for(int i = 0; i < enemy.size(); i++)
enemy[i].sprite.setPosition(enemyBody[i]->GetPosition().x, enemyBody[i]->GetPosition().y);
window.clear();
lvl.Draw(window);
window.draw(player.sprite);
for(int i = 0; i < coin.size(); i++)
window.draw(coin[i].sprite);
for(int i = 0; i < enemy.size(); i++)
window.draw(enemy[i].sprite);
window.display();
}
return 0;
}