summaryrefslogtreecommitdiff
path: root/apps/plugins/xrick/e_bomb.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/xrick/e_bomb.c')
-rw-r--r--apps/plugins/xrick/e_bomb.c158
1 files changed, 158 insertions, 0 deletions
diff --git a/apps/plugins/xrick/e_bomb.c b/apps/plugins/xrick/e_bomb.c
new file mode 100644
index 0000000000..7b9f8cf309
--- /dev/null
+++ b/apps/plugins/xrick/e_bomb.c
@@ -0,0 +1,158 @@
1/*
2 * xrick/e_bomb.c
3 *
4 * Copyright (C) 1998-2002 BigOrno (bigorno@bigorno.net).
5 * Copyright (C) 2008-2014 Pierluigi Vicinanza.
6 * All rights reserved.
7 *
8 * The use and distribution terms for this software are contained in the file
9 * named README, which can be found in the root of this distribution. By
10 * using this software in any fashion, you are agreeing to be bound by the
11 * terms of this license.
12 *
13 * You must not remove this notice, or any other, from this software.
14 */
15
16#include "xrick/e_bomb.h"
17
18#include "xrick/game.h"
19#include "xrick/ents.h"
20#include "xrick/e_rick.h"
21#include "xrick/system/system.h"
22#ifdef ENABLE_SOUND
23#include "xrick/data/sounds.h"
24#endif
25
26/*
27 * public vars (for performance reasons)
28 */
29bool e_bomb_lethal;
30U8 e_bomb_xc;
31U16 e_bomb_yc;
32
33/*
34 * private vars
35 */
36U8 e_bomb_ticker;
37
38/*
39 * Bomb hit test
40 *
41 * ASM 11CD
42 * returns: true/hit, false/not
43 */
44bool e_bomb_hit(U8 e)
45{
46 if (ent_ents[e].x > (E_BOMB_ENT.x >= 0xE0 ? 0xFF : E_BOMB_ENT.x + 0x20))
47 return false;
48 if (ent_ents[e].x + ent_ents[e].w < (E_BOMB_ENT.x > 0x04 ? E_BOMB_ENT.x - 0x04 : 0))
49 return false;
50 if (ent_ents[e].y > (E_BOMB_ENT.y + 0x1D))
51 return false;
52 if (ent_ents[e].y + ent_ents[e].h < (E_BOMB_ENT.y > 0x0004 ? E_BOMB_ENT.y - 0x0004 : 0))
53 return false;
54 return true;
55}
56
57/*
58 * Initialize bomb
59 */
60void e_bomb_init(U16 x, U16 y)
61{
62 E_BOMB_ENT.n = 0x03;
63 E_BOMB_ENT.x = x;
64 E_BOMB_ENT.y = y;
65 e_bomb_ticker = E_BOMB_TICKER;
66 e_bomb_lethal = false;
67
68 /*
69 * Atari ST dynamite sprites are not centered the
70 * way IBM PC sprites were ... need to adjust things a little bit
71 */
72#ifdef GFXST
73 E_BOMB_ENT.x += 4;
74 E_BOMB_ENT.y += 5;
75#endif
76
77}
78
79
80/*
81 * Entity action
82 *
83 * ASM 18CA
84 */
85void
86e_bomb_action(U8 e/*unused*/)
87{
88 (void)e;
89
90 /* tick */
91 e_bomb_ticker--;
92
93 if (e_bomb_ticker == 0)
94 {
95 /*
96 * end: deactivate
97 */
98 E_BOMB_ENT.n = 0;
99 e_bomb_lethal = false;
100 }
101 else if (e_bomb_ticker >= 0x0A)
102 {
103 /*
104 * ticking
105 */
106#ifdef ENABLE_SOUND
107 if ((e_bomb_ticker & 0x03) == 0x02)
108 syssnd_play(soundBombshht, 1);
109#endif
110#ifdef GFXST
111 /* ST bomb sprites sequence is longer */
112 if (e_bomb_ticker < 40)
113 E_BOMB_ENT.sprite = 0x99 + 19 - (e_bomb_ticker >> 1);
114 else
115#endif
116 E_BOMB_ENT.sprite = (e_bomb_ticker & 0x01) ? 0x23 : 0x22;
117 }
118 else if (e_bomb_ticker == 0x09)
119 {
120 /*
121 * explode
122 */
123#ifdef ENABLE_SOUND
124 syssnd_play(soundExplode, 1);
125#endif
126#ifdef GFXPC
127 E_BOMB_ENT.sprite = 0x24 + 4 - (e_bomb_ticker >> 1);
128#endif
129#ifdef GFXST
130 /* See above: fixing alignment */
131 E_BOMB_ENT.x -= 4;
132 E_BOMB_ENT.y -= 5;
133 E_BOMB_ENT.sprite = 0xa8 + 4 - (e_bomb_ticker >> 1);
134#endif
135 e_bomb_xc = E_BOMB_ENT.x + 0x0C;
136 e_bomb_yc = E_BOMB_ENT.y + 0x000A;
137 e_bomb_lethal = true;
138 if (e_bomb_hit(E_RICK_NO))
139 e_rick_gozombie();
140 }
141 else
142 {
143 /*
144 * exploding
145 */
146#ifdef GFXPC
147 E_BOMB_ENT.sprite = 0x24 + 4 - (e_bomb_ticker >> 1);
148#endif
149#ifdef GFXST
150 E_BOMB_ENT.sprite = 0xa8 + 4 - (e_bomb_ticker >> 1);
151#endif
152 /* exploding, hence lethal */
153 if (e_bomb_hit(E_RICK_NO))
154 e_rick_gozombie();
155 }
156}
157
158/* eof */