1 /*
2 Copyright (C) 2009-2021 Parallel Realities
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18 */
19
20 #include "../headers.h"
21
22 #include "../entity.h"
23 #include "../graphics/animation.h"
24 #include "../system/error.h"
25 #include "../system/properties.h"
26
27 extern Entity *self;
28
29 static void entityWait(void);
30 static void init(void);
31
addConveyorBelt(char * name,int x,int y)32 Entity *addConveyorBelt(char *name, int x, int y)
33 {
34 Entity *e = getFreeEntity();
35
36 if (e == NULL)
37 {
38 showErrorAndExit("No free slots to add a Conveyor Belt");
39 }
40
41 loadProperties(name, e);
42
43 e->x = x;
44 e->y = y;
45
46 e->action = &init;
47 e->draw = &drawLoopingAnimationToMap;
48 e->touch = &pushEntity;
49
50 setEntityAnimation(e, "STAND");
51
52 return e;
53 }
54
entityWait()55 static void entityWait()
56 {
57 if (self->active != self->dirY)
58 {
59 if (self->health == 0)
60 {
61 if (self->active == TRUE)
62 {
63 self->dirX = self->face == LEFT ? -fabs(self->speed) : self->speed;
64
65 self->frameSpeed = 1;
66 }
67
68 else
69 {
70 self->dirX = 0;
71
72 self->frameSpeed = 0;
73 }
74 }
75
76 else
77 {
78 if (self->active == TRUE)
79 {
80 self->dirX = self->face == LEFT ? -fabs(self->speed) : self->speed;
81
82 self->frameSpeed = abs(self->frameSpeed);
83 }
84
85 else
86 {
87 self->dirX = self->face == RIGHT ? -fabs(self->speed) : self->speed;
88
89 self->frameSpeed = -abs(self->frameSpeed);
90 }
91 }
92
93 self->dirY = self->active;
94 }
95 }
96
init()97 static void init()
98 {
99 if (self->health == 0)
100 {
101 if (self->active == TRUE)
102 {
103 self->dirX = self->face == LEFT ? -fabs(self->speed) : self->speed;
104
105 self->frameSpeed = 1;
106 }
107
108 else
109 {
110 self->dirX = 0;
111
112 self->frameSpeed = 0;
113 }
114 }
115
116 else
117 {
118 if (self->active == TRUE)
119 {
120 self->dirX = self->face == LEFT ? -fabs(self->speed) : self->speed;
121
122 self->frameSpeed = abs(self->frameSpeed);
123 }
124
125 else
126 {
127 self->dirX = self->face == RIGHT ? -fabs(self->speed) : self->speed;
128
129 self->frameSpeed = -abs(self->frameSpeed);
130 }
131 }
132
133 self->dirY = self->active;
134
135 self->action = &entityWait;
136 }
137