2 Copyright (C) 2004 Parallel Realities
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.
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.
13 See the GNU General Public License for more details.
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, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 currentAction = TRAP_WAIT2;
31 void Trap::setName(const char *name)
33 strncpy(this->name, name, sizeof this->name);
36 void Trap::setTrapType(int type)
41 void Trap::setSpeed(int speed)
46 void Trap::setWaitTimes(int time1, int time2)
49 this->waitTime[0] = time1;
50 this->waitTime[1] = time2;
53 void Trap::setSprite(Sprite *sprite)
55 this->sprite = sprite;
57 this->width = sprite->image[0]->w;
58 this->height = sprite->image[0]->h;
61 void Trap::setDestinations(int startX, int startY, int endX, int endY)
63 this->startX = startX;
64 this->startY = startY;
71 if (type == TRAP_TYPE_SWING)
75 speed = Math::rrand(-2, 2);
77 dy = Math::rrand(0, 45);
81 void Trap::setDamage(int damage)
83 this->damage = damage;
86 bool Trap::performSwingAction()
95 x = (0 * cos((dy * PI) / 180)) - (1 * sin((dy * PI) / 180));
96 y = (1 * cos((dy * PI) / 180)) + (0 * sin((dy * PI) / 180));
106 Math::limitFloat(&speed, -2.5, 2.5);
119 if (((int)dy >= -2) && ((int)dy <= 2))
125 bool Trap::performSpikeAction()
127 if (currentAction == TRAP_FIRSTACTION)
132 Math::limitFloat(&(x -= speed), startX, endX);
133 Math::limitFloat(&(y -= speed), startY, endY);
135 if ((x == startX) && (y == startY))
137 Math::wrapChar(&(++currentAction), 0, 3);
138 thinktime = waitTime[0];
142 if (currentAction == TRAP_SECONDACTION)
144 Math::limitFloat(&(++x), startX, endX);
145 Math::limitFloat(&(++y), startY, endY);
147 if ((x == endX) && (y == endY))
149 Math::wrapChar(&(++currentAction), 0, 3);
150 thinktime = waitTime[1];
157 bool Trap::performBarrierAction()
163 currentAction = TRAP_WAIT2;
164 thinktime = waitTime[1];
167 currentAction = TRAP_FIRSTACTION;
168 thinktime = waitTime[0];
172 if (thinktime >= waitTime[0] - 3)
178 bool Trap::performFlameAction()
184 currentAction = TRAP_WAIT2;
185 thinktime = waitTime[1];
188 currentAction = TRAP_FIRSTACTION;
189 thinktime = waitTime[0];
193 if (thinktime >= waitTime[0] - 3)
201 if (type == TRAP_TYPE_MINE)
208 if ((currentAction == TRAP_WAIT1) || (currentAction == TRAP_WAIT2))
215 Math::wrapChar(&(++currentAction), 0, 3);
218 if ((type == TRAP_TYPE_BARRIER) || (type == TRAP_TYPE_FLAME))
219 thinktime = waitTime[0];
225 case TRAP_TYPE_SPIKE:
226 return performSpikeAction();
228 case TRAP_TYPE_SWING:
229 return performSwingAction();
231 case TRAP_TYPE_BARRIER:
232 return performBarrierAction();
234 case TRAP_TYPE_FLAME:
235 return performBarrierAction();