-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathship.cpp
More file actions
89 lines (76 loc) · 1.98 KB
/
ship.cpp
File metadata and controls
89 lines (76 loc) · 1.98 KB
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
/***********************************************************************
* C++ File:
* Ship
* Author:
* Austin Jesperson & Emilio Ordonez
* Summary:
* An Ship in our simulation
************************************************************************/
#include "ship.h"
/******************************************
* SHIP : CONSTRUCTOR
*****************************************/
Ship::Ship()
{
angle = M_PI / 2.0;
radius = 10 * 40;
position.setPixelsX(-450.0);
position.setPixelsY(450.0);
velocity.setMeters(0.0, -2000.0);
acceleration.setMeters(0.0, 0.0);
rotationSpeed = 0.0;
}
/*****************************************
* SHIP : THURST
****************************************/
void Ship::thrust()
{
acceleration.setMetersX(2.0 * cos(angle - (M_PI / 2.0)));
acceleration.setMetersY(2.0 * sin(angle - (M_PI / 2.0)));
}
/******************************************
* SHIP : STOP THRUST
*****************************************/
void Ship::stopThrust()
{
acceleration.setMetersX(0.0);
acceleration.setMetersY(0.0);
}
/************************************************
* SHIP : MOVE
************************************************/
void Ship::move(bool isLeft, bool isRight, bool isDown)
{
if (isLeft && !isRight)
{
rotate(-.1);
}
if (!isLeft && isRight)
{
rotate(.1);
}
if (isDown)
{
isThrusting = true;
thrust();
}
if (!isDown)
{
isThrusting = false;
stopThrust();
}
}
/***************************************
* SHIP : FIRE
**************************************/
Bullet* Ship::fire()
{
Bullet* bullet = new Bullet();
Position start;
start.setPixelsX(position.getPixelsX() + 19.0 * sin(angle));
start.setPixelsY(position.getPixelsY() + 19.0 * cos(angle));
double vx = velocity.getMetersX() + 9000 * sin(angle);
double vy = velocity.getMetersY() + 9000 * cos(angle);
bullet->initialPlacement(start.getMetersX(), start.getMetersY(), vx, vy);
return bullet;
}