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 "obstacles.h"
24 void addObstacle(const char *name, int x, int y, const char *spriteName)
26 Entity *obstacle = new Entity();
28 obstacle->setName(name);
29 obstacle->place(x, y);
30 obstacle->setSprites(graphics.getSprite(spriteName, true), graphics.getSprite(spriteName, true), graphics.getSprite(spriteName, true));
34 Math::addBit(&obstacle->flags, ENT_SLIDES);
37 map.addObstacle(obstacle);
40 bool checkObstacleContact(Entity *ent, int dir)
42 Entity *obstacle = (Entity*)map.obstacleList.getHead();
44 bool collision = false;
46 while (obstacle->next != NULL)
48 obstacle = (Entity*)obstacle->next;
50 if (obstacle->flags & ENT_TELEPORTING)
62 collision = Collision::collision(ent->x + ent->dx, ent->y, ent->width, ent->height - 1, obstacle->x, obstacle->y, obstacle->width, obstacle->height);
64 else if (dir == DIR_Y)
66 collision = Collision::collision(ent->x, ent->y + ent->dy, ent->width, ent->height - 1, obstacle->x, obstacle->y, obstacle->width, obstacle->height);
70 collision = Collision::collision(ent->x + ent->dx, ent->y + ent->dy, ent->width, ent->height - 1, obstacle->x, obstacle->y, obstacle->width, obstacle->height);
77 if ((ent->y + ent->height == obstacle->y + obstacle->height) || ((ent->flags & ENT_BULLET) && (ent->owner == &player)))
79 obstacle->dx = (ent->dx / 2);
81 if (ent->dx < 0) ent->x = obstacle->x + obstacle->width;
82 if (ent->dx > 0) ent->x = obstacle->x - ent->width;
101 Entity *obstacle = (Entity*)map.obstacleList.getHead();
105 while (obstacle->next != NULL)
107 obstacle = (Entity*)obstacle->next;
109 if (obstacle->flags & ENT_TELEPORTING)
111 moveEntity(obstacle);
115 x = (int)(obstacle->x - engine.playerPosX);
116 y = (int)(obstacle->y - engine.playerPosY);
119 if (!(obstacle->flags & ENT_WEIGHTLESS))
121 obstacle->applyGravity();
124 moveEntity(obstacle);
126 if (!(obstacle->flags & ENT_TELEPORTING))
128 if (!(obstacle->flags & ENT_SLIDES))
134 graphics.blit(obstacle->getFaceImage(), x, y, graphics.screen, false);