最近设计了一款简陋游戏的雏形
本帖最后由 孤星8 于 2024-6-7 16:42 编辑在命令行窗口下,执行我的程序可以用左键和右键移动太空船(其实只是^符号),暂时不能发射武器。
我是用汇编写的,用的GetKeyState来读取键盘。
format PE console
entry start
include 'win32a.inc'
MOST_LEFT equ 1
MOST_RIGHT equ 70
START_COL equ 35
;START_ROW equ 20
section '.data' data readable writeable
_newpos dd START_COL
_oldpos dd START_COL
_spaceship db '^'
_bullet db '|'
_blank db ' '
_ansi_cls db 27,'[H',27,'[J'
_ansi_cls_len = $ - _ansi_cls
_ansi_reset db 27,'[0m' ; ANSI escape code (reset color)
_ansi_reset_len = $ - _ansi_reset
_instruction db 'Press Left and Right arrow to move; ESC to quit'
_instruction_len= $ - _instruction
_stdout dd ?
_mode dd ?
_number rb 10
_ansi_goto_new rb 9 ; 27,'[00;00H'
_ansi_goto_old rb 9
_count dd ?
;CSI n ; m H
;Moves the cursor to row n, column m. The values are 1-based, and default to 1 (top left corner) if omitted.
;VK_ESCAPE 0x1B ESC key
;VK_LEFT 0x25 LEFT ARROW key
;VK_UP 0x26 UP ARROW key
;VK_RIGHT 0x27 RIGHT ARROW key
;VK_DOWN 0x28 DOWN ARROW key
section '.code' code readable executable
start:
push -11
call
mov dword , eax
push _mode
push
call
or , 4 ;ENABLE_VIRTUAL_TERMINAL_PROCESSING
push
push
call
push 0
push 0
push _ansi_cls_len
push _ansi_cls
push dword
call ;Clear entire screen
push 0
push 0
push _instruction_len
push _instruction
push dword
call ;Print keyboard instruction
mov eax, dword
call itoa
mov , ebx
call DrawSpaceship
.loop:
push 100
call
push 0x1B ;ESC key
call
bt eax, 15 ; If the high-order bit is 1, the key is down; otherwise, it is up
jc .done
push 0x25 ;LEFT ARROW key
call
bt eax, 15
jc .left
push 0x27 ;RIGHT ARROW key
call
bt eax, 15
jc .right
jmp .loop
.left:
call SaveValue
sub , 1
cmp , MOST_LEFT
jl .keepleft
mov eax, dword
call itoa
mov , ebx
;push 0
;push 0
;push ebx
;push _number
;push dword
;call
call DrawSpaceship
jmp .loop
.keepleft:
mov , MOST_LEFT
jmp .loop
.right:
call SaveValue
add , 1
cmp , MOST_RIGHT
jg .keepright
mov eax, dword
call itoa
mov , ebx
;push 0
;push 0
;push ebx
;push _number
;push dword
;call
call DrawSpaceship
jmp .loop
.keepright:
mov , MOST_RIGHT
jmp .loop
.done:
push 0
call
itoa: ;-) Nice code snippet by Pauli Lindgren(https://pkl.paldex.fi/)
; INPUT:EAX
; OUTPUT: _number
; LEN OF OUTPUT: EBX
mov ecx, 10
xor ebx, ebx
.divide:
xor edx, edx
div ecx
push edx
inc ebx
test eax, eax
jnz .divide
mov ecx, ebx
lea esi,
.next:
pop eax
add al, '0'
mov , al
inc esi
loop .next
ret
SaveValue: ;Save old spaceship position
mov eax,
mov , eax
mov ecx, 8
lea edi,
lea esi,
rep movsb
ret
DrawSpaceship:
mov ecx,
lea edi,
mov byte , 27
mov byte , '['
mov byte , '2';START_ROW = 20
mov byte , '0'
mov byte , ';'
add edi,5
lea esi,
rep movsb
mov byte , 'H'
mov byte , 0
push 0
push 0
push 8
push _ansi_goto_new ;New position
push dword
call
push 0
push 0
push 1
push _spaceship
push dword
call ;Draw new spaceship
push 0
push 0
push 8
push _ansi_goto_old ;Old position
push dword
call
push 0
push 0
push 1
push _blank
push dword
call ;Delete old spaceship
ret
section '.idata' import readable writeable
library kernel32, 'KERNEL32.DLL', \
user32, 'USER32.DLL'
import kernel32,\
GetStdHandle, 'GetStdHandle', \
WriteConsole, 'WriteConsoleA', \
ExitProcess,'ExitProcess', \
GetConsoleMode, 'GetConsoleMode',\
SetConsoleMode, 'SetConsoleMode',\
Sleep, 'Sleep'
import user32,\
GetKeyState, 'GetKeyState'
作为一个web开发者,很敬重游戏开发者,哪怕只是雏形,而且还是汇编语言编写的,哈哈{:10_453:} 加油 simonzhd 发表于 2024-6-5 05:24
作为一个web开发者,很敬重游戏开发者,哪怕只是雏形,而且还是汇编语言编写的,哈哈 ...
站长过奖了,你准备学Flutter用Xcode编译iOS应用更让我敬佩你的毅力。哈哈。 james007 发表于 2024-6-5 06:34
加油
谢谢james007,也期待你的作品。 看不太明白 蓝莓糖 发表于 2024-6-6 21:41
看不太明白
很是高兴得到蓝莓糖的重视。你是指源代码看不明白吧? 这个程序打开后中间只有一个^ 符号,可以左右移动,迟点希望可以完善它,射出子弹,再迟点可以有外星飞船,给玩家对准射击。中文有个名称,不知道是什么了,英文名有几个名称,泛称Alien Shooting game / Galaxy spaceship.... 总觉得会编程写码的人很牛。为你点赞! green5 发表于 2024-6-7 13:03
总觉得会编程写码的人很牛。为你点赞!
很高兴得到绿姐的称赞!:D 本帖最后由 孤星8 于 2024-6-7 16:52 编辑
我上传了shooter.zip,内含一个文件shooter.exe,可以用Windows打开运行。(已扫描电脑病毒)
页:
[1]
2