-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredshell.cpp
107 lines (95 loc) · 2.13 KB
/
redshell.cpp
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "redshell.h"
#include <cmath>
#include <iostream>
using namespace std;
/* Constructor for a red shell, sets velocity to 1.1
@param pm Pixmap pointer to show picture
@param nx Initial x cooridinate to set position
@param ny Initial y coordinate to set poition **/
RedShell :: RedShell(QPixmap *pm, int nx, int ny) : Thing(pm,nx,ny)
{
*pm = pm->scaled(50, 50, Qt::KeepAspectRatio);
vX = 1.1;
vY = 1.1;
}
/* Default destructor **/
RedShell:: ~RedShell()
{}
/* @return the current vX of the redshell **/
double RedShell:: getVelX()
{
return vX;
}
/* @return the current vY of the redshell **/
double RedShell:: getVelY()
{
return vY;
}
/* Adds the paramenter to the vX of the object
@param x The int passed in from MainWIndow **/
void RedShell:: setVelX(double x)
{
vX+=x;
}
/* Adds the parameter vY of the object
@param y The int passed in from MainWIndow **/
void RedShell:: setVelY(double y)
{
vY += y;
}
/* sets the vX of the object
@param x The int passed in from MainWIndow **/
void RedShell:: setDVelX(double x)
{
vX=x;
}
/* sets the vY of the object
@param y The int passed in from MainWIndow **/
void RedShell:: setDVelY(double y)
{
vY = y;
}
/* Takes the position of the mainPLayer and uses trig to calculate the angle that needs to be traveled, and sets the velocity and direction accordingly
@param point The position of the main player passed by MainWindow **/
void RedShell::move(QPointF point)
{
// finding projectile angle
double dy = (point.y() +50) - pos().y();
double dx = point.x() - pos().x();
double angle = dy/dx;
double velocityX = abs(cos(angle) * vX);
double velocityY = abs(sin(angle) * vY);
if(dx > 0)
{
x= x + velocityX;
}
if (dx < 0)
{
x = x - velocityX;
}
if ( dx == 0)
{
x=x;
}
if(dy > 0)
{
y = y + velocityY;
}
if(dy < 0)
{
y = y -velocityY;
}
if ( dy == 0)
{
y=y;
}
setPos(x,y);
}
/* The RedShell class implements its own move function, but this one is pure virtual within Thing **/
void RedShell :: move()
{
setPos(x,y);
}
/* @return 1-- tells switch in MainWindow to execute shell collision **/
int RedShell::executePower()
{return 1;}