Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Oliver-Ginster
unregistriert
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include "Framework.hpp" #include "Game.hpp" int main(int argc, char *argv[]) { atexit(SDL_Quit); if (g_pFramework->Init (800, 720, 16, true) == false) return (0); CGame Game; Game.Init (); Game.Run (); Game.Quit (); g_pFramework->Del (); return (0); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
#include "Game.hpp" CGame::CGame () { m_pSpriteBackground = NULL; m_pSpriteWall = NULL; m_pSpriteRoad = NULL; } void CGame::Init () { m_pSpriteBackground = new CSprite; m_pSpriteBackground->Load ("picture/field.jpg"); m_pSpriteWall = new CSprite; m_pSpriteWall->Load ("picture/wall.jpg"); m_pSpriteRoad = new CSprite; m_pSpriteRoad->Load ("picture/road.jpg"); m_pSpriteRoad->SetColorKey (255, 0, 255); m_bGameRun = true; } void CGame::Quit () { if (m_pSpriteBackground != NULL) { delete (m_pSpriteBackground); m_pSpriteBackground = NULL; } if (m_pSpriteWall != NULL) { delete (m_pSpriteWall); m_pSpriteWall = NULL; } if (m_pSpriteRoad != NULL) { delete (m_pSpriteRoad); m_pSpriteRoad = NULL; } } void CGame::Run () { while (m_bGameRun == true) { ProcessEvents (); g_pFramework->Update (); g_pFramework->Clear (); m_pSpriteBackground->Render (); RenderWalls (); RenderRoads (); } } void CGame::ProcessEvents () { SDL_Event Event; if (SDL_PollEvent (&Event))// Gab es ein Even? { // Ja, also schauen welches: switch (Event.type) { case (SDL_QUIT): { m_bGameRun = false; }break; case (SDL_KEYDOWN):// Wurde eine Taste gedrückt? { switch (Event.key.keysym.sym) { case (SDLK_ESCAPE): { m_bGameRun = false; }break; } }break; }// Ende von switch }// Ende von if } void CGame::CreateWalls () { CWall Wall; float YPos = 1; float XPos = 1; Wall.Init (m_pSpriteWall, XPos, YPos); m_WallList.push_back (Wall); } void CGame::CreateRoads () { CRoad Road; float YPos = 600; float XPos = 600; Road.Init (m_pSpriteRoad, XPos, YPos); m_RoadList.push_back (Road); } void CGame::RenderWalls () { list<CWall>::iterator It; for (It = m_WallList.begin (); It != m_WallList.end (); ++It) { It->Render (); } } void CGame::RenderRoads () { list<CRoad>::iterator It; for (It = m_RoadList.begin (); It != m_RoadList.end (); ++It) { It->Render (); } } |
C-/C++-Quelltext |
|
1 2 3 4 |
class CGame { ... } // <- hier |
Oliver-Ginster
unregistriert
Oliver-Ginster
unregistriert
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 |
{ /* * The /GS security cookie must be initialized before any exception * handling targetting the current image is registered. No function * using exception handling can be called in the current image until * after __security_init_cookie has been called. */ __security_init_cookie(); return __tmainCRTStartup(); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
#include "Game.hpp" CGame::CGame () { m_pSpriteBackground = NULL; m_pSpriteWall = NULL; m_pSpriteRoad = NULL; } void CGame::Init () { m_pSpriteBackground = new CSprite; m_pSpriteBackground->Load ("picture/field.jpg"); m_pSpriteWall = new CSprite; m_pSpriteWall->Load ("picture/wall.jpg"); m_pSpriteRoad = new CSprite; m_pSpriteRoad->Load ("picture/road.jpg"); m_pSpriteRoad->SetColorKey (255, 0, 255); m_bGameRun = true; } void CGame::Quit () { if (m_pSpriteBackground != NULL) { delete (m_pSpriteBackground); m_pSpriteBackground = NULL; } if (m_pSpriteWall != NULL) { delete (m_pSpriteWall); m_pSpriteWall = NULL; } if (m_pSpriteRoad != NULL) { delete (m_pSpriteRoad); m_pSpriteRoad = NULL; } } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Game::Game () : m_spriteBackground(new Sprite("picture/field.jpg")), m_spriteWall(new Sprite("picture/wall.jpg")), m_spriteRoad(new Sprite("picture/road.jpg", 255, 0, 255)), m_run(true) {} Game::~Game () { delete m_spriteBackground; delete m_spriteWall; delete m_spriteRoad; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
void CGame::CreateWalls () { CWall Wall; float YPos = 1; float XPos = 1; Wall.Init (m_pSpriteWall, XPos, YPos); m_WallList.push_back (Wall); } void CGame::CreateRoads () { CRoad Road; float YPos = 600; float XPos = 600; Road.Init (m_pSpriteRoad, XPos, YPos); m_RoadList.push_back (Road); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 |
void Game::createWalls() { m_walls.push_back(Wall(m_pSpriteWall, 1.f, 1.f)); } void Game::createRoads() { m_roads.push_back(Road(m_pSpriteRoad, 600.f, 600.f)); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
void CGame::RenderWalls () { list<CWall>::iterator It; for (It = m_WallList.begin (); It != m_WallList.end (); ++It) { It->Render (); } } void CGame::RenderRoads () { list<CRoad>::iterator It; for (It = m_RoadList.begin (); It != m_RoadList.end (); ++It) { It->Render (); } } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 |
void Game::renderWalls() const { std::for_each(m_walls.begin(), m_walls.end(), std::mem_fun_ref(&Wall::render)); } void Game::renderRoads () const { std::for_each(m_roads.begin(), m_roads.end(), std::mem_fun_ref(&Road::render)); } |
Oliver-Ginster
unregistriert
Oliver-Ginster
unregistriert
Werbeanzeige