2 Copyright (C) 2004-2011 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 "obstacles.h"
23 void addObstacle(const char *name, int x, int y, const char *spriteName)
25 Entity *obstacle = new Entity();
27 obstacle->setName(name);
28 obstacle->place(x, y);
29 obstacle->setSprites(graphics.getSprite(spriteName, true), graphics.getSprite(spriteName, true), graphics.getSprite(spriteName, true));
33 Math::addBit(&obstacle->flags, ENT_SLIDES);
36 map.addObstacle(obstacle);
39 bool checkObstacleContact(Entity *ent, int dir)
41 Entity *obstacle = (Entity*)map.obstacleList.getHead();
43 bool collision = false;
45 while (obstacle->next != NULL)
47 obstacle = (Entity*)obstacle->next;
49 if (obstacle->flags & ENT_TELEPORTING)
61 collision = Collision::collision(ent->x + ent->dx, ent->y, ent->width, ent->height - 1, obstacle->x, obstacle->y, obstacle->width, obstacle->height);
65 collision = Collision::collision(ent->x, ent->y + ent->dy, ent->width, ent->height - 1, obstacle->x, obstacle->y, obstacle->width, obstacle->height);
72 if ((ent->y + ent->height == obstacle->y + obstacle->height) || ((ent->flags & ENT_BULLET) && (ent->owner == &player)))
74 obstacle->dx = (ent->dx / 2);
76 if (ent->dx < 0) ent->x = obstacle->x + obstacle->width;
77 if (ent->dx > 0) ent->x = obstacle->x - ent->width;
96 Entity *obstacle = (Entity*)map.obstacleList.getHead();
100 while (obstacle->next != NULL)
102 obstacle = (Entity*)obstacle->next;
104 if (obstacle->flags & ENT_TELEPORTING)
106 moveEntity(obstacle);
110 x = (int)(obstacle->x - engine.playerPosX);
111 y = (int)(obstacle->y - engine.playerPosY);
114 if (!(obstacle->flags & ENT_WEIGHTLESS))
116 obstacle->applyGravity();
119 moveEntity(obstacle);
121 if (!(obstacle->flags & ENT_TELEPORTING))
123 if (!(obstacle->flags & ENT_SLIDES))
129 graphics.blit(obstacle->getFaceImage(), x, y, graphics.screen, false);