Files
pipgupip/windows/bat/flappybird/FlappyBird.exb
T

123 lines
2.5 KiB
Plaintext
Raw Normal View History

noout(chcp 65001)
include(console)
include(time)
include(math)
define(MAP_WIDTH, 50)
define(MAP_HEIGHT, 15)
define(PIPES_COUNT, 4)
function get_cell(x, y, out_res)
set "$out_res=!map[$y][$x]!"
end function
function set_cell(x, y, val)
set "map[$y][$x]=$val"
end function
//function draw_map()
// for /l %%i in (0,1,calc{MAP_HEIGHT-1}) do (
// set "txt="
// for /l %%j in (0,1,calc{MAP_WIDTH-1}) do (
// set "txt=!txt!!map[%%i][%%j]!"
// )
// echo.!txt!
// )
//end function
function draw_map()
set i=0
set j=0
set /a mh=MAP_HEIGHT-1
set /a mw=MAP_WIDTH-1
:_dm_loop_y
set "txt="
:_dm_loop_x
pause>nul
call set txt=%txt%%%map[%i%][%j%]%%
set /a j+=1
if %j% lss %mw% goto _dm_loop_x
title %j% %i%
set /a i+=1
if %i% lss %mh% goto _dm_loop_y
end function
function move_cell(old_x, old_y, new_x, new_y)
get_cell($old_x, $old_y, out _cell_val)
set_cell($old_x, $old_y, " ")
set_cell($new_x, $new_y, %_cell_val%)
end function
function draw_player()
set_cell($player_x, $player_y, "●")
end function
function create_pipe(x, val, char)
for /l %%i in (0,1,calc{$val-3}) do (
set_cell($x, calc{MAP_HEIGHT-1-%%i}, "$char")
)
for /l %%i in (0,1,calc{MAP_HEIGHT-$val-3}) do (
set_cell($x, %%i, "$char")
)
end function
function create_pipes()
for /l %%i in (1,1,4) do (
random(0, calc{MAP_HEIGHT-3}, out pipe%%i_val)
)
end function
function move_pipes(off)
for /l %%i in (1,1,4) do (
create_pipe(calc{10*%%i-$pipe_offset}, $pipe%%i_val, " ")
create_pipe(calc{10*%%i-$pipe_offset-$off}, $pipe%%i_val, "█")
)
set /a pipe_offset+=$off
end function
title Flappy Bird
set_size(MAP_WIDTH, calc{MAP_HEIGHT+2})
for /l %%i in (0,1,MAP_HEIGHT) do (
for /l %%j in (0,1,MAP_WIDTH) do (
set "map[%%i][%%j]= "
)
)
set player_x=2
set player_y=7
set pipe_offset=0
create_pipes()
:game_loop
//read key
//read_key(3, "no_key", out key)
//if(%key% == Spacebar)
// //jump
// set_cell(%player_x%, %player_y%, " ")
// set /a player_y-=2
// draw_player()
//end if
//gravity
get_cell(%player_x%, calc{%player_y%+1}, out pc_val)
if("%pc_val%" == " " && %player_y% < calc{MAP_HEIGHT-1})
set_cell(%player_x%, %player_y%, " ")
set /a player_y+=1
end if
draw_player()
for /l %%i in (1,1,4) do (
create_pipe(calc{10*%%i-$pipe_offset}, $pipe%%i_val, " ")
create_pipe(calc{10*%%i-$pipe_offset-1}, $pipe%%i_val, "█")
)
set /a pipe_offset+=1
//redraw map
cls
draw_map()
goto game_loop