-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspaceship.cpp
More file actions
61 lines (51 loc) · 1.69 KB
/
Copy pathspaceship.cpp
File metadata and controls
61 lines (51 loc) · 1.69 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
#include "spaceship.h"
//set up the starting coordinate of the ship
//as well as its movement speed (and direction)
spaceShip::spaceShip(int initialxCoordinate,
int initialyCoordinate,
int movementSpeed,
int maxX,
int shipWidth,
int shipHeight):
m_initialxCoordinate(initialxCoordinate),
m_initialyCoordinate(initialyCoordinate),
m_movementSpeed(movementSpeed),
m_maxX(maxX){
m_spaceShipImage.load(":/images/defender.png");
m_spaceShipImage = m_spaceShipImage.scaled(shipWidth,shipHeight);
}
void spaceShip::nextFrame(){
//animate the space ship
m_initialxCoordinate += m_movementSpeed;
if(m_initialxCoordinate >= m_maxX){
m_initialxCoordinate = (2*m_maxX) - m_initialxCoordinate;
m_movementSpeed *= -1;
}else if (m_initialxCoordinate <= 0){
m_initialxCoordinate *= -1;
m_movementSpeed *= -1;
}
}
void spaceShip::setMovementDirection(int direction){
m_movementSpeed = m_movementSpeed * direction;
}
//getter for the new x Coordinate so it can be accessed
//by the weapon object in nextFrame() method
int spaceShip::getNewxCoordinate(){
return m_initialxCoordinate;
}
//getter for the new y Coordinate so it can be accessed
//by the weapon object in nextFrame() method
int spaceShip::getNewyCoordinate(){
return m_initialyCoordinate;
}
int spaceShip::getMovementSpeed(){
return m_movementSpeed;
}
//getter for the space ship QPixmap object so it can be accessed
//by the weapon object in the nextFrame() method
QPixmap spaceShip::getSpaceShipImage(){
return m_spaceShipImage;
}
int spaceShip::getMaxX(){
return m_maxX;
}