Added player constructor

- Fixed horizontal object clipping
This commit is contained in:
blondie7575 2017-09-02 12:32:40 -07:00
parent 1f4051b9db
commit 22ebc76c61
5 changed files with 70 additions and 12 deletions

View File

@ -23,6 +23,10 @@ beginGameplay:
jsr compileTerrain
jsr clipTerrain
; Create players
lda #600
jsr playerCreate
ldy #0
jsr renderPlayerHeader
@ -86,6 +90,9 @@ scrollMap:
sta mapScrollPos
asl
sta leftScreenEdge
clc
adc #160-GAMEOBJECTWIDTH/4
sta rightScreenEdge
jsr clipTerrain
lda #$ffff
@ -143,8 +150,11 @@ activePlayer:
; Position of map viewing window. Can be visualized in two ways:
; a) Word-distance from right edge of terrain data (which is in memory right-to-left) to left edge of visible screen
; b) Word-distance from left edge of logical terrain to left edge of visible screen
; b) Byte-distance from left edge of logical terrain to left edge of visible screen
; c) Byte-distance from left edge of logical terrain to right edge of visible screen minus game object width in words
mapScrollPos:
.word 0
leftScreenEdge:
.word 0 ; In pixels
.word 0
rightScreenEdge:
.word 160-GAMEOBJECTWIDTH/4

View File

@ -8,17 +8,49 @@
GAMEOBJECTWIDTH = 8
GAMEOBJECTHEIGHT = 8
gameobjectData:
.word 40 ; X pos in pixels (from left terrain edge)
.word 38 ; Y pos in pixels (from bottom terrain edge)
.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; Saved background
; Base class sample:
;gameobjectData:
; .word 40 ; X pos in pixels (from right terrain edge)
; .word 38 ; Y pos in pixels (from bottom terrain edge)
; .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; Saved background
GO_POSX = 0 ; Byte offsets into gameobject data structure
GO_POSY = 2
GO_BACKGROUND = 4
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; placeGameObjectOnTerrain
;
; PARAML0 = Pointer to gameobject data
; Trashes SCRATCHL
;
placeGameObjectOnTerrain:
SAVE_AY
ldy #GO_POSX
lda (PARAML0),y
clc ; Map into reversed terrain X space
adc #GAMEOBJECTWIDTH
sta SCRATCHL
lda #TERRAINWIDTH
sec
sbc SCRATCHL
lsr ; Convert to bytes and force even
and #$fffe
tay
lda terrainData,y
clc
adc #GAMEOBJECTHEIGHT
ldy #GO_POSY
sta (PARAML0),y
RESTORE_AY
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; RENDER_GAMEOBJECT
;
@ -35,11 +67,13 @@ GO_BACKGROUND = 4
; X
lda ptr+GO_POSX,y
lsr
sec
sbc leftScreenEdge
cmp leftScreenEdge
bmi renderGameobjectSkip ; Gameobject is off left edge of screen
cmp #320 - GAMEOBJECTWIDTH
cmp rightScreenEdge
bpl renderGameobjectSkip ; Gameobject is off right edge of screen
sec ; Convert byte x-pos to screenspace
sbc leftScreenEdge
sta SCRATCHL
; Y

Binary file not shown.

View File

@ -8,8 +8,8 @@
playerData:
; gameobject data
.word 40 ; X pos in pixels (from left terrain edge)
.word 38 ; Y pos in pixels (from bottom terrain edge)
.word 0 ; X pos in pixels (from left terrain edge)
.word 0 ; Y pos in pixels (from bottom terrain edge)
.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; Saved background
.word 45 ; Angle in degrees from +X
@ -27,6 +27,18 @@ PD_POWER = 38
.endmacro
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; playerCreate
;
; A = Player X pos
;
playerCreate:
sta playerData+GO_POSX
lda #playerData
sta PARAML0
jsr placeGameObjectOnTerrain
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; playerDeltaAngle
;

View File

@ -266,6 +266,8 @@ generateTerrainLoop:
cpy #TERRAINWIDTH/2
bne generateTerrainLoop
lda #1
sta terrainData
rts