Re-did item system

- Changed main update to the new routine
- Changed how the item locations work. Instead of an array for position, array for location, and potentially another array for sub-position, it uses one array of bytes, where each byte has 2 bits for rotation, 2 bits for subposition, and 4 bits for type.
This commit is contained in:
Byron Lathi 2019-06-06 16:35:53 -04:00
parent 0dbe98e484
commit 9c247bd2e9
5 changed files with 78 additions and 142 deletions

Binary file not shown.

View File

@ -65,23 +65,27 @@ draw: ldx TILENUM ; This section gets the type of tile to draw.
lin1t8: ldy #00
patch_1: ; Loop through the first 8 lines, drawing the value from the tile
lda TILE2D,X ; data to the screen memory
beq skip1
sta (ADDR_1),Y
inx
skip1: inx
iny
patch_2:
lda TILE2D,X
beq skip2
sta (ADDR_1),Y
inx
skip2: inx
iny
patch_3:
lda TILE2D,X
beq skip3
sta (ADDR_1),Y
inx
skip3: inx
iny
patch_4:
lda TILE2D,X
beq skip4
sta (ADDR_1),Y
inx
skip4: inx
iny
lda ADDR_1+1
adc #$04
@ -93,23 +97,27 @@ patch_4:
lin916: ldy #00 ; Y resets to go back to the beginning of screen memory offset
patch_5:
lda TILE2D,X
beq skip5
sta (ADDR_2),Y
inx
skip5: inx
iny
patch_6:
lda TILE2D,X
beq skip6
sta (ADDR_2),Y
inx
skip6: inx
iny
patch_7:
lda TILE2D,X
beq skip7
sta (ADDR_2),Y
inx
skip7: inx
iny
patch_8:
lda TILE2D,X
beq skip8
sta (ADDR_2),Y
inx
skip8: inx
iny
lda ADDR_2+1
adc #$04

View File

@ -6,7 +6,6 @@
.import itemdraw
.import World
.import ItemLoc
.import itemRot
.define UPDATEPT $6
.define UPDATERT $8
@ -16,49 +15,34 @@
_main:
jsr HGR ; Hires setup stuff
jsr BKGND
loop: jsr update ; update runs the "game logic" (more to come)
jmp loop ; to every tile, which animates belts and assemblers
loop: jmp update ; update runs the "game logic" (more to come)
; to every tile, which animates belts and assemblers
update: ldx #00 ; This loop just updates any animated tiles, like conveyors.
update1:lda World,x
cktile: cmp #00
beq view
cmp #16 ; Check if it is one of the three conveyor positions
beq rtconvJ ; Jump if it is
cmp #18
beq rtconvJ
cmp #20
beq rtconv2J ; Jump if it needs to be reset
cmp #22
beq lfconvJ
cmp #24
beq lfconvJ
cmp #26
beq lfconv2J
cmp #10
beq upassmJ
cmp #12
beq upassmJ
cmp #14
beq upassm2J
jmp ckitem
rtconvJ: jmp rtconv
rtconv2J:jmp rtconv2
lfconvJ: jmp lfconv
lfconv2J:jmp lfconv2
upassmJ: jmp upassm
upassm2J:jmp upassm2
ckitem: lda World,x
update1:lda #>updates
sta UPDATEPT+1
lda World,x ; Load every world coordinate
clc
adc #<updates
sta UPDATEPT
ldy #00
lda (UPDATEPT),y
sta UPDATERT
iny
lda (UPDATEPT),y
sta UPDATERT+1
lda World,X
jmp (UPDATERT)
ckitem: lda World,x
clc
cmp #16
bcs upitem
jmp view
upitem: lda ItemLoc,x
bcc view
lda ItemLoc,X
and #$3 ; Isolate *+
cmp #00 ; Right now just right and left
beq itemright
cmp #02
beq orecalc1
cmp #04
beq orecalc2
cmp #06
beq orecalc3
beq itemleft
view: lda World,x
sta TILENUM
txa
@ -73,6 +57,11 @@ view: lda World,x
bcs iview
jmp footer
iview: lda ItemLoc,x
and #$f0 ; Isolate the last 4 bits
lsr ; Move those to the first 4 bits
lsr
lsr
lsr
sta TILENUM
txa
asl
@ -83,71 +72,21 @@ iview: lda ItemLoc,x
tax
footer: inx
cpx #100
bne updateme
rts
updateme:
jmp update1
bne update1
jmp loop
itemright:
itemleft:
jmp view
updates:
.word view, view ; 00, 02
.word insert, insert, insert2 ; 04, 06, 08
.word upassm, upassm, upassm2 ; 10, 12, 14
.word rtconv, rtconv, rtconv2 ; 16, 18, 20
.word lfconv, lfconv, lfconv2 ; 22, 24, 26
orecalc1:
lda ItemRot,x
cmp #00
beq orecalc10
cmp #02
beq orecalc12
jmp view
orecalc10:
lda #04
sta ItemLoc,x
jmp view
orecalc12:
lda #00
sta ItemLoc,x
lda #06
dex
sta ItemLoc,x
jmp view
orecalc2:
lda ItemRot,x
cmp #00
beq orecalc20
cmp #02
beq orecalc22
jmp view
orecalc20:
lda #06
sta ItemLoc,x
jmp view
orecalc22:
lda #02
sta ItemLoc,x
jmp view
orecalc3:
lda ItemRot,x
cmp #00
beq orecalc30
cmp #02
beq orecalc32
jmp view
orecalc30:
lda #00
sta ItemLoc,x
lda #02
inx
sta ItemLoc,x
jmp view
orecalc32:
lda #04
sta ItemLoc,x
jmp view
rtconv: clc ; Add 2 to the tile type, moving it forward 1.
adc #02
@ -216,12 +155,4 @@ slow1: lda #>updates
lda (UPDATEPT),Y
sta UPDATERT+1
lda World,x
jmp (UPDATERT)
updates:
.word view ; If the tile is grass (0), do nothing
.word rtconv, rtconv, rtconv2 ; 02, 04, 06
.word lfconv, lfconv, lfconv2 ; 08, 10, 12
.word insert, insert, insert2 ; 14, 16, 18
.word upassm, upassm, upassm2 ; 20, 22, 24
jmp (UPDATERT)

View File

@ -10,13 +10,10 @@
.export World
.export ItemLoc
.export ItemRot
World: ; This is the array which stores all of the world data.
; Right now this is just 10x10, so no other methods are needed.
.byte 16, 16, 16, 16, 16, 16, 16, 10, 00, 00
.byte 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
.byte 00, 02, 00, 02, 00, 00, 00, 00, 00, 00
.byte 16, 00, 00, 00, 00, 00, 00, 00, 00, 00
.byte 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
.byte 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
.byte 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
@ -24,23 +21,24 @@ World: ; This is the array which stores all of the world data.
.byte 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
.byte 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
.byte 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
.byte 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
.byte 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
; Item's rotation and position.
; 00000000
; | | |
; | | | First two bits are rotation (0-3)
; | | Third and fourth bits are position in cell (0-2)
; | Last 4 bits are the item type.
;
; For reference, 00001100 is $C
; 00000011 is $3
; 00001111 is $F
ItemLoc:
.byte 02, 00, 00, 00, 00, 00, 00, 00, 00, 00
.byte 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
.byte 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
.byte 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
.byte 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
.byte 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
.byte 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
.byte 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
.byte 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
.byte 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
; Item's rotation. 0 is to the right, 1 is up, 2 is left, 3 is down.
ItemRot:
.byte 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
.byte $20, 00, 00, 00, 00, 00, 00, 00, 00, 00
.byte 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
.byte 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
.byte 00, 00, 00, 00, 00, 00, 00, 00, 00, 00

View File

@ -1,3 +1,2 @@
.import World
.import ItemLoc
.import ItemRot
.import ItemLoc