Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Egg;
- interface
- uses
- Windows, sysutils;
- procedure EEgg;
- implementation
- var
- snk : array[1..251] of byte;
- buffer : array[1..11] of byte;
- coloredwelcome : Cardinal = 14;
- siz : Cardinal = 4;
- app : Cardinal = 0;
- direction : Cardinal = 0;
- lastframe : Cardinal = 0;
- score : Cardinal = 0;
- procedure EEgg;
- asm
- lea eax, app
- push eax
- push PAGE_EXECUTE_READWRITE
- push 1
- call @nxt
- @nxt:
- pop eax
- push eax
- call VirtualProtect
- push 0
- push 0
- push 0
- lea eax, @estart//pmon
- push eax
- push 0
- push 0
- call CreateThread
- retn
- //jmp @estart //Deprecated
- @_strlength:
- mov edi, [esp+4]
- xor eax, eax
- xor ecx, ecx
- not ecx
- repne scasb
- not ecx
- dec ecx
- mov eax, ecx
- ret 4
- @stringPlaceHolder: db ' '
- @_write:
- push dword [esp+4]
- call @_strlength
- push eax
- push -11
- call GetStdHandle
- pop ecx
- push 0
- lea edx, @stringPlaceHolder
- push edx
- push ecx
- push dword [esp+16]
- push eax
- call WriteConsole
- ret 4
- @_writeln:
- push dword [esp+4]
- call @_write
- call @1
- db $0A, $0D, $00
- @1:
- call @_write
- ret 4
- @_setpos:
- shl dword [esp+8], 16
- mov eax, [esp+4]
- or [esp+8], eax
- push dword [esp+8]
- push -11
- call GetStdHandle
- pop ecx
- push ecx
- push eax
- call SetConsoleCursorPosition
- ret 8
- @_setcolor:
- push -11
- call GetStdHandle
- push dword [esp+4]
- push eax
- call SetConsoleTextAttribute
- ret 4
- @_inttostr:
- lea edi, buffer
- mov ecx, 10
- xor al, al
- rep stosb
- lea ecx, buffer+11
- mov eax, [esp+4]
- push 10
- @2:
- xor edx, edx
- div dword [esp]
- add edx, $30
- mov byte [ecx], dl
- dec ecx
- test eax, eax
- jnz @2
- pop eax
- inc ecx
- mov eax, ecx
- ret 4
- @random: dd @_random
- @_random:
- call GetTickCount
- mov ecx, eax
- and ecx, 11b
- shr eax, cl
- xor edx, edx
- push dword [esp+4]
- div dword [esp]
- mov eax, edx
- add esp, 4
- ret 4
- @ispressed: dd @_ispressed
- @_ispressed:
- push dword [esp+4]
- call GetAsyncKeyState
- and eax, $8000
- ret 4
- @APPLE_COLOR: dd 194
- @SNAKE_COLOR: dd 42
- @SNAKE_HEAD: dd 162
- @FIELD_COLOR: dd 0
- @FIELD_WIDTH: dd 60
- @FIELD_HEIGHT: dd 20
- @FPS: dd 65
- @spawn_apple:
- push dword [@FIELD_WIDTH]
- call @_Random
- mov dword [app], eax
- shl dword [app], 8
- push dword [@FIELD_HEIGHT]
- call @_Random
- or dword [app], eax
- retn
- @update_direction:
- push VK_DOWN
- call @_ispressed
- test eax, eax
- jz @5
- cmp dword [direction], VK_UP
- je @5
- mov dword [direction], VK_DOWN
- @5:
- push VK_UP
- call @_ispressed
- test eax, eax
- jz @4
- cmp dword [direction], VK_DOWN
- je @4
- mov dword [direction], VK_UP
- @4:
- push VK_RIGHT
- call @_ispressed
- test eax, eax
- jz @7
- cmp dword [direction], VK_LEFT
- je @7
- mov dword [direction], VK_RIGHT
- @7:
- push VK_LEFT
- call @_ispressed
- test eax, eax
- jz @6
- cmp dword [direction], VK_RIGHT
- je @6
- mov dword [direction], VK_LEFT
- @6:
- ret
- @dot: db ' ', 0
- @shead: db '@', 0
- @sapple: db '+', 0
- @draw_field:
- push dword [@SNAKE_COLOR]
- call @_setcolor
- mov ecx, dword [siz]
- dec ecx
- @8:
- push ecx
- lea eax, snk
- shl ecx, 1
- add eax, ecx
- movzx eax, word [eax]
- mov edx, eax
- and edx, $FF
- shr eax, 8
- and eax, $FF
- push edx
- push eax
- call @_setpos
- lea eax, @dot
- push eax
- call @_write
- pop ecx
- loop @8
- push dword [@SNAKE_HEAD]
- call @_setcolor
- lea eax, snk
- movzx eax, word [eax]
- mov edx, eax
- and edx, $FF
- shr eax, 8
- and eax, $FF
- push edx
- push eax
- call @_setpos
- lea eax, @shead
- push eax
- call @_write
- push dword [@APPLE_COLOR]
- call @_setcolor
- lea eax, app
- movzx eax, word [eax]
- mov edx, eax
- and edx, $FF
- shr eax, 8
- and eax, $FF
- push edx
- push eax
- call @_setpos
- lea eax, @sapple
- push eax
- call @_write
- push 0
- push 0
- call @_setpos
- ret
- @calculate:
- mov eax, dword [siz]
- dec eax
- shl eax, 1
- lea edx, snk
- add eax, edx
- xor edx, edx
- movzx eax, word [eax]
- mov dx, ax
- and dx, $FF
- shr ax, 8
- push edx
- push eax
- call @_setpos
- push 0
- call @_setcolor
- lea eax, @dot
- push eax
- call @_write
- mov ecx, dword [siz]
- @9:
- mov eax, ecx
- shl eax, 1
- lea edx, snk
- add eax, edx
- xor edx, edx
- mov edx, ecx
- dec edx
- shl edx, 1
- lea ebx, snk
- add edx, ebx
- mov dx, word [edx]
- mov word [eax], dx
- mov eax, dword [siz]
- dec ecx
- test ecx, ecx
- jnz @9
- mov eax, dword [direction]
- cmp eax, VK_UP
- jne @10
- lea eax, snk
- dec byte [eax]
- cmp byte [eax], $FF
- je @_lost
- retn
- @10:
- cmp eax, VK_DOWN
- jne @11
- lea eax, snk
- inc byte [eax]
- mov ecx, dword [@FIELD_HEIGHT]
- inc ecx
- //mov ecx, dword [ecx]
- cmp byte [eax], cl
- je @_lost
- retn
- @11:
- cmp eax, VK_LEFT
- jne @12
- lea eax, snk
- inc eax
- dec byte [eax]
- cmp byte [eax], $FF
- je @_lost
- retn
- @12:
- cmp eax, VK_RIGHT
- jne @13
- lea eax, snk
- inc eax
- inc byte [eax]
- mov ecx, dword [@FIELD_WIDTH]
- inc ecx
- cmp byte [eax], cl
- je @_lost
- @13:
- retn
- @check_game:
- xor ecx, ecx
- inc ecx
- @14:
- mov eax, ecx
- shl eax, 1
- lea edx, snk
- add eax, edx
- movzx eax, word [eax]
- cmp ax, word [snk]
- je @_lost
- inc ecx
- cmp ecx, dword [siz]
- jne @14
- movzx eax, word [snk]
- cmp eax, dword [app]
- jne @15
- call @spawn_apple
- mov eax, dword [siz]
- shl eax, 1
- add dword [score], eax
- inc dword [siz]
- @15:
- ret
- @_lost:
- push 0
- call @_setcolor
- push 7
- call @_setcolor
- push 0
- push 0
- call @_setpos
- lea eax, @dead
- push eax
- call @_write
- push dword [score]
- call @_inttostr
- push eax
- call @_write
- lea eax, @dead2
- push eax
- call @_write
- @91:
- push VK_RETURN
- call @_ispressed
- jnz @90
- push 10
- call Sleep
- jmp @91
- @90:
- push VK_RETURN
- call @_ispressed
- test eax, eax
- jnz @90
- jmp @estart
- @wall: db '#', 0
- @Draw_boarders:
- push 7
- call @_setcolor
- mov ecx, dword [@FIELD_WIDTH]
- inc ecx
- @20:
- push ecx
- dec ecx
- mov edx, dword [@FIELD_HEIGHT]
- inc edx
- push edx
- push ecx
- call @_setpos
- lea eax, @wall
- push eax
- call @_write
- pop ecx
- loop @20
- mov ecx, dword [@FIELD_HEIGHT]
- inc ecx
- @21:
- push ecx
- dec ecx
- mov edx, dword [@FIELD_WIDTH]
- inc edx
- push ecx
- push edx
- call @_setpos
- lea eax, @wall
- push eax
- call @_write
- pop ecx
- loop @21
- ret
- //----------------------- MAIN CODE --------------------
- @mstr: db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
- @current: dd 0
- @pmon:
- @_a:
- mov ecx, $80
- @_b:
- push ecx
- push ecx
- call @ispressed
- test eax, eax
- jz @_nxt
- lea eax, @mstr
- add eax, dword [@current]
- mov byte [eax], cl
- @_nxt:
- pop ecx
- cmp ecx, 47
- jb @_c
- loop @_b
- @_c:
- push 1
- call Sleep
- jmp @_a
- @estart:
- call AllocConsole
- push 1
- push 1
- call @_setpos
- lea eax, ColoredWelcome
- push eax
- call @_setcolor
- lea eax, @Welcome
- push eax
- call @_write
- @30:
- push 50
- call Sleep
- inc dword [coloredwelcome]
- cmp dword [coloredwelcome], $10
- jnge @_novary
- and dword [coloredwelcome], 0
- @_novary:
- push dword [ColoredWelcome]
- call @_setcolor
- push 1
- push 1
- call @_setpos
- lea eax, @Welcome
- push eax
- call @_write
- push VK_RETURN
- call @_ispressed
- test eax, eax
- jz @30
- call @draw_boarders
- mov ecx, 251
- lea edi, snk
- xor al, al
- rep stosb
- lea eax, snk
- mov word [eax],$0300
- add eax, 2
- mov word [eax],$0200
- add eax, 2
- mov word [eax],$0100
- add eax, 2
- mov word [eax],$0000
- mov dword [siz], 4
- mov dword [direction], VK_RIGHT
- call @spawn_apple
- @31:
- call GetTickCount
- sub eax, [lastframe]
- and eax, $FFFF
- cmp eax, 65
- jng @_01
- call @update_direction
- call @calculate
- call @check_game
- call @draw_field
- call GetTickCount
- mov lastframe, eax
- @_01:
- push 3
- call @_setcolor
- mov eax, dword [@FIELD_HEIGHT]
- add eax, 2
- push eax
- push 0
- call @_setpos
- movzx eax, byte [snk]
- push eax
- call @_inttostr
- push eax
- call @_write
- lea eax, @dot
- push eax
- call @_write
- movzx eax, byte [snk+1]
- push eax
- call @_inttostr
- push eax
- call @_write
- lea eax, @dot
- push eax
- call @_writeln
- lea eax, @sscore
- push eax
- call @_write
- push dword [score]
- call @_inttostr
- push eax
- call @_write
- push 1
- call Sleep
- jmp @31
- retn
- @WELCOME:
- db ' ad88888ba ,ad8888ba, db' , $0A, $0D
- db ' d8" "8b d8"'' `"8b d88b' , $0A, $0D
- db ' Y8, d8'' `8b d8''`8b' ,$0A, $0D
- db ' `Y8aaaaa, 88 88 d8'' `8b' , $0A, $0D
- db ' `"""""8b, 88 88 d8YaaaaY8b' , $0A, $0D
- db ' `8b Y8, "88,,8P d8""""""""8b' , $0A, $0D
- db ' Y8a a8P Y8a. Y88P d8'' `8b' , $0A, $0D
- db ' "Y88888P" `"Y8888Y"Y8a d8'' `8b', $0A, $0D, $0A, $0D
- db ' [ENTER] ', $0A, $0D, $00
- @sscore: db 'Score ', 0
- @dead: db 'Des end [', 0
- @dead2: db ' points]', 0
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement