I forgot to commit for a while and I haven't done much, but got the very basics of the game pong working. Signed-off-by: deadvey <deadvey@deadvey.com>
87 lines
1.4 KiB
NASM
87 lines
1.4 KiB
NASM
game_pong:
|
|
pusha
|
|
call os_set_graphics_mode
|
|
jmp .draw_player_1
|
|
jmp .draw_player_2
|
|
jmp .detect_inputi
|
|
.draw_player_1:
|
|
; X coords
|
|
mov ax, [p1_x]
|
|
mov [x_start], ax
|
|
mov [x_end], ax
|
|
|
|
; Y coords
|
|
mov bx, [p1_y]
|
|
mov [y_start], bx
|
|
add bx, [bat_height] ; Add the bat height to the y coord
|
|
mov [y_end], b
|
|
call os_draw_graphical_rectangle
|
|
ret
|
|
.draw_player_2:
|
|
; X coords
|
|
mov ax, [p2_x]
|
|
mov [x_start], ax
|
|
mov [x_end], ax
|
|
|
|
; Y coords
|
|
mov bx, [p2_y]
|
|
mov [y_start], bx
|
|
add bx, [bat_height] ; Add the bat height to the y coord
|
|
mov [y_end], bx
|
|
|
|
call os_draw_graphical_rectangle
|
|
ret
|
|
.detect_input:
|
|
call os_read_input
|
|
; Exit if backspace is pressed
|
|
cmp al, 08h
|
|
je .finish
|
|
; Go up when you press 'w'
|
|
cmp al, 77h
|
|
je .p1_up
|
|
; Go up when you press 's'
|
|
cmp al, 73h
|
|
je .p1_down
|
|
|
|
; Loop back
|
|
jmp .detect_input
|
|
.p1_down:
|
|
; X coords
|
|
mov ax, [p1_x]
|
|
mov [x_start], ax
|
|
mov [x_end], ax
|
|
|
|
; Y coords
|
|
mov bx, [p1_y]
|
|
add bx, 5 ; Move the bat down 5
|
|
mov [y_start], bx
|
|
add bx, [bat_height] ; Add the bat height to the y coord
|
|
mov [y_end], bx
|
|
|
|
call os_draw_graphical_rectangle
|
|
ret
|
|
.p1_up:
|
|
mov ax, [move_distance]
|
|
sub ax, [p1_y]
|
|
call os_draw_graphical_rectangle
|
|
ret
|
|
.finish:
|
|
call os_set_text_mode
|
|
popa
|
|
ret
|
|
|
|
section .data
|
|
x_start dw 0
|
|
y_start dw 0
|
|
x_end dw 0
|
|
y_end dw 0
|
|
|
|
p1_y dw 5
|
|
p2_y dw 0
|
|
p1_x dw 5
|
|
p2_x dw 30
|
|
|
|
bat_height dw 20
|
|
move_distance dw 5
|
|
colour db 1111b
|