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