-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathButtonFieldDeploy.cpp
More file actions
105 lines (92 loc) · 3.04 KB
/
ButtonFieldDeploy.cpp
File metadata and controls
105 lines (92 loc) · 3.04 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "Engine.h"
#include "ButtonFieldDeploy.h"
#include "TextureManager.h"
#include "UserField.h"
#include "EnemyField.h"
#include "resource.h"
#include "SoundButton.h"
extern Engine engine;
extern UserField userField;
extern EnemyField enemyField;
extern TextureManager textureManager;
extern SoundButton soundButton;
/// <summary>
/// Default constructor for the ButtonFieldDeploy class.
/// </summary>
/// <param name="StartX">The X coordinate of the ButtonField.</param>
/// <param name="StartY">The Y coordinate of the ButtonField.</param>
ButtonFieldDeploy::ButtonFieldDeploy(int StartX, int StartY)
{
this->StartX = StartX;
this->StartY = StartY;
this->Cells[0][0].ButtonID = BF_MOVE_LEFT;
this->Cells[0][1].ButtonID = BF_MOVE_LEFT;
this->Cells[0][2].ButtonID = BF_MOVE_UP;
this->Cells[1][0].ButtonID = BF_MOVE_DOWN;
this->Cells[1][1].ButtonID = BF_ROTATE;
this->Cells[1][2].ButtonID = BF_MOVE_UP;
this->Cells[2][0].ButtonID = BF_MOVE_DOWN;
this->Cells[2][1].ButtonID = BF_MOVE_RIGHT;
this->Cells[2][2].ButtonID = BF_MOVE_RIGHT;
this->Cells[3][0].ButtonID = BF_DEPLOY;
this->Cells[3][1].ButtonID = BF_DEPLOY;
this->Cells[3][2].ButtonID = BF_DEPLOY;
}
/// <summary>
/// Changes OpenGL coordinates to ButtonField coordinates.
/// </summary>
/// <param name="coordinates: ">The coordinates of the click to be converted.</param>
/// <returns>Wether or not the user has clicked on the ButtonField.</returns>
bool ButtonFieldDeploy::Click(POINT& coordinates)
{
if (coordinates.x >= this->StartX && coordinates.y >= this->StartY && coordinates.x < ButtonFieldW + this->StartX && coordinates.y < ButtonFieldH + this->StartY)
{
coordinates.x -= this->StartX;
coordinates.y -= this->StartY;
return true;
}
return false;
}
/// <summary>
/// Draws the ButtonField.
/// </summary>
void ButtonFieldDeploy::Draw()
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textureManager.ButtonFieldDeployTextureID);
glBegin(GL_QUADS);
glTexCoord2d(0, 0); glVertex2f(this->StartX, this->StartY);
glTexCoord2d(1, 0); glVertex2f(this->StartX + 4, this->StartY);
glTexCoord2d(1, 1); glVertex2f(this->StartX + 4, this->StartY + 3);
glTexCoord2d(0, 1); glVertex2f(this->StartX, this->StartY + 3);
glEnd();
glDisable(GL_TEXTURE_2D);
}
/// <summary>
/// Deploys the current active ship.
/// </summary>
void ButtonFieldDeploy::Deploy()
{
if (userField.Ships[engine.ShipsDeployed].Deployable)
{
if (soundButton.State == SoundButton::STATE::On)
{
PlaySound(NULL, NULL, NULL);
PlaySound(MAKEINTRESOURCE(S_WAVE_DEPLOY), GetModuleHandle(NULL), SND_RESOURCE | SND_ASYNC | SND_NOSTOP);
}
userField.Ships[engine.ShipsDeployed].Deployed = true;
}
else
{
if (soundButton.State == SoundButton::STATE::On)
{
PlaySound(NULL, NULL, NULL);
PlaySound(MAKEINTRESOURCE(S_WAVE_ERROR), GetModuleHandle(NULL), SND_RESOURCE | SND_ASYNC | SND_NOSTOP);
}
return;
}
engine.ShipsDeployed++;
if (engine.ShipsDeployed == 10) return;
enemyField.CloseNextShip();
engine.MoveShipToUserField(enemyField.Ships[engine.ShipsDeployed], userField.Ships[engine.ShipsDeployed]);
}