Tank Sprite

Defines the sprites used for the tank, the function for drawing tanks, and the function for tank to tank pixel collision. More...


Files

file  tanksprite.h
 Defintions of functions and data that deal directly with the tank sprites.

Defines

#define FHoriz   1
 Flip horizontally.
#define FVert   2
 Flip vertically.
#define Trans   4
 Transpose.

Functions

void DrawTank (SDL_Surface *dest, RenderItem *item)
 Draws a player's tank.
void GenTankSprites ()
 Generates all 16 tank sprites from 3 prototype sprites.
Bool IsCollidingShell (Player *tank, Player *shell)
 Tank to shell collision detection.
Bool IsCollidingTank (Player *p1, Player *p2)
 Tank to tank collision detection.

Variables

static const Uint8 imgFlags [16]
 The set of flags used to control rendering a tank in all 16 rotations from three sprites.
const Uint8 shellInitLoc [16][2]
 An array of deltas for the shells inital location that is organized by the tank's rotation.
static const Uint8 spriteProtos [3][8]
 The sprite as a bit pattern, on for tank pixel.
Uint8 sprites [16][8]
 Sprite data for all sixteen sprites.

Detailed Description

Defines the sprites used for the tank, the function for drawing tanks, and the function for tank to tank pixel collision.

Copyright (C) 2007 Jeff Jackowski

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Or visit their website at: http://www.gnu.org/


Define Documentation

#define FHoriz   1

Flip horizontally.

Definition at line 32 of file tanksprite.c.

Referenced by GenTankSprites().

#define FVert   2

Flip vertically.

Definition at line 37 of file tanksprite.c.

Referenced by GenTankSprites().

#define Trans   4

Transpose.

Definition at line 42 of file tanksprite.c.

Referenced by GenTankSprites().


Function Documentation

void DrawTank ( SDL_Surface *  dest,
RenderItem item 
)

Draws a player's tank.

Does not check for visibility.

Bug:
Does not clip its drawing to the changed region.
Parameters:
dest The surface that is the target of the rendering operation.
item The RenderItem, and Player, that the function will render.
Warning:
item must also be a Player.
Author:
Jeff Jackowski

Definition at line 167 of file tanksprite.c.

References colorVals, dInfo, DisplayInfo_t::luh, DisplayInfo_t::luw, RenderItem_t::physLocX, RenderItem_t::physLocY, and sprites.

Referenced by AddPlayer(), BfldErrInit(), main(), SplashInit(), and TeamSelInit().

void GenTankSprites (  ) 

Generates all 16 tank sprites from 3 prototype sprites.

The algorithm used closely resembles the original tank rendering routine. Generating the sprites helps my lazyness because I don't have to come up with the sprites myself or make a tool to generate the sprites. Having each sprite simplifies and speeds up the rendering and collision detection algorithms.

Note:
Only needs to be called once.
Author:
Jeff Jackowski

Definition at line 129 of file tanksprite.c.

References FHoriz, FVert, imgFlags, spriteProtos, sprites, and Trans.

Referenced by main().

Bool IsCollidingShell ( Player tank,
Player shell 
)

Tank to shell collision detection.

The algorithm first computes where on the tank's sprite the shell is located while also checking a bounding box to see if the shell is anywhere on tank's sprite. If the shell is on the tank's sprite, pixel collision will be computed.

Parameters:
tank The player who's tank that might be hit by the shell.
shell The player who's shell might hit the tank.
Returns:
True if the shell hit the tank, false otherwise.
Author:
Jeff Jackowski

Definition at line 259 of file tanksprite.c.

References FALSE, Player_t::rot, Player_t::shellX, Player_t::shellY, sprites, TRUE, Player_t::x, and Player_t::y.

Bool IsCollidingTank ( Player p1,
Player p2 
)

Tank to tank collision detection.

The algorithm first finds an overlap region for the players and at the same time checks for an overlap. If there is an overlap, collision detection is done on the pixels of the sprites used for the players.

Parameters:
p1 A player that might be colliding.
p2 The player that the first might be colliding with.
Returns:
True if the players are colliding with each other, false otherwise
Author:
Jeff Jackowski

Definition at line 194 of file tanksprite.c.

References FALSE, Player_t::rot, sprites, TRUE, Player_t::x, and Player_t::y.

Referenced by SpawnTank().


Variable Documentation

const Uint8 imgFlags[16] [static]

Initial value:

 {
    0,
    0,
    0,
     1  |  2  |  4 ,
     1  |  4 ,
     1  |  4 ,
     2 ,
     2 ,
     2 ,
     1  |  2 ,
     1  |  2 ,
     4 ,
     4 ,
     2  |  4 ,
     1 ,
     1 
}
The set of flags used to control rendering a tank in all 16 rotations from three sprites.

Author:
Jeff Jackowski

Definition at line 89 of file tanksprite.c.

Referenced by GenTankSprites().

const Uint8 shellInitLoc[16][2]

An array of deltas for the shells inital location that is organized by the tank's rotation.

Author:
Jeff Jackowski

Definition at line 64 of file tanksprite.h.

const Uint8 spriteProtos[3][8] [static]

The sprite as a bit pattern, on for tank pixel.

The least significant bit represents the leftmost pixel. The comments show individual bits with the leftmost bit representing the leftmost pixel.

Definition at line 50 of file tanksprite.c.

Referenced by GenTankSprites().

Uint8 sprites[16][8]

Sprite data for all sixteen sprites.

The data is generated by GenTankSprites() at runtime. The first dimention indicates the rotation of the tank sprite. The second dimention indicates the horizontal line of the sprite. A set bit indictaes the pixel is part of the tank.

Definition at line 108 of file tanksprite.c.

Referenced by DrawTank(), GenTankSprites(), IsCollidingObstacle(), IsCollidingShell(), and IsCollidingTank().


Generated on Mon May 28 04:41:43 2007 for Retro Tank Super Attack by  doxygen 1.5.2