2 Copyright (C) 2004-2010 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.
21 #include "teleporters.h"
24 * Adds a teleporter to the level.
25 * @param name The group name of the teleporter
26 * @param x The x location of the teleporter
27 * @param y The y location of the teleporter
28 * @param destX The x destination of the teleporter
29 * @param destY The y destination of the teleporter
30 * @param active The active state of the teleporter
32 void addTeleporter(const char *name, int x, int y, int destX, int destY, bool active)
34 Teleporter *teleport = new Teleporter();
36 teleport->setName(name);
37 teleport->set(x, y, destX, destY);
38 teleport->active = active;
40 map.addTeleporter(teleport);
44 * Teleporters an entity that touches this teleporter to
45 * the teleporter's destination location
46 * @param ent The entity to check against
48 void checkTeleportContact(Entity *ent)
50 Teleporter *teleport = (Teleporter*)map.teleportList.getHead();
52 while (teleport->next != NULL)
54 teleport = (Teleporter*)teleport->next;
56 if (!teleport->active)
59 if (Collision::collision(ent->x + ent->dx, ent->y + ent->dy, ent->width, ent->height, teleport->x + 16, teleport->y - 20, 32, 25))
61 ent->dx = teleport->destX;
62 ent->dy = teleport->destY;
63 Math::addBit(&ent->flags, ENT_TELEPORTING);
64 addTeleportParticles(ent->x + (ent->width / 2), ent->y + (ent->height / 2), 50, SND_TELEPORT3);
66 debug(("%s - Teleporting to %f:%f\n", ent->name, ent->dx, ent->dy));
72 * Loops through all the teleporters and makes them do their thing
76 Sprite *teleportStar = graphics.getSprite("TeleportStar", true);
77 Teleporter *teleport = (Teleporter*)map.teleportList.getHead();
82 while (teleport->next != NULL)
84 teleport = (Teleporter*)teleport->next;
86 x = (int)(teleport->x - engine.playerPosX);
87 y = (int)(teleport->y - engine.playerPosY);
89 if ((abs(x) <= 800) && (abs(y) <= 600))
91 if (teleport->sprite == NULL)
93 teleport->sprite = graphics.getSprite("Teleporter", true);
96 graphics.blit(teleport->sprite->getCurrentFrame(), x, y, graphics.screen, false);
100 dy = Math::rrand(-100, -10);
102 map.addParticle(teleport->x + Math::prand() % 64, teleport->y, 0, dy, Math::rrand(30, 60), graphics.white, teleportStar, PAR_WEIGHTLESS);