Death Star Run
Introduction:
The goal of this project is to create a simulation type game for the attack on the Death Star from Star Wars. The user will navigate an X-Wing through a 3d trench while avoiding obstacles.
Download xwing.zip
* Note: this thing sketches out sometimes on winME and 98, but there have been no problems so far with NT-based.
** For best results, play a StarWars MP3 as background music and turn off the lights.
Implementation:
The implementation of the trench will be very similar to lab 5 with a few changes. We've decided to change the width:height ratio of the top of the trapezoids, giving the user a different perspective to suggest flying rather than walking. The X-Wing will be rendered as a sprite which will move left and right in reponse to keystrokes. The forward motion of the X-Wing through the trench will be not be controlled by the user since the craft will move forwards whether or not the user is pressing keys. A collision check will occur each step as the player flies through the trench to determine if an obstacle has been hit.
Procedures:
DrawBox
- Purpose: Draw a rectangular box
- Inputs:
- DX: upper left corner
- CX: width of box
- BX: height of box
- AL: color
- Outputs: Writes to screen
- Registers: All preserved
- Assumes: width is a multiple of 2
- Programmer: Craig Beisel
This routine will draw a rectanglular filled box at the specified position on the screen.
DrawWalls
- Purpose: Draw the walls of the trench at the specified depth
- Inputs:
- Outputs: Writes to screen
- Registers: All preserved
- Calls: DrawTrap
- Constants: GrayScale colors
- Programmer: Craig Beisel
This routine draws the trapezoidal walls at each depth of the trench by making two calls to the drawTrapezoid procedure. A table lookup will be used to determine the correct parameter values to drawTrapezoid at each depth. The color of the trapezoids will be determined by the byte in _TRENCH at that depth. The obstacles are drawn in the corners first and then in the middle from top to bottom to avoid having edge colors overlap.
DrawTrapezoid
- Purpose: Draw a trapezoid
- Inputs:
- DX: upper left corner
- CX: width
- BX: height
- AL: color
- AH: direction (0=L, 1=R)
- Outputs: Writes to screen
- Registers: All preserved
- Assumes: width is a multiple of 2
- Programmer: Craig Beisel
This routine will draw a trapezoid at the specified position on the screen. Two trapezoids are available, left and right. Instead of being symmetrical about X though, the bottom part of the trapezoid will maintain a 2:1 width to height ratio, while the top will become 4:1.
DrawFloorCeiling
- Purpose: Fill in the bottom of the trench and outer-space at the specified depth.
- Inputs:
- Outputs: Writes to screen
- Registers: All preserved
- Uses: DrawBox
- Constants: Grayscale colors
- Programmer: Craig Beisel
This routine will draw in the base of the trench at each depth with gray and fill in the sky with black by setting up the proper colors, determining the correct starting pixel from the table lookups and making a call to DrawBox.
DrawXWing
- Purpose: Draw the X-Wing
- Inputs:
- AX: row of upper left corner
- DX: col of upper left corner
- SI: location of image data
- Outputs: Writes to screen
- Registers: All preserved
- Assumes: XWING_WIDTH, XWING_HEIGHT, TRANS_COLOR
- Programmer: Brian Blankstein
The procedure takes the image of an X-Wing and displays it on the screen over the trench image in a location designated by the inputs. The image will probably be represented as pallete numbers for each pixel. One pallete will be designated as "transparent" and the trench colors won't be overridden. By having the location of the image in the data segment be passed in, this procedure can be used to display different images (ie xwing from different angles or exploding).
CheckCollision
- Purpose: Determine if the player has hit an obstacle
- Inputs:
- SI: "depth" of X-Wing into trench
- DI: position of X-Wing on screen
- Outputs: al: 1 = collision, 0 = no collision
- Registers: preserved except al
- Assumes: _TRENCH
- Programmer: Brian Blankstein
The screen will be broken up into 6 equal sections (a 3x2 grid). Each of these grid cells represents a possible location for an obstacle. Each of these cells, in turn, is split into a smaller 4x4 grid. When these smaller grids are combined, they represent all possible locations for the Xwing. So, the position of the Xwing on the screen is passed in as di. Then the procedure determines which obstacle cell the xwing is in (probably using a lookup table), and then checks to see if there is an obstacle in that cell in that position along the trench (from _MAZE[si]). Returns 1 if there is, 0 if not.
ReadFile
- Purpose: Fill in _TRENCH with data
- Outputs: data into _TRENCH
- Registers: All preserved
- Constants: _TRENCHFILE, _TRENCHFILEHANDLE, _TRENCHFILEBUFFER
- Programmer: Craige Thomas
This routine simply reads the text file "Trench.dta" one byte at a time and writes the corresponding data into _TRENCH. Opening, reading, and closing of the file are all done using INT21h Dos commands.
UpdateScreen
- Purpose: Redraw the whole trench
- Inputs:
- di: "depth" of X-Wing into the trench
- Outputs: Writes to screen
- Registers: All preserved
- Programmer: Craig Beisel
This routine will use di to look at the player's position in the trench. Then it will call DrawFloorCeiling, DrawWalls, and DrawObstacles at each depth to render the trench.
DrawObstacles
- Purpose: display obstacles that the player must avoid
- Inputs:
- si: depth into _TRENCH at which to render
- Outputs: Writes to screen
- Registers: All preserved
- Programmer: Craige Thomas
This routine will examine the contents of _TRENCH to determine what kind of obstacle to render. Based on that it will calculate the appropriate starting position from an obstacle table lookup function. Then it will render the obstacle at that position using DrawBox and DrawParaT and DrawParaS.
DrawParaT
- Purpose: Draw L and R top Parallelgrams
- Inputs:
- ah: 0=R, 1=L
- bx: depth of para
- cx: cx value of box to make 3d
- Outputs: Writes to screen
- Registers: All preserved
- Programmer: Craig Beisel
This routine draws a vertical parallelgram on the screen at the specified location, creating a 3d effect for a box.
DrawParaT
- Purpose: Draw L and R side parallelgrams
- Inputs:
- ah: 0=R, 1=L
- bx: depth of para
- cx: cx value of box to make 3d
- Outputs: Writes to screen
- Registers: All preserved
- Programmer: Craig Beisel
This routine draws a horizontal parallelgram on the screen at the specified location, creating a 3d effect for a box.
MainLoop
- Purpose: run the program til the end
- Outputs: the game
- Registers: All preserved
- Uses: UpdateScreen, DrawXWing, ProcessKeystroke, _XWINGPOS
- Programmer: Craige Thomas
This routine will be the main execution loop that keeps the program running until the player wins or dies. It will call UpdateScreen periodically after moving the player forward in the trench, or anytime the XWing has been moved. Most of the execution time will be spent polling for keystrokes and burning clock cycles since otherwise the game would be far too fast to actually play.
ReadKey
- Purpose: Read a keystroke
- Inputs:
- Outputs: ax=0 no key, or ah=extended key or al=regular key code
- Registers: All preserved
- Constants: arrow key values
- Programmer: Alex Manley
This method is used to check if the keyboard has received a key using INT16h.
ProcessKeystroke
- Purpose: Handle the user input and move the xwing accordingly
- Inputs:
- Outputs: changes _XWINGPOS
- Registers: All preserved
- Constants: arrow key values
- Programmer: Alex Manley
ProcessKeystroke will determine which key has been pressed. If it is one of the arrow keys, _XWINGPOS will be updated. If the user has pressed "q" then the game will exit. Otherwise, the key will be discarded.
calcPos
outputs: di, corresponding pixel
uses: xwingwidth and xwingheight
programmer: Brian Blankstein and Craige Thomas
Determines the pixel of the upper right corner of the XWing from where it is in xwingpos. This is used to display it at the appropriate place by drawXwing.
We also ended up using a ShowPCX routine, written by Brandon Long for startup, death, and victory screens.