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
![]() |
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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
#include <iostream> #include <SFML/Graphics.hpp> #include <SFML/Audio.hpp> int main() { ////////////////////////////////Images and Sounds//////////////////////////////////// sf::RenderWindow Window(sf::VideoMode(800,600), "Pokémon 2.0", sf::Style::Close); /////Sprite///// enum direction {Down, Left, Right, Up}; sf::Vector2i source(1, Down); sf::Vector2i gsource(1, Down); sf::Texture tplayer; tplayer.loadFromFile("Sprites/player.png"); sf::Sprite player(tplayer); player.setPosition(360,250); player.setOrigin(16,16); sf::Texture tghost; tghost.loadFromFile("Sprites/Ghost.png"); sf::Sprite ghost(tghost); ghost.setPosition(417,15); sf::Texture tbackground; tbackground.loadFromFile("Sprites/Town.png"); sf::Sprite background(tbackground); background.setScale(2.087,1.873); background.setPosition(400,300); background.setOrigin((tbackground.getSize().x / 2),(tbackground.getSize().y / 2)); /////Music and Sound///// sf::Music backgroundmusic; backgroundmusic.openFromFile("Music and Sound/Pokemon_Theme.ogg"); backgroundmusic.setVolume(50); backgroundmusic.setLoop(true); backgroundmusic.play(); //Zeit sf::Clock clock; sf::Time time = clock.restart(); sf::Clock animationclockplayer; sf::Time animationtimeplayer = animationclockplayer.restart(); sf::Time animationtime2 = sf::milliseconds(200); sf::Clock animationclockghost; sf::Time animationtimeghost = animationclockghost.restart(); sf::Time animationtime3 = sf::milliseconds(100); ////////////////////////////////Runtime-Loop//////////////////////////////////// while(Window.isOpen()) { //time animationtimeplayer = animationclockplayer.getElapsedTime(); animationtimeghost = animationclockghost.getElapsedTime(); time = clock.getElapsedTime(); //Event-Loop sf::Event Event; while (Window.pollEvent(Event)) { switch (Event.type) { case sf::Event::Closed: Window.close(); backgroundmusic.stop(); break; case sf::Event::KeyPressed: if (Event.key.code == sf::Keyboard::Escape) { Window.close(); backgroundmusic.stop(); } break; } } /////Controls player///// if (sf::Keyboard::isKeyPressed) clock.restart(); if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { source.y = Down; player.move(0,0.1 * time.asMilliseconds()); } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { source.y = Left; player.move(-0.1 * time.asMilliseconds(),0); } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { source.y = Right; player.move(0.1 * time.asMilliseconds(),0); } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { source.y = Up; player.move(0,-0.1 * time.asMilliseconds()); } /////Kollisionen///// //outline if (player.getPosition().y < 46) //down player.move(0,0.1 * time.asMilliseconds()); else if (player.getPosition().x > 725) //left player.move(-0.1 * time.asMilliseconds(),0); else if (player.getPosition().x < 75) //right player.move(0.1 * time.asMilliseconds(),0); else if (player.getPosition().y > 555) //up player.move(0,-0.1 * time.asMilliseconds()); ////////////////////////////////Displaying//////////////////////////////////// //Animation player if (animationtimeplayer > animationtime2) { source.x++; animationclockplayer.restart(); } if(source.x * 32 >= tplayer.getSize().x) source.x = 0; //Animation ghost if (animationtimeghost > animationtime3) { gsource.x++; animationclockghost.restart(); if(gsource.x * 32 >= tghost.getSize().x) gsource.x = 0; } /////Updating and Drawing///// player.setTextureRect(sf::IntRect(source.x * 32, source.y * 32, 32, 32)); ghost.setTextureRect(sf::IntRect(gsource.x * 32, gsource.y * 32, 32, 32)); Window.clear(); Window.draw(background); //Window.draw(ghost); Window.draw(player); Window.display(); } backgroundmusic.stop(); return 0; } |
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
![]() |
C-/C++-Quelltext |
1 2 3 4 5 |
int *p = new int; // mach irgendwas mit p delete p; |
![]() |
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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
#include <iostream> #include <SFML/Graphics.hpp> #include <SFML/Audio.hpp> int main() { ////////////////////////////////Images and Sounds//////////////////////////////////// sf::RenderWindow Window(sf::VideoMode(800,600), "Pokémon 2.0", sf::Style::Close); /////Sprites///// enum direction {Down, Left, Right, Up}; sf::Vector2i source(1, Down); sf::Vector2i gsource(1, Down); sf::Texture *tplayer = new sf::Texture; tplayer->loadFromFile("Sprites/player.png"); sf::Sprite *player = new sf::Sprite; player->setTexture(*tplayer); player->setPosition(360,250); player->setOrigin(16,16); sf::Texture *tghost = new sf::Texture; tghost->loadFromFile("Sprites/Ghost.png"); sf::Sprite *ghost = new sf::Sprite; ghost->setTexture(*tghost); ghost->setPosition(417,15); sf::Texture *tbackground = new sf::Texture; tbackground->loadFromFile("Sprites/Town.png"); sf::Sprite *background = new sf::Sprite; background->setTexture(*tbackground); background->setScale(2.087,1.873); background->setPosition(400,300); background->setOrigin((tbackground->getSize().x / 2),(tbackground->getSize().y / 2)); /////Music and Sound///// sf::Music *backgroundmusic = new sf::Music; backgroundmusic->openFromFile("Music and Sound/Pokemon_Theme.ogg"); backgroundmusic->setVolume(50); backgroundmusic->setLoop(true); backgroundmusic->play(); //Zeit sf::Clock *clock = new sf::Clock; sf::Time *time = new sf::Time; *time = clock->restart(); sf::Clock *animationclockplayer = new sf::Clock; sf::Time *animationtimeplayer = new sf::Time; *animationtimeplayer = animationclockplayer->restart(); sf::Time *animationtime2 = new sf::Time; *animationtime2 = sf::milliseconds(200); sf::Clock *animationclockghost = new sf::Clock; sf::Time *animationtimeghost = new sf::Time; *animationtimeghost = animationclockghost->restart(); sf::Time *animationtime3 = new sf::Time; *animationtime3 = sf::milliseconds(100); ////////////////////////////////Runtime-Loop//////////////////////////////////// while(Window.isOpen()) { //time *animationtimeplayer = animationclockplayer->getElapsedTime(); *animationtimeghost = animationclockghost->getElapsedTime(); *time = clock->getElapsedTime(); //Event-Loop sf::Event *Event = new sf::Event; while (Window.pollEvent(*Event)) { switch (Event->type) { case sf::Event::Closed: Window.close(); break; case sf::Event::KeyPressed: if (Event->key.code == sf::Keyboard::Escape) { Window.close(); } break; } } /////Controls player///// if (sf::Keyboard::isKeyPressed) clock->restart(); if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { source.y = Down; player->move(0,0.1 * time->asMilliseconds()); } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { source.y = Left; player->move(-0.1 * time->asMilliseconds(),0); } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { source.y = Right; player->move(0.1 * time->asMilliseconds(),0); } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { source.y = Up; player->move(0,-0.1 * time->asMilliseconds()); } /////Kollisionen///// //outline if (player->getPosition().y < 46) //down player->move(0,0.1 * time->asMilliseconds()); else if (player->getPosition().x > 725) //left player->move(-0.1 * time->asMilliseconds(),0); else if (player->getPosition().x < 75) //right player->move(0.1 * time->asMilliseconds(),0); else if (player->getPosition().y > 555) //up player->move(0,-0.1 * time->asMilliseconds()); ////////////////////////////////Displaying//////////////////////////////////// //Animation player if (animationtimeplayer > animationtime2) { source.x++; animationclockplayer->restart(); } if(source.x * 32 >= tplayer->getSize().x) source.x = 0; //Animation ghost if (animationtimeghost > animationtime3) { gsource.x++; animationclockghost->restart(); if(gsource.x * 32 >= tghost->getSize().x) gsource.x = 0; } /////Updating and Drawing///// player->setTextureRect(sf::IntRect(source.x * 32, source.y * 32, 32, 32)); ghost->setTextureRect(sf::IntRect(gsource.x * 32, gsource.y * 32, 32, 32)); Window.clear(); Window.draw(*background); //Window.draw(ghost); Window.draw(*player); Window.display(); } backgroundmusic->stop(); delete clock; delete time; delete animationclockplayer; delete animationtimeplayer; delete animationclockghost; delete animationtimeghost; delete animationtime2; delete animationtime3; delete tplayer; delete player; delete tghost; delete ghost; delete tbackground; delete background; delete backgroundmusic; return 0; } |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »SwatzZ« (13.05.2013, 17:31)
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Werbeanzeige