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.
27 x = y = dx = dy = tx = ty = width = height = 0;
31 environment = ENV_AIR;
36 thinktime = baseThink = 0;
48 for (int i = 0 ; i < 3 ; i++)
54 void Entity::setName(const char *name)
56 strlcpy(this->name, name, sizeof this->name);
59 void Entity::setSprites(Sprite *sprite1, Sprite *sprite2, Sprite *sprite3)
67 if (sprite[0]->maxFrames > 0)
69 currentFrame = Math::prand() % (sprite[0]->maxFrames + 1);
72 width = sprite[0]->image[0]->w;
73 height = sprite[0]->image[0]->h;
78 void Entity::animate()
85 sprite[face]->getNextFrame(¤tFrame, ¤tTime);
89 SDL_Surface *Entity::getFaceImage()
91 if ((health > 0) && (immune <= 120))
93 return sprite[face]->image[currentFrame];
96 return sprite[2]->getCurrentFrame();
99 void Entity::place(int x, int y)
101 this->x = this->tx = x;
102 this->y = this->ty = y;
105 void Entity::setVelocity(float dx, float dy)
117 void Entity::setRandomVelocity()
119 dx = Math::rrand(-100, 100);
122 dy = Math::rrand(-15, 0);
125 void Entity::applyGravity()
127 if ((environment == ENV_AIR) && (!(flags & ENT_WEIGHTLESS)))
132 Math::limitFloat(&dy, -12, 12);
135 void Entity::checkEnvironment()
140 Math::limitChar(&(oxygen += 2), 0, 7);
143 if (!(flags & ENT_SWIMS))
145 Math::limitChar(&(oxygen -= 1), 0, 7);
170 if ((falling) && (immune == 121) && (environment == ENV_AIR))
176 Math::wrapInt(&(--thinktime), 0, baseThink);
177 Math::limitInt(&(--reload), 0, 255);
179 if (flags & ENT_DYING)
184 if (flags & ENT_FLIES)
191 Math::removeBit(&flags, ENT_FLIES);
203 Math::limitChar(&fuel, 0, 7);
205 if ((thinktime == 0) && (!(flags & ENT_INANIMATE)))