-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectile.cpp
More file actions
65 lines (57 loc) · 1.49 KB
/
Copy pathProjectile.cpp
File metadata and controls
65 lines (57 loc) · 1.49 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
/*
Author: Nick Witten
Date Last Modified: 4/15/21
Organization: ECE2036 Class
Description:
Implements the Projectile functions
to control the shape, color, and movement of
lasers fired from the command ship.
*/
#include "Projectile.h"
#include "graphic.h"
// Reference points
extern const double maxX;
extern const double maxY;
/************************************
Projectile constructor to set laser
properties.
************************************/
Projectile::Projectile()
{
m_Length = 5;
m_Velocity = 160;
m_color = YELLW;
m_numPoints = 2;
}
/**************************************************
This function resets the laser to a position off
the front of the ship and sets the laser's
direction.
**************************************************/
void Projectile::reset(double dirX, double dirY, double startX, double startY)
{
m_xPoints[0] = (startX);
m_yPoints[0] = (startY);
m_xPoints[1] = (startX+dirX*m_Length);
m_yPoints[1] = (startY+dirY*m_Length);
m_DirX = dirX;
m_DirY = dirY;
m_bIsValid = true;
}
/*************************************
Overrides sprite move to check for when
lasers go off the screen and sets them
invalid.
*************************************/
void Projectile::move()
{
// Check if the new position will be off the screen
if (m_xPoints[1] >= maxX || m_yPoints[1] >= maxY ||
m_xPoints[1] <= 0 || m_yPoints[1] <= 0)
{
m_bIsValid = false;
draw(true);
} else {
Sprite::move();
}
}