Overview of animate.asm:
The animate.asm procedures are called from the mainloop by making a call to RedrawScreen during each loop. This procedure then calls all of the following procedures listed below. The aim is to draw the seascape background in a postion that will give the appearance of scrolling and thus give the player's ship an illusion of movement. This is accomplished by using a 320x40 pixel strip of background picture, and using the natural characteristic of the video display where graphics 'wrap around' if the offset starts from the middle of a row. The only thing to to calculate is WHICH row to start from since ships move in the vertical plane, as well as the horizontal.
The background graphic is displayed first in the required position. The player's ship is then displayed in the centre of the screen. The ship's orientation variable decides which ship sprite to display from the images.pcx file. Other player's ships that are within the screens boundaries are next to be displayed, with Projectiles and Torpedos the next to be displayed. Any other player's ships that are out of the screen area are not drawn. Special effects sprites are drawn next in the required position in the screen buffer.
Finally the Radar Screen is updated with a dot representing each ship in it's absolute map postion and the stats bar is written to the screen at the bottom of the display. This allows the player to see vital statitcics about speed, damage, ammunition and targetting.
Implementation of the graphics procedures was quite straightforward, though the background scrolling took a while to perfect. the background is not truly tile based so that the game can have any size play area. This can be changed simply by a constant SizeMul in Structs.INC. The ship tiles themselves took the most time to draw since they are not simple 2D graphics, rather small 3D images that had to be rotated and drawn pixel by pixel using Corel Photopaint 7. Problems that arose during the implementation were how to keep track of which ships and projectiles were within visible range of your own ship and how to draw all players and projectiles in the correct position within the entire map area. Phantom ships proved to be a menace during the networking process but were ironed out quickly. In the end, Battle in the Blue turned into an extremely fun and absorbing game - quite addictive.
Images.PCX
Files:
images.PCX:
320x200 file containing sprites 'tiles' to be loaded into ScreenSeg
Sprites are: 320x40 pixel background strip of the ocean
16 different 40x40 pixels orientations of the player's ship
?? orientations of Projectiles and Torpedos
Various special effects e.g. explosions and shell-splashes
Intro.PCX: 320x200x256 graphic of the front screen and menu options.
Waiting.PCX: screen viewed when waiting for players to join networked game.
Segments:
VidGrSeg: Video Graphics segment (0A000h) for mode 13h VGA graphics output to the screen
ScreenSeg: Segment to set up the screen before it is to be displayed on
the Video Display
ImageSeg: Stores the background and sprites image always so as to minimize
I/O.
ScratchSeg: Destination segment for opened .PCX files.
Constants:
CursorOffset EQU 48000
BulletOffset EQU 48010
TorpedoOffset EQU 48020
SeaSlice
EQU 12800 ;bytes per sea slice
TileSize
EQU 1600 ;bytes per ship tile
Variables:
temp dW ?
DistY dw ? ;Y-Distance
from projectile or enemy to player's Ship
DistX dw ? ;X-Distance
from projectile or enemy to player's Ship
ShipPos dw ? ;position of ship in centre of screen
Images db 'images.pcx',0 ;sprites file
LoadedFile db 0 ;0 if images.pcx
is not loaded, 1 otherwise
FilePos dw 0
;position in images.pcx of a certain sprite
HorizOffset dw 0 ;how far the oceanstrip
must be scrolled for this redrawloop
PlayerColors db 0C9h ;lookup
table for radar colors
db 0B9h
db 0B9h
db 0B9h
StatsOffsets dw 55133 ;lookup
table for where to place statistics readouts on the screen
dw 58333
dw 61533
dw 56567
dw 59127
dw 62007
dw 56611
dw 59491
Included
Structures, Procedures, Variables:
Macros.inc: General macros - used for debugging
Structs.inc: Game Structures
RSave: From Lib291
RRest: From Lib291
External Procedures\variables:
extrn MyShip:PlayerType, NumProjectiles:byte, ProjectileArray:ProjectileType
extrn NumberPlayers:byte, EnemyArray:EnemyType
extrn pbuf:byte, crlf:byte
Procedures:
RedrawScreen:
INPUTS: None
OUTPUT: Screen is redrawn with updated
ships, radar, background and stats
CALLS: LoadPCX, StorePCX,
DrawBackG, ShowSprites, ShowScreen, PlotRadar, StatsBar
PURPOSE: main loop in animate.asm that does
exactly as the name suggests each time it is
called by the main
LoadPCX:
INPUTS: DX = offset
of filehandle to be opened
OUTPUTS: PCX file stored uncompressed
in ScratchPad
CALLS:
NONE
PURPOSE: procedure to open PCX file
(broken up from ECE 291 lab manual procedure)
StorePCX:
INPUTS: ES
= ImageSeg (destination segment for graphic data)
DS = ScratchSeg (source segment)
OUPUTS: Expanded image
and palette stored in screen
CALLS:
NONE
PURPOSE: Decompresses PCX file and stores
the pixel data and palette in ScreenSeg
variable screen.
(broken up from ECE291 lab manual procedure)
DrawBackG:
INPUTS: ImageSeg
ImagePad
MyShip.Xpos
MyShip.Ypos
These are absolute positions withing the entire 640x400 pixel map.
OUTPUTS: ScreenSeg is filled
with background image
CALLS:
NONE
PURPOSE: - Calculate the position that background
must be drawn in to provide illusion of motion.
- Write the background to the ScreenSeg for double buffering.
DrawSprites:
INPUTS: FilePos, ShipPos
BX = current enemy being drawn
OUTPUTS: Ship sprites (player and enemies) written to
locations in ScreenSeg
CALLS: NONE
PURPOSE: Draw in all ships over the already drawn background
residing in ScreenSeg.
SmallSprites:
INPUTS: SI = offset in ImagePad of
sprite
DI = offset in screen as destination for sprite
OUPUTS:
CALLS: NONE
PURPOSE: Calculate offsets of the sprite image in the ImagePad, and
Calculate where sprite should
be placed in Screen
ShowScreen:
INPUTS: Video Graphics
Segment (0A000h)
ScreenSeg (source)
OUTPUTS: whole of redrawn image displayed on screen
CALLS: NONE
PURPOSE: Show stored image on the video screen
PlotRadar:
INPUTS: none
OUTPUTS: Colour Dot displayed on radar screen
to represent ship positions on the map
CALLS:
NONE
PURPOSE: Plot the absolute positions of
players on radar screen at bottom of display
StatsBar:
INPUTS: none
OUTPUTS: Stats Bar is drawn and updated at bottom
of screen
CALLS: GetStats which
returns with BX = pointer to a 3 char buffer
containing ascii characters of the statistic numbers.
PURPOSE: show all ammunition, gunnery and damage statistics
on screen
ShowMenu
INPUTS: DX = effective
address of PCX file for various menu screens
OUTPUT: menu screens displayed
CALLS: LoadPCX, StorePCX,
ShowScreen
PURPOSE:
display the various menu screens before and after gameplay
note:
Called by Intro in Network.ASM
ACTION A-PLENTY ON THE OPEN SEAS!!!