Files
crawos/source/games/pong.asm
deadvey 07932e2ce0 Pong
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>
2025-10-16 13:56:17 +01:00

100 lines
1.6 KiB
NASM

game_pong:
call .draw_players
call .detect_input
; Clears screen and draws both players and ball
.draw_screen:
call os_set_graphics_mode ; Clear screen
.draw_p1:
; Player 1
mov ax, [p1_x]
mov [x_start], ax
mov [x_end], ax
mov bx, [p1_y]
mov [y_start], bx
add bx, [bat_height]
mov [y_end], bx
call os_draw_graphical_rectangle ; Draw player 1
.draw_p2:
; Player 2
mov ax, [p2_x]
mov [x_start], ax
mov [x_end], ax
mov bx, [p2_y]
mov [y_start], bx
add bx, [bat_height]
mov [y_end], bx
call os_draw_graphical_rectangle ; Draw player 1
ret
; Player 1 movements
.p1_up:
mov dx, [p1_y]
sub dx, 5
mov [p1_y], dx
call .draw_players
jmp .detect_input
.p1_down:
mov dx, [p1_y]
add dx, 5
mov [p1_y], dx
call .draw_players
jmp .detect_input
; Player 2 movements
.p2_up:
mov dx, [p2_y]
sub dx, 5
mov [p2_y], dx
call .draw_players
jmp .detect_input
.p2_down:
mov dx, [p2_y]
add dx, 5
mov [p2_y], dx
call .draw_players
jmp .detect_input
; Ball bouncing
.bounce_ball:
.detect_input:
call os_read_input
cmp al, 08h
je .finish
; Player 1
cmp al, 77h ; Pressed 'w' (player 1 up)
je .p1_up
cmp al, 73h ; Pressed 's' (player 1 down)
je .p1_down
; Player 2
cmp al, 5bh ; Pressed '[' (player 2 up)
je .p2_up
cmp al, 27h ; Pressed ''' (player 2 down)
je .p2_down
jmp .detect_input
.finish:
call os_set_text_mode
call os_start_cli
section .data
ball_x dw 5
ball_y dw 5
p1_x dw 5
p1_y dw 5
p2_x dw 315
p2_y dw 5
bat_height dw 20