-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patha.cpp
100 lines (63 loc) · 1.74 KB
/
a.cpp
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
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <iostream>
int main(){
enum Direction { Down=0, Left=48, Right=96, Up=144};
sf::Vector2i source(32,Down);
float frameCounter =0, frameSpeed=500, switchFrame=100;
sf::RenderWindow window;
window.create(sf::VideoMode(700,700),"Pirate of the Quizma");
sf::RectangleShape player(sf::Vector2f(100.0f,100.0f));
sf::Texture playerTexture;
playerTexture.loadFromFile("spritewalk.png");
player.setTexture(&playerTexture);
player.setPosition(275,550);
sf::Music music;
music.openFromFile("GOT.wav");
window.setKeyRepeatEnabled(false);
while (window.isOpen()){
sf::Event 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();
else if((event.key.code == sf::Keyboard::Return))
music.play();
/*case sf::Event::ButtonPressed:
if() */
default:
break;
}
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)){
source.y=Up;
player.move(0,-1);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)){
source.y=Left;
player.move(-1,0);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)){
source.y=Right;
player.move(1,0);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)){
source.y=Down;
player.move(0,1);
}
source.x +=32;
if (source.x >=playerTexture.getSize().x){
source.x=0;
}
player.setTextureRect(sf::IntRect(source.x,source.y,32,48));
window.draw(player);
window.display();
window.clear();
}
return 0;
}