aboutsummaryrefslogtreecommitdiff
path: root/game/entities.asm
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-05-12 23:36:49 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-05-12 23:36:49 +0100
commita20b308cfe92a8bb47c6896e7fdb24b15c2efd59 (patch)
tree22a38850ea38dc91f02095101192061aaafbc30d /game/entities.asm
parent8eec2f91339b8f06e1b80c49c976a9d9ac6e01f7 (diff)
downloadtr8vm-a20b308cfe92a8bb47c6896e7fdb24b15c2efd59.tar.gz
tr8vm-a20b308cfe92a8bb47c6896e7fdb24b15c2efd59.zip
Add player bullets
Also a changes in the entity system: - don't preserve the BG (always erase black) - skip unused entities - fix in the reserved size (and entity is 8 bytes) - allocate new entities
Diffstat (limited to 'game/entities.asm')
-rw-r--r--game/entities.asm197
1 files changed, 96 insertions, 101 deletions
diff --git a/game/entities.asm b/game/entities.asm
index b3e1eea..eb9c44f 100644
--- a/game/entities.asm
+++ b/game/entities.asm
@@ -5,15 +5,35 @@
.equ ET_NONE 0
.equ ET_PLAYER 1
.equ ET_ENEMY 2
+.equ ET_BULLET 3
.equ ET_END 0xff
.equ ET_BG 0xa000
-entities_erase:
- ; bg is stored in ET_BG addr
- ld b, >ET_BG
- push b
+entities_init:
+ ld x, <entities
+ ld a, >entities
+
+ ; skip player
+ add x, 8
+ bo
+ inc a
+
+entities_init_next:
+ ld y, [a : x]
+ cmp y, ET_END
+ bz
+ ret
+
+ ld y, ET_NONE
+ ld [a : x], y
+
+ add x, 8
+ bo
+ inc a
+ jmp entities_init_next
+entities_erase:
ld x, <entities
ld a, >entities
@@ -21,8 +41,17 @@ entities_erase_next:
ld y, [a : x]
cmp y, ET_END
bz
- jmp entities_erase_done
+ ret
+ cmp y, 0
+ bnz
+ jmp entities_erase_in_use
+
+ add x, 8
+ bo
+ inc a
+ jmp entities_erase_next
+entities_erase_in_use:
; settings mode
ld y, 128
ld b, 0xb0
@@ -32,9 +61,9 @@ entities_erase_next:
inc b
; addr: bg data
- ld y, 0
+ ld y, <ET_BG
port b, y
- ld y, [sp + 0]
+ ld y, >ET_BG
port b, y
; x
@@ -66,17 +95,8 @@ entities_erase_next:
add x, 6
bo
inc a
-
- pop b
- inc b
- push b
-
jmp entities_erase_next
-entities_erase_done:
- pop a
- ret
-
entities_update:
ld x, <entities
ld a, >entities
@@ -86,7 +106,16 @@ entities_update_next:
cmp y, ET_END
bz
ret
+ cmp y, 0
+ bnz
+ jmp entities_update_in_use
+
+ add x, 8
+ bo
+ inc a
+ jmp entities_update_next
+entities_update_in_use:
push a
push x
@@ -124,10 +153,6 @@ entities_update_next:
jmp entities_update_next
entities_draw:
- ; bg is stored in ET_BG addr
- ld b, >ET_BG
- push b
-
ld x, <entities
ld a, >entities
@@ -135,30 +160,19 @@ entities_draw_next:
ld y, [a : x]
cmp y, ET_END
bz
- jmp entities_draw_done
-
- ; two local variables to keep x, y coord
-
- inc x
- bo
- inc a
- ld y, [a : x]
- ; x coord
- push y
+ ret
+ cmp y, 0
+ bnz
+ jmp entities_draw_in_use
- inc x
+ add x, 8
bo
inc a
- ld y, [a : x]
- ; y coord
- push y
+ jmp entities_draw_next
- inc x
- bo
- inc a
- ; a : x points to the frame
+entities_draw_in_use:
- ; save bg data
+ ; draw sprite
; settings mode
ld y, 128
@@ -168,49 +182,19 @@ entities_draw_next:
; setup
inc b
- ; addr: bg data saving space
- ld y, 0
- port b, y
- ld y, [sp + 2]
- port b, y
-
- ; x
- ld y, [sp + 1]
- port b, y
-
- ; y
- ld y, [sp + 0]
- port b, y
-
- ; 16x16
- ld y, 16
- port b, y
- port b, y
-
- ; blit
- dec b
- ; read, no transparent
- ld y, 4
- port b, y
-
- ; draw sprite
-
- ; settings mode
- ld y, 128
- ld b, 0xb0
- port b, y
+ push a
+ push x
- ; setup
- inc b
+ add x, 3
+ bo
+ inc a
- ; prepare some local variables
+ ; frame number
+ ld b, [a : x]
- ; frame
- ld y, [a : x]
inc x
bo
inc a
- push y
; sprite addr
ld y, [a : x]
@@ -219,19 +203,14 @@ entities_draw_next:
bo
inc a
ld y, [a : x]
- push y
- ; frame number
- ld b, [sp + 2]
entity_draw_frame:
dec b
bo
jmp entity_draw_frame_done
; calculate frame
- ld y, [sp + 0]
inc y
- ld [sp + 0], y
jmp entity_draw_frame
entity_draw_frame_done:
@@ -239,23 +218,28 @@ entity_draw_frame_done:
; settings port
ld b, 0xb1
+ ld x, y
+ pop y
+
; addr: sprite data
- ld y, [sp + 1]
- port b, y
- ld y, [sp + 0]
port b, y
+ port b, x
- ; free local variables
- pop y
- pop y
- pop y
+ pop x
+ pop a
+
+ inc x
+ bo
+ inc a
; x
- ld y, [sp + 1]
+ ld y, [a : x]
port b, y
-
+ inc x
+ bo
+ inc a
; y
- ld y, [sp + 0]
+ ld y, [a : x]
port b, y
; 16x16
@@ -269,20 +253,31 @@ entity_draw_frame_done:
ld y, 3
port b, y
- pop y
- pop y
-
; next entity
- add x, 3
+ add x, 6
bo
inc a
+ jmp entities_draw_next
- pop b
- inc b
- push b
+entities_new:
+ ld x, <entities
+ ld a, >entities
- jmp entities_draw_next
+entities_new_loop:
+ ld y, [a : x]
+ cmp y, ET_END
+ ccf
+ bz
+ ret
+ cmp y, 0
+ bz
+ jmp entities_new_found
-entities_draw_done:
- pop a
+ add x, 8
+ bo
+ inc a
+ jmp entities_new_loop
+
+entities_new_found:
+ scf
ret