-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathship.cpp
More file actions
48 lines (37 loc) · 1011 Bytes
/
Copy pathship.cpp
File metadata and controls
48 lines (37 loc) · 1011 Bytes
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
#define _USE_MATH_DEFINES
#include <cmath>
#include "ship.h"
#include "renderer.h"
Ship::Ship(): angel_(90), vx(0), vy(0)
{}
void Ship::tick(Keys keys, Settings settings, Vector acel)
{
if (keys[KEY_LEFT])
angel_ += 120.0f * settings.DELTA_T / 1000.0f;
if (keys[KEY_RIGHT])
angel_ -= 120.0f * settings.DELTA_T / 1000.0f;
move_[MOVE_FOREWARD] = keys[KEY_UP];
if (isFlying)
{
vx += accel * cos(angel_ * M_PI /180) * settings.DELTA_T/1000.0f;
vy += accel * sin(angel_* M_PI /180) * settings.DELTA_T/1000.0f;
if (vx < -velLimit)
vx = velLimit;
else if(vx > velLimit)
vx = velLimit;
if (vy < -velLimit)
vy = velLimit;
else if(vy > velLimit)
vy = velLimit;
}
else{
vx *= 0.6;
vy *= 0.6;
}
x += vx;
y += vy;
}
void Ship::draw(Renderer &p, int wChange, int hChange)
{
p.drawShip(x + wChange/2, y + hChange/2, angel_);
}