2 Copyright © 2004 Parallel Realities
3 Copyright © 2007-2008 Kővágó Zoltán <DirtY.iCE.hu@gmail.com>
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 "CCollision.h"
23 #include "CGraphics.h"
26 #include "CTeleporter.h"
27 #include "console/console.hpp"
28 #include "teleporters.h"
31 * Adds a teleporter to the level.
32 * @param name The group name of the teleporter
33 * @param x The x location of the teleporter
34 * @param y The y location of the teleporter
35 * @param destX The x destination of the teleporter
36 * @param destY The y destination of the teleporter
37 * @param active The active state of the teleporter
39 void addTeleporter(char *name
, int x
, int y
, int destX
, int destY
, bool active
)
41 Teleporter
*teleport
= new Teleporter();
43 teleport
->setName(name
);
44 teleport
->set(x
, y
, destX
, destY
);
45 teleport
->active
= active
;
47 map
.addTeleporter(teleport
);
51 * Teleporters an entity that touches this teleporter to
52 * the teleporter's destination location
53 * @param ent The entity to check against
55 void checkTeleportContact(Entity
*ent
)
57 Teleporter
*teleport
= (Teleporter
*)map
.teleportList
.getHead();
59 while (teleport
->next
!= NULL
)
61 teleport
= (Teleporter
*)teleport
->next
;
63 if (!teleport
->active
)
66 if (Collision::collision(ent
->x
+ ent
->dx
, ent
->y
+ ent
->dy
, ent
->width
, ent
->height
, teleport
->x
+ 16, teleport
->y
- 20, 32, 25))
68 ent
->dx
= teleport
->destX
;
69 ent
->dy
= teleport
->destY
;
70 Math::addBit(&ent
->flags
, ENT_TELEPORTING
);
71 addTeleportParticles(ent
->x
+ (ent
->width
/ 2), ent
->y
+ (ent
->height
/ 2), 50, SND_TELEPORT3
);
73 debug("tele", 3) << ent
->name
<< " - Teleporting to " << ent
->dx
<< ":" << ent
->dy
<< std::endl
;;
79 * Loops through all the teleporters and makes them do their thing
83 Sprite
*teleportStar
= graphics
.getSprite("TeleportStar", true);
84 Teleporter
*teleport
= (Teleporter
*)map
.teleportList
.getHead();
89 while (teleport
->next
!= NULL
)
91 teleport
= (Teleporter
*)teleport
->next
;
93 x
= (int)(teleport
->x
- map
.offsetX
);
94 y
= (int)(teleport
->y
- map
.offsetY
);
96 if ((abs(x
) <= (graphics
.width
+ 160)) && (abs(y
) <= (graphics
.height
+ 120)))
98 if (teleport
->sprite
== NULL
)
100 teleport
->sprite
= graphics
.getSprite("Teleporter", true);
103 graphics
.blit(teleport
->sprite
->getCurrentFrame(), x
, y
, graphics
.screen
, false);
105 if (teleport
->active
)
107 dy
= Math::rrand(-100, -10);
109 map
.addParticle(teleport
->x
+ rand() % 64, teleport
->y
, 0, dy
, Math::rrand(30, 60), graphics
.white
, teleportStar
, PAR_WEIGHTLESS
);