-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.cc
68 lines (60 loc) · 1.07 KB
/
player.cc
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
#include "vector.h"
#include "gameObj.h"
#include "player.h"
#include <iostream>
#include <math.h>
#define PI 3.14159
Player::Player(){
pos.set(0,0);
vel.set(0,0);
angle=0;
}
Player::Player(Vector p, Vector v):
GameObj(p,v)
{
brakeAmt=.96;
angle=0;
}
void Player::accelerate(double c){
vel.add(c*cos(angle), c*sin(angle));
vel.limit(0,20);
accel=true;
}
void Player::rotate(double amount){
angle += amount;
if (angle>PI){
angle-=PI*2;
} else if(angle<-PI){
angle+=PI*2;
}
}
void Player::brake(){
brakeAmt=.7;
}
double Player::getAngle(){
//std::cout<<"angle"<<angle<<"\n";
return angle;
}
void Player::interact(std::vector<GameObj*>, std::vector<int> keys, double delta){
Vector ans (0,0);
accel=false;
for (int i=0;i<keys.size();i++){
int key=keys[i];
if (key == 38){
std::cout<<"accel\n";
accelerate(2.3);
}else if(key == 40){
std::cout<<"brake\n";
brake();
}else if(key == 37){
std::cout<<"left\n";
rotate(-.13);
}else if(key == 39){
std::cout<<"right\n";
rotate(.13);
}
}
pos.add(vel);
vel.mult(brakeAmt);
brakeAmt=.96;
}