-
Notifications
You must be signed in to change notification settings - Fork 0
/
Laser.cpp
138 lines (120 loc) · 4 KB
/
Laser.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <windows.h> // Header File For Windows
#include <stdio.h> // Header File For Standard Input / Output
#include <stdarg.h> // Header File For Variable Argument Routines
#include <math.h> // Header File For Math Operations
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library
#include "glut.h"
#include "baseTypes.h"
#include "ShapeDraw.h"
#include "collInfo.h"
#include "object.h"
//#include "inputmapper.h"
#include "ball.h"
#include "field.h"
#include "fieldmanager.h"
#include "gamedefs.h"
#include "gameobjects.h"
#include "random.h"
#include "stateManager.h"
#include "inputmanager.h"
#include "playermanager.h"
#include "player.h"
#include "blockmanager.h"
#include "block.h"
#include "laser.h"
#include "powerupmanager.h"
void LaserC::moveUp()
{
int x;
x=5;
}
LaserC::LaserC(float initPosX,float initPosY, int playerWhoCreated)
:playerCreator(playerWhoCreated)
{
mEnabled = true;
mPosition.x = initPosX;
mPosition.y = initPosY;
}
LaserC::LaserC()
{
mEnabled = true;
mCollInfo.shape = CollInfoC::SHAPE_CIRCLE;
};
LaserC::~LaserC()
{
};
void LaserC::update(DWORD milliseconds)
{
if (mEnabled) {
if (playerCreator == 1) {
mPosition.y += bulletSpeed * milliseconds / 10;
} else {
mPosition.y -= bulletSpeed * milliseconds / 10;
}
DoCollisions();
}
}
void LaserC::DoCollisions()
{
CollideField();
CollideBlocks();
CollidePlayer(PlayerManagerC::GetInstance()->getPlayer1Ptr());
CollidePlayer(PlayerManagerC::GetInstance()->getPlayer2Ptr());
}
void LaserC::CollideField(void)
{
FieldC *field = FieldManagerC::GetInstance()->getFieldPtr();
float_t rightSide = field->getPosition()->x+((float_t)field->getWidth()/2.0f);
float_t leftSide = field->getPosition()->x-((float_t)field->getWidth()/2.0f);
float_t topSide = field->getPosition()->y+((float_t)field->getHeight()/2.0f);
float_t bottomSide = field->getPosition()->y-((float_t)field->getHeight()/2.0f);
if ((mPosition.x - mRadius <= leftSide) || (mPosition.x + mRadius >= rightSide) || (mPosition.y - mRadius <= bottomSide) || (mPosition.y + mRadius >= topSide)) {
mEnabled = false;
}
};
void LaserC::CollidePlayer(PlayerC* player)
{
float_t rightSide = player->getPosition()->x+((float_t)player->getWidth()/2.0f);
float_t leftSide = player->getPosition()->x-((float_t)player->getWidth()/2.0f);
float_t topSide = player->getPosition()->y+((float_t)player->getHeight()/2.0f);
float_t bottomSide = player->getPosition()->y-((float_t)player->getHeight()/2.0f);
if (mPosition.x <= rightSide && mPosition.x >= leftSide && mPosition.y >= bottomSide && mPosition.y <= topSide) {
player->stun();
disable();
}
};
void LaserC::CollideBlocks()
{
BlockC** blockArray = BlockManagerC::GetInstance()->getBlocks();
for (int i = 0; i < BlockManagerC::GetInstance()->getMaxBlocks(); i++) {
BlockC* curBlock = blockArray[i];
if (curBlock == nullptr) {
return;
}
if (!curBlock->isEnabled()) {
continue;
}
float_t rightSide = mPosition.x + (mRadius);
float_t leftSide = mPosition.x - (mRadius);
float_t topSide = mPosition.y + (mRadius);
float_t bottomSide = mPosition.y - (mRadius);
float_t blockRightSide = curBlock->getPosition()->x + ((float_t)curBlock->getWidth()/2.0f);
float_t blockLeftSide = curBlock->getPosition()->x - ((float_t)curBlock->getWidth()/2.0f);
float_t blockTopSide = curBlock->getPosition()->y + ((float_t)curBlock->getHeight()/2.0f);
float_t blockBottomSide = curBlock->getPosition()->y - ((float_t)curBlock->getHeight()/2.0f);
bool collision = rectanglesCollide(leftSide, topSide, rightSide, bottomSide, blockLeftSide, blockTopSide, blockRightSide, blockBottomSide);
if (collision) {
if (curBlock->applyDamage()) {
PowerupManagerC::GetInstance()->possiblySpawnPowerup(curBlock->getPosition()->x, curBlock->getPosition()->y, playerCreator);
}
mEnabled = false;
}
}
};
void LaserC::render()
{
if (mEnabled) {
DrawCircle(mRadius,mPosition.x,mPosition.y,0xFF,0x00,0x00,false);
}
}