Re: A83: programming question


[Prev][Index][Thread]

Re: A83: programming question




Here's some code from my upcoming game "DragonQuest Dungeon"
Lots of stuff here, makes lots of calls to other routines that don't exist 
in this snip of code.

It does change animation frames and other stuff, but you probably won't need 
that.

When it changes/checks player's position, D is the player's Y position, E is 
the X position.  Both are stored into (xpos) by the 2 byte ld's.

The "call NewMap" does some routine that basicly does this:

Get new map (my game uses RLE compressed maps)
Display the new map
Copy graphics to saferam2 (if you copy Saferam2 to Plotsscreen each frame)
Other stuff...

MoveLoop:
	;Draw Screen
	call calccoords
	call renderscreen
	call waitkey
	ld de,(xpos)

	;===============
	;  Check Keys:
	;===============
	;Down?
	cp GDown
	jr z,MoveDown
	;Up?
	cp GLeft
	jr z,MoveLeft
	;Left?
	cp GRight
	jr z,MoveRight
	;Right?
	cp GUp
	jr z,MoveUp
	;Clear?
	cp GClear
	;Clear quits
	ret z
	;Go back to moveloop
	jr MoveLoop

	;=================
	;  Keys pressed:
	;=================
MoveDown:
	;inc ypos
	inc d
	;down frame
	ld a,0
	jr MoveCheck
MoveUp:
	;dec ypos
	dec d
	;up frame
	ld a,2
	jr MoveCheck
MoveLeft:
	;dec xpos
	dec e
	;down frame
	ld a,0
	jr MoveCheck
MoveRight:
	;inc xpos
	inc e
	;Right frame
	ld a,4
	;===================
	;  After movement:
	;===================
MoveCheck:
	;Set new animation frame
	ld b,a
	ld a,(frame)
	and 1
	xor 1
	or b
	ld (frame),a

	call UpdatePlayerGfx
	;=================================
	;  Check to see if off the edge:
	;=================================
	;Check Y position:
	ld a,d
	;If -1,
	inc a
	;Up a room
	jr z,roomup
	;If 8
	cp 8+1
	;Down a room
	jr z,roomdown
	;Check X position:
	ld a,e
	;If -1,
	inc a
	;Left a room
	jr z,roomLeft
	;If 12
	cp 12+1
	;Right a room
	jr z,roomRight
	;=====================================
	;  Check what's at player's position
	;=====================================
	;Check at de
	call checkde
	;Check bit %00000100 (Wall bit)
	and 4
	;If wall, Go back.
	jr nz,MoveLoop
	;Otherwise:
	;Set new position
	call smoothmove

	;Go back to MoveLoop
	jr MoveLoop

	;=====================================
	;  Code that handles switching rooms
	;=====================================
	;Each Room___ code consists of the following:
	;Set the new x/y position
	;Inc or dec MAP row or column respectively
	;Go to RoomDif
RoomUp:
	ld d,7
	ld hl,row
	dec (hl)
	jr RoomDif
RoomDown:
	ld d,0
	ld hl,row
	inc (hl)
	jr RoomDif
RoomLeft:
	ld e,11
	ld hl,col
	dec (hl)
	jr RoomDif
RoomRight:
	ld e,0
	ld hl,col
	inc (hl)
RoomDif:
	;Set new position
	ld (xpos),de
	;Get new map
	call newMap
	;Back to movement
	jp MoveLoop






>From: "John Doe" <phlu00@hotmail.com>
>Reply-To: assembly-83@lists.ticalc.org
>To: assembly-83@lists.ticalc.org
>Subject: A83: programming question
>
>
>I'm looking for a tutorial or someone to help me.  I'm trying to get my
>tilempa routine to move to the next tilemap when you move to the edge of 
>the
>screen, how would i do that?
>
>  Thanks,
>         Phlu

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com