1
0
mirror of https://github.com/fumiama/c64-snake.git synced 2026-06-05 00:32:39 +08:00

很多改进

This commit is contained in:
fumiama
2021-04-13 23:29:01 +08:00
parent 44c4e25be1
commit 43aa9250b1
7 changed files with 71 additions and 128 deletions

View File

@@ -48,14 +48,9 @@ addfood:
tay
* lda (_ptr), y
iny
cmp #csnk
beq -
cmp #cblk
beq -
cmp #crnd
beq -
cmp #csps
bne -
lda #crnd
dey
sta (_ptr), y
rts
.scend

View File

@@ -16,7 +16,7 @@
.data zp
.space d 1 ; 方向 值定义如上
.space c 1 ; 🐍长度 最大255 最小0
.space prev_d 1 ; 前一个方向
.space s 2 ; 得分 小端序
.space _ptr 2 ; 通用指针
.space eat 1 ; 吃到食物标记

View File

@@ -13,7 +13,7 @@ printfail:
`print failhint
rts
erasehint:
ldy #25
ldy #22
lda #csps
* sta [title+20*40+8-1], y
dey

150
judge.asm
View File

@@ -24,75 +24,13 @@
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
judgeout:
.scope
lda d
;;方向向上
cmp #go_u
beq _gup
;;方向向下
cmp #go_d
beq _gdown
;;方向向左
cmp #go_l
beq _gleft
;;方向向右
cmp #go_r
beq _gright
jmp _End1 ;什么都没有撞
`judgeof cblk
bcs +
cmp #csnk
bne +
sec
* rts
;是否撞墙;是否考虑溢出情况;撞墙撞自己要不要分开写?
_gup: ;地址-40?实现:/减法/地址跳跃
lda shead
sec
sbc #40
sta _ptr
lda shead+1
sbc #0
sta _ptr+1
ldy #0
lda (_ptr),y
cmp #cblk
beq _End2
jmp _selfx
_gdown: ldy #40 ;地址+40,好像有问题,这个(shead)是蛇头地址的地址了 拟修改:lda (取低位用啥来着)(shead),sec, adc #40,
lda (shead),y
cmp #cblk
beq _End2
jmp _selfx
_gleft:
lda shead
sec
sbc #1
sta _ptr
lda shead+1
sbc #0
sta _ptr+1
ldy #0
lda (_ptr),y
cmp #cblk
beq _End2
jmp _selfx
_gright:ldy #1 ;地址+1好像有问题这个(shead) 拟修改:lda (取低位用啥来着)(shead),sec,adc #
lda (shead),y
cmp #cblk
beq _End2
_selfx: cmp #csnk
beq _End2
;蛇没死
_End1: clc
rts
;蛇死了
_End2: sec
rts
.scend
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; judgefood 判断是否吃到食物
; 是->sec 即进位标志置1
@@ -104,8 +42,17 @@ _End2: sec
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
judgefood:
.scope
`judgeof crnd
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; judgeof 两个判断的宏
; 是->sec 即进位标志置1
; 否->clc 即进位标志置0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.macro judgeof
lda d
ldy #0
;;方向向上
cmp #go_u
beq _gup
@@ -121,54 +68,43 @@ judgefood:
jmp _End1 ;输入了一个无效字符,,,,,?
;是否撞墙;是否考虑溢出情况-不用;撞墙撞自己要不要分开写?
_gup:
lda shead
sec
sbc #40
sta _ptr
lda shead+1
sbc #0
sta _ptr+1
ldy #0
_gup:
`_m_ptr_minus 40
lda (_ptr),y
jmp _compare
cmp #crnd
beq _End2
bne _End1
_gdown: ldy #40 ;地址+40
_gdown:
ldy #40 ;地址+40
lda (shead),y
cmp #crnd
beq _End2
bne _End1
jmp _compare
_gleft:
lda shead
sec
sbc #1
sta _ptr
lda shead+1
sbc #0
sta _ptr+1
ldy #0
_gleft:
`_m_ptr_minus 1
lda (_ptr),y
jmp _compare
cmp #crnd
beq _End2
bne _End1
_gright:ldy #1 ;地址+1
_gright:
ldy #1 ;地址+1
lda (shead),y
cmp #crnd
_compare:
cmp #_1
beq _End2
;没吃到
;没吃到 默认情况
_End1: clc
rts
jmp _end
;吃到了
_End2: sec
rts
_end:
.macend
.scend
.macro _m_ptr_minus
lda shead
sec
sbc #_1
sta _ptr
lda shead+1
sbc #0
sta _ptr+1
.macend

View File

@@ -19,20 +19,27 @@ main:
sta eat
jsr judgefood ; 判断是否吃到食物
bcc +
inc c ; 蛇长加一
lda #1
sta eat
jsr addfood
* jsr move ; 蛇移动一格
jsr calcscore ; 计算得分
jsr printscore ; 打印分数
lda d
sta prev_d ; 备份前一个按键
lda #32
jsr delay ; 延时期间最后一个按键位于d
lda d
cmp #ed_g
bne +
beq _end
cmp #st_g
bne ---
jsr getchar
lda prev_d
sta d ; 恢复按键
jmp ---
_end:
rts
* jmp ----
.scend
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -47,8 +54,6 @@ main:
sta s + 1 ; 初始化分数为0
jsr printscore ; 打印分数
jsr move_init
lda #2
sta c ; 初始化蛇长为1
jsr printfield ; 打印蛇,包括边框
jsr printhint ; 打印开始提示
lda #go_d ; 初始化方向为下

View File

@@ -5,10 +5,13 @@ printfield:
.scope
ldx #23 ; i代表行数不含边框
lda #<field ; 取地址低8位
clc
adc #1
sta _ptr
lda #>field ; 取地址高8位
sta _ptr + 1
ldy #0
jsr _print_blk_line
;ldy #0 ; 此时y一定为0
* lda #cblk
sta (_ptr), y ; 打印左边框
lda #39
@@ -19,12 +22,7 @@ printfield:
jsr _addptr
dex
bne -
lda #cblk
ldy #40
dec _ptr
* sta (_ptr), y ; 打印底边
dey
bne -
jsr _print_blk_line
rts
_addptr:
@@ -34,4 +32,13 @@ _addptr:
inc _ptr + 1
* sta _ptr
rts
_print_blk_line:
lda #cblk
ldy #40
dec _ptr
* sta (_ptr), y ; 打印底边
dey
bne -
rts
.scend

BIN
snake.prg

Binary file not shown.