Created
June 7, 2012 19:49
-
-
Save mloc/2891147 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SFML/Graphics.hpp> | |
#include <iostream> | |
#include <String> | |
using std::string; | |
string map ="\ | |
SSSSSSSSSS\ | |
SWWWWWWWWS\ | |
SWFFFFFFWS\ | |
SWFFFFFFWS\ | |
SWFFFFFFWS\ | |
SWFFFFFFWS\ | |
SWFFFFFFWS\ | |
SWFFFFFFWS\ | |
SWWWWWWWWS\ | |
SSSSSSSSSS"; | |
int main() | |
{ | |
std::cout << map; | |
// Create the main window | |
sf::RenderWindow App(sf::VideoMode(640, 640), "SFML window"); | |
// Load a sprite to display | |
sf::Image PlayerImg; | |
if (!PlayerImg.LoadFromFile("dude.png")) | |
return EXIT_FAILURE; | |
sf::Sprite PlayerSpr(PlayerImg); | |
sf::Image FloorImg; | |
if (!FloorImg.LoadFromFile("floor.png")) | |
return EXIT_FAILURE; | |
sf::Sprite FloorSpr(FloorImg); | |
sf::Image WallImg; | |
if (!WallImg.LoadFromFile("wall.png")) | |
return EXIT_FAILURE; | |
sf::Sprite WallSpr(WallImg); | |
sf::Image SpaceImg; | |
if (!SpaceImg.LoadFromFile("space.png")) | |
return EXIT_FAILURE; | |
sf::Sprite SpaceSpr(SpaceImg); | |
int rotadd = 0; | |
// Start the game loop | |
while (App.IsOpened()) | |
{ | |
// Process events | |
sf::Event Event; | |
while (App.GetEvent(Event)) | |
{ | |
// Close window : exit | |
if (Event.Type == sf::Event::Closed) | |
App.Close(); | |
} | |
// Clear screen | |
App.Clear(); | |
// Draw the sprite | |
string::iterator iter; | |
int ix = 0, iy = 0; | |
for(iter=map.begin(); iter < map.end(); iter++) | |
{ | |
sf::Sprite * spr; | |
switch(*iter) | |
{ | |
case 'S': | |
spr = &SpaceSpr; | |
break; | |
case 'W': | |
spr = &WallSpr; | |
break; | |
case 'F': | |
spr = &FloorSpr; | |
break; | |
} | |
spr->SetPosition(ix*32,iy*32); | |
App.Draw(*spr); | |
if(++ix >= 10) | |
{ | |
ix = 0; | |
iy += 1; | |
} | |
} | |
// Update the window | |
App.Display(); | |
} | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment