aboutsummaryrefslogtreecommitdiffstats
path: root/src/UIClass.cpp
blob: 18e273e8f544b312b6c5e6b675a00ae4193b45dc (plain)
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
#include <UIClass.h>

extern Player player;
extern World *currentWorld;

void UIClass::handleEvents(){
	SDL_Event e;
	while(SDL_PollEvent(&e)){
		switch(e.type){
		case SDL_WINDOWEVENT:
			switch(e.window.event){
				case SDL_WINDOWEVENT_CLOSE:
					gameRunning = false;
				break;
			}
		case SDL_KEYDOWN:
			if(e.key.keysym.sym == SDLK_d) player.right = true;
			if(e.key.keysym.sym == SDLK_a) player.left = true;
			if(e.key.keysym.sym == SDLK_LSHIFT) player.speed = 3;
			if(e.key.keysym.sym == SDLK_SPACE){
				player.loc.y += HLINE*1.2;
				player.vel.y += .004;
			}
			if(e.key.keysym.sym == SDLK_i)
				if(currentWorld->behind){
					player.loc.x-=(currentWorld->getWidth()-currentWorld->behind->getWidth())/2; // Match player's location to new area
					currentWorld=currentWorld->behind;											 // Go to new area
					if(player.loc.x>-1+currentWorld->getWidth())								 // Don't let player fall out of world if previous area was bigger
						player.loc.x=-1+currentWorld->getWidth()-player.width-HLINE;
				}
			if(e.key.keysym.sym == SDLK_k)
				if(currentWorld->infront){
					player.loc.x+=(currentWorld->infront->getWidth()-currentWorld->getWidth())/2; // Match player's location to new area
					currentWorld=currentWorld->infront;											  // Go to new area
					if(player.loc.x>-1+currentWorld->getWidth())								  // Don't let player fall out of world if previous area was bigger
						player.loc.x=-1+currentWorld->getWidth()-player.width-HLINE;
				}
			break;
		case SDL_KEYUP:
			if(e.key.keysym.sym == SDLK_d) player.right = false;
			if(e.key.keysym.sym == SDLK_a) player.left = false;
			if(e.key.keysym.sym == SDLK_LSHIFT) player.speed = 1.0;
		
			if(e.key.keysym.sym == SDLK_ESCAPE) gameRunning = false;
			break;
		}	
	}
}