/
actarrowtrap.cpp
106 lines (90 loc) · 2.17 KB
/
actarrowtrap.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
/*-------------------------------------------------------------------------------
BARONY
File: actarrowtrap.cpp
Desc: implements arrow trap code
Copyright 2013-2016 (c) Turning Wheel LLC, all rights reserved.
See LICENSE for details.
-------------------------------------------------------------------------------*/
#include "main.hpp"
#include "game.hpp"
#include "stat.hpp"
#include "entity.hpp"
#include "sound.hpp"
#include "collision.hpp"
/*-------------------------------------------------------------------------------
act*
The following function describes an entity behavior. The function
takes a pointer to the entity that uses it as an argument.
-------------------------------------------------------------------------------*/
#define ARROWTRAP_FIRED my->skill[0]
#define ARROWTRAP_AMBIENCE my->skill[6]
void actArrowTrap(Entity* my)
{
int x, y;
int c;
// eliminate arrow traps that have been destroyed.
if ( !checkObstacle(my->x, my->y, my, NULL) )
{
list_RemoveNode(my->mynode);
return;
}
ARROWTRAP_AMBIENCE--;
if ( ARROWTRAP_AMBIENCE <= 0 )
{
ARROWTRAP_AMBIENCE = TICKS_PER_SECOND * 30;
playSoundEntity( my, 149, 128 );
}
if ( !my->skill[28] )
{
return;
}
// received on signal
if ( my->skill[28] == 2)
{
if ( !ARROWTRAP_FIRED )
{
ARROWTRAP_FIRED = 1;
for ( c = 0; c < 4; c++ )
{
switch ( c )
{
case 0:
x = 12;
y = 0;
break;
case 1:
x = 0;
y = 12;
break;
case 2:
x = -12;
y = 0;
break;
case 3:
x = 0;
y = -12;
break;
}
if ( !checkObstacle(my->x + x, my->y + y, my, NULL) )
{
Entity* entity = newEntity(166, 1, map.entities); // arrow
playSoundEntity(my, 239 + rand() % 3, 96);
entity->parent = my->getUID();
entity->x = my->x + x;
entity->y = my->y + y;
entity->z = my->z;
entity->yaw = c * (PI / 2.f);
entity->sizex = 1;
entity->sizey = 1;
entity->behavior = &actArrow;
entity->flags[UPDATENEEDED] = TRUE;
entity->flags[PASSABLE] = TRUE;
// arrow power
entity->skill[3] = 17;
// causes poison for six seconds
entity->skill[4] = 360;
}
}
}
}
}