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.
22 #include "teleporters.h"
25 * Adds a teleporter to the level.
26 * @param name The group name of the teleporter
27 * @param x The x location of the teleporter
28 * @param y The y location of the teleporter
29 * @param destX The x destination of the teleporter
30 * @param destY The y destination of the teleporter
31 * @param active The active state of the teleporter
33 void addTeleporter(const char *name, int x, int y, int destX, int destY, bool active)
35 Teleporter *teleport = new Teleporter();
37 teleport->setName(name);
38 teleport->set(x, y, destX, destY);
39 teleport->active = active;
41 map.addTeleporter(teleport);
45 * Teleporters an entity that touches this teleporter to
46 * the teleporter's destination location
47 * @param ent The entity to check against
49 void checkTeleportContact(Entity *ent)
51 Teleporter *teleport = (Teleporter*)map.teleportList.getHead();
53 while (teleport->next != NULL)
55 teleport = (Teleporter*)teleport->next;
57 if (!teleport->active)
60 if (Collision::collision(ent->x + ent->dx, ent->y + ent->dy, ent->width, ent->height, teleport->x + 16, teleport->y - 20, 32, 25))
62 ent->dx = teleport->destX;
63 ent->dy = teleport->destY;
64 Math::addBit(&ent->flags, ENT_TELEPORTING);
65 addTeleportParticles(ent->x + (ent->width / 2), ent->y + (ent->height / 2), 50, SND_TELEPORT3);
67 debug(("%s - Teleporting to %f:%f\n", ent->name, ent->dx, ent->dy));
73 * Loops through all the teleporters and makes them do their thing
77 Sprite *teleportStar = graphics.getSprite("TeleportStar", true);
78 Teleporter *teleport = (Teleporter*)map.teleportList.getHead();
83 while (teleport->next != NULL)
85 teleport = (Teleporter*)teleport->next;
87 x = (int)(teleport->x - engine.playerPosX);
88 y = (int)(teleport->y - engine.playerPosY);
90 if ((abs(x) <= 800) && (abs(y) <= 600))
92 if (teleport->sprite == NULL)
94 teleport->sprite = graphics.getSprite("Teleporter", true);
97 graphics.blit(teleport->sprite->getCurrentFrame(), x, y, graphics.screen, false);
101 dy = Math::rrand(-100, -10);
103 map.addParticle(teleport->x + Math::prand() % 64, teleport->y, 0, dy, Math::rrand(30, 60), graphics.white, teleportStar, PAR_WEIGHTLESS);