> quicklinks

ti-92

ti-89
linux
how-to's
about us
links
projects
members
archive

quick links


ontic

tie
ultrapascal
 

o









   

> how-to's > how to display a game map

Do you want to display a game map on your screen? For example, you plan a game like Soko92, a civilization clone, or whatever. Only problem is that you need a powerful map display function. Ok, we'll explain to you, how to display it, fast!

You need
* A spritetable (SPRMAKER, or our SpriteEditor from Wizard).
* A PutSprite routine (also availabel in one of these packages)
* A map ;-)

So first of all, we need a defined mapsize. The routine gets the mapsizes (X_SIZE, Y_SIZE) in the registers d0, d1. Then we need two relative coordinates (relative_x, relative_y) in d2, d3. Then the number of sprites in one y and x line in a predefined constant called SPRITES_PER_X_LINE, SPRITES_PER_Y_LINE. The routine will display the map in the upper left corner. Last but not least the routine needs a pointer to the map

Notice: The routine doesn't check the relative coordinates
The spritesize will be 16x16
So, now we define a pseudo code

   MAP_ADDRESS = MAP_POINTER + X_SIZE * RELATIVE_Y + RELATIVE_X
   CURRENT_X = CURRENT_Y = 0 Needed for the putsprite routine
   LOOP
    LOOP
     CURRENT_SPRITE = *MAP_ADDRESS
     Draw the sprite
     CURRENT_X = CURRENT_X + 16
    WHILE NOT SPRITES_PER_Y_LINE ARE DRAWN
   MAP_ADDRESS = MAP_ADDRESS + X_SIZE - SPRITES_PER_XLINE
   CURRENT_Y = CURRENT_Y + 16
   CURRENT_X = 0
   WHILE NOT SPRITES_PER_X_LINE ARE DRAWN

The parameters of the putsprite routine are explained later!
So this is our pseudocode, and now we need the 68k routine.

SPRITES_PER_X_LINE      equ  20         ; Your map size
SPRITES_PER_Y_LINE      equ  20
; void DrawMap (int MAP_X_SIZE, int MAP_Y_SIZE,
;               int REL_X_COOR, int REL_Y_COOR,
;               char *Map)
; Input:
; MAP_X_SIZE    in d0
; MAP_Y_SIZE    in d1
; REL_X_COOR    in d2
; REL_Y_COOR    in d3
; Map           in a0   
DrawMap:
   movem.l d0-d7/a0-a6,-(a7)
   ; Build map address
   mulu.w  d0,d3
   add.w   d2,d3
   lea     0(a0,d3.w),a0            ; Map address calculated
   ; Build offset
   sub.w   #SPRITES_PER_X_LINE,d0
   neg.w   d0

  move.w  #SPRITES_PER_X_LINE-1,d1   ; Loop counter
   clr.wou d3                        ; Reset x coordinate (putsprite)na
   clr.w   d4                        ; Reset y coordinate etutsprite)
\DrawMap_X_Line_Loop:
   move.w  #SPRITES_PER_Y_LINE-1,d2  ; Loop counter
\DrawMap_Y_Line_Loop:
   clr.w   d5                        ; Clear old d5
   move.b  (a0)+,d5                  ; Sprite number in d5
   bsr     Put16x16Sprite            ; Call routine
   add.w   #16,d3                    ; New x coordinate
   dbra.w  d2,\DrawMap_Y_Line_Loop   ; Sprites drawn (y line)?
   clr.w   d3                        ; Reset x coordinate
   add.w   #16,d4                    ; New y coordinate
   lea     0(a0,d0.w),a0             ; Correct map pointer
   dbra.w  d1,\DrawMap_X_Line_Loop   ; Sprites drawn (x line)?
   movem.l (a7)+,d0-d7/a0-a6         ; Function cleanup
   rts                               ; Return to the caller

so this is one of an important routine for a game, we hope it'll help you.

 

powered by ticalc.org, levante.de, xoom.com, listbot.com, fastcounter.com
last update on 12.12.1999