]> git.mxchange.org Git - quix0rs-blobwars.git/blob - src/teleporters.cpp
Updated PNG icon files.
[quix0rs-blobwars.git] / src / teleporters.cpp
1 /*
2 Copyright (C) 2004-2011 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, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20
21 #include "teleporters.h"
22
23 /**
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
31 */
32 void addTeleporter(const char *name, int x, int y, int destX, int destY, bool active)
33 {
34         Teleporter *teleport = new Teleporter();
35
36         teleport->setName(name);
37         teleport->set(x, y, destX, destY);
38         teleport->active = active;
39         
40         map.addTeleporter(teleport);
41 }
42
43 /**
44 * Teleporters an entity that touches this teleporter to
45 * the teleporter's destination location
46 * @param ent The entity to check against
47 */
48 void checkTeleportContact(Entity *ent)
49 {
50         Teleporter *teleport = (Teleporter*)map.teleportList.getHead();
51
52         while (teleport->next != NULL)
53         {
54                 teleport = (Teleporter*)teleport->next;
55
56                 if (!teleport->active)
57                         continue;
58
59                 if (Collision::collision(ent->x + ent->dx, ent->y + ent->dy, ent->width, ent->height, teleport->x + 16, teleport->y - 20, 32, 25))
60                 {
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);
65                         
66                         debug(("%s - Teleporting to %f:%f\n", ent->name, ent->dx, ent->dy));
67                 }
68         }
69 }
70
71 /**
72 * Loops through all the teleporters and makes them do their thing
73 */
74 void doTeleporters()
75 {
76         Sprite *teleportStar = graphics.getSprite("TeleportStar", true);
77         Teleporter *teleport = (Teleporter*)map.teleportList.getHead();
78
79         int x, y;
80         float dy;
81
82         while (teleport->next != NULL)
83         {
84                 teleport = (Teleporter*)teleport->next;
85
86                 x = (int)(teleport->x - engine.playerPosX);
87                 y = (int)(teleport->y - engine.playerPosY);
88
89                 if ((abs(x) <= 800) && (abs(y) <= 600))
90                 {
91                         if (teleport->sprite == NULL)
92                         {
93                                 teleport->sprite = graphics.getSprite("Teleporter", true);
94                         }
95
96                         graphics.blit(teleport->sprite->getCurrentFrame(), x, y, graphics.screen, false);
97
98                         if (teleport->active)
99                         {
100                                 dy = Math::rrand(-100, -10);
101                                 dy /= 100;
102                                 map.addParticle(teleport->x + Math::prand() % 64, teleport->y, 0, dy, Math::rrand(30, 60), graphics.white, teleportStar, PAR_WEIGHTLESS);
103                         }
104                 }
105         }
106 }