-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.h
90 lines (78 loc) · 2.49 KB
/
input.h
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
int GetKeys()
{
while ( SDL_PollEvent(&event) )
{
if ( event.type == SDL_QUIT ) { done = 1; }
if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_ESCAPE ) { done = 1; }
if ( event.key.keysym.sym == SDLK_SPACE )
{
Player1.fire();
}
}
}
//reset the speeds
Player1.yspeed = 0;
Player1.xspeed = 0;
keyDown = false;
//This gets the state of a key opposed to decting when one was pressed.
Uint8 *keystate = SDL_GetKeyState(NULL);
if(keystate[SDLK_UP] && keyDown==false)
{
//alter the dimentions if the tank has moved anything but 180 degrees
if(Player1.direction == 1 || Player1.direction == 3)
{
float dirTemp = Player1.x;
Player1.x = Player1.y;
Player1.y = dirTemp;
}
Player1.direction = 0;
Player1.yspeed = -Player1.yvel;
Player1.xspeed = 0;
keyDown=true;
}
else if(keystate[SDLK_RIGHT] && keyDown==false)
{
//alter the dimentions if the tank has moved anything but 180 degrees
if(Player1.direction == 0 || Player1.direction == 2)
{
float dirTemp = Player1.x;
Player1.x = Player1.y;
Player1.y = dirTemp;
}
Player1.direction = 1;
Player1.xspeed = Player1.yvel;
Player1.yspeed = 0;
keyDown=true;
}
else if(keystate[SDLK_DOWN] && keyDown==false)
{
//alter the dimentions if the tank has moved anything but 180 degrees
if(Player1.direction == 1 || Player1.direction == 3)
{
float dirTemp = Player1.x;
Player1.x = Player1.y;
Player1.y = dirTemp;
}
Player1.direction = 2;
Player1.yspeed = Player1.yvel;
Player1.xspeed = 0;
keyDown=true;
}
else if(keystate[SDLK_LEFT] && keyDown==false)
{
//alter the dimentions if the tank has moved anything but 180 degrees
if(Player1.direction == 0 || Player1.direction == 2)
{
float dirTemp = Player1.x;
Player1.x = Player1.y;
Player1.y = dirTemp;
}
Player1.direction = 3;
Player1.xspeed = -Player1.yvel;
Player1.yspeed = 0;
keyDown=true;
}
return 0;
}