2 Copyright (C) 2004-2011 Parallel Realities
3 Copyright (C) 2011-2015 Perpendicular Dimensions
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 currentAction = TRAP_WAIT2;
32 void Trap::setName(const char *name)
34 strlcpy(this->name, name, sizeof this->name);
37 void Trap::setTrapType(int type)
42 void Trap::setSpeed(int speed)
47 void Trap::setWaitTimes(int time1, int time2)
50 this->waitTime[0] = time1;
51 this->waitTime[1] = time2;
54 void Trap::setSprite(Sprite *sprite)
56 this->sprite = sprite;
58 this->width = sprite->image[0]->w;
59 this->height = sprite->image[0]->h;
62 void Trap::setDestinations(int startX, int startY, int endX, int endY)
64 this->startX = startX;
65 this->startY = startY;
72 if (type == TRAP_TYPE_SWING)
76 speed = Math::rrand(-2, 2);
78 dy = Math::rrand(0, 45);
82 void Trap::setDamage(int damage)
84 this->damage = damage;
87 bool Trap::performSwingAction()
96 x = (0 * cos((dy * PI) / 180)) - (1 * sin((dy * PI) / 180));
97 y = (1 * cos((dy * PI) / 180)) + (0 * sin((dy * PI) / 180));
107 Math::limitFloat(&speed, -2.5, 2.5);
120 if (((int)dy >= -2) && ((int)dy <= 2))
126 bool Trap::performSpikeAction()
128 if (currentAction == TRAP_FIRSTACTION)
133 Math::limitFloat(&(x -= speed), startX, endX);
134 Math::limitFloat(&(y -= speed), startY, endY);
136 if ((x == startX) && (y == startY))
138 Math::wrapChar(&(++currentAction), 0, 3);
139 thinktime = waitTime[0];
143 if (currentAction == TRAP_SECONDACTION)
145 Math::limitFloat(&(++x), startX, endX);
146 Math::limitFloat(&(++y), startY, endY);
148 if ((x == endX) && (y == endY))
150 Math::wrapChar(&(++currentAction), 0, 3);
151 thinktime = waitTime[1];
158 bool Trap::performBarrierAction()
164 currentAction = TRAP_WAIT2;
165 thinktime = waitTime[1];
168 currentAction = TRAP_FIRSTACTION;
169 thinktime = waitTime[0];
173 if (thinktime >= waitTime[0] - 3)
179 bool Trap::performFlameAction()
185 currentAction = TRAP_WAIT2;
186 thinktime = waitTime[1];
189 currentAction = TRAP_FIRSTACTION;
190 thinktime = waitTime[0];
194 if (thinktime >= waitTime[0] - 3)
202 if (type == TRAP_TYPE_MINE)
209 if ((currentAction == TRAP_WAIT1) || (currentAction == TRAP_WAIT2))
216 Math::wrapChar(&(++currentAction), 0, 3);
219 if ((type == TRAP_TYPE_BARRIER) || (type == TRAP_TYPE_FLAME))
220 thinktime = waitTime[0];
226 case TRAP_TYPE_SPIKE:
227 return performSpikeAction();
229 case TRAP_TYPE_SWING:
230 return performSwingAction();
232 case TRAP_TYPE_BARRIER:
233 return performBarrierAction();
235 case TRAP_TYPE_FLAME:
236 return performBarrierAction();