-
Notifications
You must be signed in to change notification settings - Fork 1
/
SwordWeapon.cpp
96 lines (77 loc) · 2.74 KB
/
SwordWeapon.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
//Scott Backer
//Sword Weapon Class CPP: Creates a sword weapon for use with a player/AI
#include "SwordWeapon.h"
//!The constructor for the sword weapon
//In -
// ALLEGRO_EVENT_QUEUE* InputEventQueue = the allegro event queue of the game
// ALLEGROEVENT& InputAlEvent - the allegro event of the game
SwordWeapon::SwordWeapon(ALLEGRO_EVENT_QUEUE* InputEventQueue, ALLEGRO_EVENT& InputAlEvent) :
Weapon(InputEventQueue, InputAlEvent, 16, 16, false, 0.2, 10),
m_SwordWeaponTile(0, 0, 70, 70, true, true, false, true, 6)
{
//initialize member variables
m_OnActive = true;
al_init_user_event_source(&m_SwordActiveEventSource);
al_register_event_source(m_EventQueue, &m_SwordActiveEventSource);
}
//!Handles allegro events for the sword weapon class
void SwordWeapon::EventHandler()
{
//if the weapon is active watch the active timer
if(m_IsActive)
{
//emit the event source that the projectile has moved
m_AlEvent.user.type = CUSTOM_EVENT_ID(MELEEATTACK_EVENT);
m_AlEvent.user.data1 = m_LastDrawnXPosition;
m_AlEvent.user.data2 = m_LastDrawnYPosition;
al_emit_user_event(&m_SwordActiveEventSource, &m_AlEvent, NULL);
m_OnActive = false;
//Update the weapon sprite tile
m_SwordWeaponTile.Event_Handler();
//iterate the timer
m_CurrentAttackCount++;
//if the active timer is reached
if(m_CurrentAttackCount >= m_AttackTime)
{
//make weapon unactive and reset timer
m_IsActive = false;
m_CurrentAttackCount = 0;
m_OnActive = true;
}
}
}
//!Handles drawing for the weapon class
//In -
// int DrawXCoordinate - DrawXCoordinate - the x coordinate to draw the weapon at
// int DrawYCoordinate - DrawXCoordinate - the y coordinate to draw the weapon at
// int XDirection - the x direction relative to the player/AI using the weapon to draw at (use graph coordinates to calculate (Ex. 0, 1 is North or Up))
// int YDirection - the y direction relative to the player/AI using the weapon to draw at (use graph coordinates to calculate (Ex. 0, 1 is North or Up))
void SwordWeapon::Draw(int DrawXCoordinate, int DrawYCoordinate, int XDirection, int YDirection)
{
//keep track of last coordinates
m_LastDrawnXPosition = DrawXCoordinate;
m_LastDrawnYPosition = DrawYCoordinate;
//set draw direction
if(XDirection == 0 && YDirection == -1)
{
m_LastDrawnDirection = Direction(North);
}
else if(XDirection == 0 && YDirection == 1)
{
m_LastDrawnDirection = Direction(South);
}
else if(XDirection == 1 && YDirection == 0)
{
m_LastDrawnDirection = Direction(East);
}
else if(XDirection == -1 && YDirection == 0)
{
m_LastDrawnDirection = Direction(West);
}
else
{
m_LastDrawnDirection = Direction(North);
}
//draw sprite
m_SwordWeaponTile.Draw(DrawXCoordinate, DrawYCoordinate, XDirection, YDirection, m_IsActive);
}