floppyboot

bootsector Flappy Bird clone for x86
git clone git://squid-tech.com/floppyboot.git
Log | Files | Refs | README

commit 0a38ad7d87abb32fa5f84ec8773b2c0468b825a0
parent 3c5ff1da1de88e12e5a90127b00bd608b1daa424
Author: Josh Moore <jxm5210@rit.edu>
Date:   Sun, 12 Jan 2020 15:16:38 -0500

Add gravity

Diffstat:
Mfloppyboot.asm | 125++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 111 insertions(+), 14 deletions(-)

diff --git a/floppyboot.asm b/floppyboot.asm @@ -6,6 +6,13 @@ org 0x7C00 %define JUMP_KEY 0x48 ; up arrow + +%define MAX_FALL 1 ; maximum rate of fall +%define JUMP_VEL -1 ; jump speed + +%define START_ROW 12 +%define START_COL 3 + boot: ; set video mode to 40x25 16-color MOV AH, 0x00 @@ -23,9 +30,10 @@ boot: MOV CH, 0x3F INT 0x10 + CALL draw_bird + loop: ; main game loop - .input: ; check input keystroke MOV AH, 0x01 @@ -45,15 +53,47 @@ loop: .process_game: ; update game state, draw graphics - - JMP loop.input -halt: - CLI - HLT + ; process bird fall + MOV CH, [birdy] + MOV CL, [birdx] + + ADD CH, [birdvy] + CALL move_bird + + ; add gravity + MOV AL, [birdvy] + CMP AL, MAX_FALL + JE loop.checkfalldeath + ADD AL, 1 + MOV [birdvy], AL + +.checkfalldeath: + ; check fall death + MOV AL, [birdy] + CMP AL, 24 ; the bottom row + JL loop.delay + + ; set the bird's vertical position to the bottom row + MOV CH, 24 + CALL move_bird + JMP end_game + +.delay: + ; delay + MOV CX, 0x01 + MOV DX, 0x86A0 + MOV AH, 0x86 + INT 0x15 + + JMP loop + +end_game: + JMP end_game draw_bird: ; draw the bird at birdx and birdy + ; set AL to the character to draw for the bird ; returns nothing PUSHA @@ -66,30 +106,87 @@ draw_bird: ; draw the bird MOV AH, 0x09 - MOV AL, 0x40 ; @ MOV BH, 0x00 + MOV AL, '@' MOV BL, 0x0E MOV CX, 1 INT 0x10 POPA - RET + RET jump_bird: + PUSH AX + + MOV AL, JUMP_VEL + MOV [birdvy], AL + + POP AX + RET + +move_bird: + ; move the bird to a new location + ; CH = new row + ; CL = new col + PUSHA - MOV AL, [birdy] - SUB AL, 1 - MOV [birdy], AL - CALL draw_bird + ; check whether the new row is less than 0 + ; if it is, set the new row to 0 + CMP CH, 0 + JGE move_bird.checkloc + MOV CH, 0 + +.checkloc: + ; do nothing if the new loc is the same as the old + MOV DH, [birdy] + MOV DL, [birdx] + CMP CX, DX + JE move_bird.return + + ; draw bird at new location + MOV AH, 0x02 + MOV BH, 0x00 + MOV DH, CH + MOV DL, CL + INT 0x10 + + PUSH CX + + MOV AH, 0x0A + MOV AL, '@' + MOV CX, 1 + INT 0x10 + + ; draw blank at current location + MOV AH, 0x02 + MOV DH, [birdy] + MOV DL, [birdx] + INT 0x10 + + MOV AH, 0x0A + MOV AL, ' ' + MOV CX, 1 + INT 0x10 + + POP CX + + ; set the bird's game location to the new location + MOV [birdy], CH + MOV [birdx], CL + +.return: POPA RET ; game data ; bird position -birdx: db 6 -birdy: db 6 +birdx: db START_COL +birdy: db START_ROW + +; bird vertical velocity +birdvy: db 0 times 510 - ($-$$) db 0 ; pad with zeroes to 510 bytes dw 0xAA55 ; bootloader magic