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.
26 x = y = dx = dy = tx = ty = width = height = 0;
30 environment = ENV_AIR;
35 thinktime = baseThink = 0;
47 for (int i = 0 ; i < 3 ; i++)
53 void Entity::setName(const char *name)
55 strlcpy(this->name, name, sizeof this->name);
58 void Entity::setSprites(Sprite *sprite1, Sprite *sprite2, Sprite *sprite3)
66 if (sprite[0]->maxFrames > 0)
68 currentFrame = Math::prand() % (sprite[0]->maxFrames + 1);
71 width = sprite[0]->image[0]->w;
72 height = sprite[0]->image[0]->h;
77 void Entity::animate()
84 sprite[face]->getNextFrame(¤tFrame, ¤tTime);
88 SDL_Surface *Entity::getFaceImage()
90 if ((health > 0) && (immune <= 120))
92 return sprite[face]->image[currentFrame];
95 return sprite[2]->getCurrentFrame();
98 void Entity::place(int x, int y)
100 this->x = this->tx = x;
101 this->y = this->ty = y;
104 void Entity::setVelocity(float dx, float dy)
116 void Entity::setRandomVelocity()
118 dx = Math::rrand(-100, 100);
121 dy = Math::rrand(-15, 0);
124 void Entity::applyGravity()
126 if ((environment == ENV_AIR) && (!(flags & ENT_WEIGHTLESS)))
131 Math::limitFloat(&dy, -12, 12);
134 void Entity::checkEnvironment()
139 Math::limitChar(&(oxygen += 2), 0, 7);
142 if (!(flags & ENT_SWIMS))
144 Math::limitChar(&(oxygen -= 1), 0, 7);
169 if ((falling) && (immune == 121) && (environment == ENV_AIR))
175 Math::wrapInt(&(--thinktime), 0, baseThink);
176 Math::limitInt(&(--reload), 0, 255);
178 if (flags & ENT_DYING)
183 if (flags & ENT_FLIES)
190 Math::removeBit(&flags, ENT_FLIES);
202 Math::limitChar(&fuel, 0, 7);
204 if ((thinktime == 0) && (!(flags & ENT_INANIMATE)))