Skip to content

Instantly share code, notes, and snippets.

@RaphGL
Created June 22, 2023 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RaphGL/bbd4f0df5833d829ddf57a96e94c9f17 to your computer and use it in GitHub Desktop.
Save RaphGL/bbd4f0df5833d829ddf57a96e94c9f17 to your computer and use it in GitHub Desktop.
Flappy Bird for the Chip8. It uses Wernsey's Chip8 assembler: https://github.com/wernsey/chip8
define x v0
define y v1
define tube_x v2
define tube_y v3
define px v4
define py v5
define k_flap v6
define score v7
define x2 v8
define arg1 va
define arg2 vb
; initialization
ld x, 63
ld x2, 31
ld px, 5
ld vd, 0
ld k_flap, 8
ld score, 0
rnd tube_y, #0f
start:
; waits for 1/60s to pass
ld vd, dt
se vd, 0
jp start
cls
call player_handle_physics
call player_draw
; draws first tube
add x, -1
ld arg1, x
sne x, 62
rnd arg2, #0b
call draw_tubes
; draws second tube
add x2, -1
ld arg1, x2
sne x2, 62
rnd arg2, #0b
call draw_tubes
; print player score
sne x, px
add score, 1
ld arg1, 30
ld arg2, 40
ld f, score
drw arg1, arg2, 5
; creates timer to make game 60 fps
ld vd, 1
ld dt, vd
jp start
; draws the player sprite
player_draw:
ld i, player
drw px, py, 3
ret
; handles physics and player input
player_handle_physics:
sknp k_flap
add py, -1
sne py, 29
ret
skp k_flap
add py, 1
ret
; draw_tubes(x, y)
; x and y indicate the location of the gap
; in between the tubes
draw_tubes:
ld i, tube
; draws upper tube
ld tube_x, arg1
ld tube_y, -8
add tube_y, arg2
drw tube_x, tube_y, 8
; draws lower tube
ld tube_x, arg1
ld tube_y, 16
add tube_y, arg2
drw tube_x, tube_y, 8
ret
tube:
db %01111110,
%01111110,
%01111110,
%01111110,
%01111110,
%01111110,
%01111110,
%01111110
player:
db %00111100,
%00111100,
%00111100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment