-
Notifications
You must be signed in to change notification settings - Fork 5
/
Pad.h
33 lines (30 loc) · 789 Bytes
/
Pad.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
#pragma once
#include "common.h"
#include "client.h"
class Keyboard;
class Pad {
public:
bool up, down, left, right;
Pad() : up(false), down(false), left(false), right(false) {
}
void readKeyboard(Keyboard *kbd);
void getVec( Vec2 *v ){
float dx=0,dy=0;
if( up ) dy=1.0;
if( down ) dy=-1.0;
if( right ) dx=1.0;
if( left ) dx=-1.0;
if(dx!=0 || dy!=0){
normalize( &dx, &dy, 1 );
}
v->x = dx;
v->y = dy;
}
DIR4 getDir() {
if(up) return DIR4_UP; else if(down) return DIR4_DOWN; else if(right) return DIR4_RIGHT; else if(left) return DIR4_LEFT; else return DIR4_NONE;
}
void setUpKey( bool u) { up = u; }
void setDownKey( bool d) { down = d; }
void setLeftKey( bool l ) { left = l; }
void setRightKey( bool r ) { right = r; }
};