erste programme
This commit is contained in:
122
cards/cave.p8
Normal file
122
cards/cave.p8
Normal file
@@ -0,0 +1,122 @@
|
||||
pico-8 cartridge // http://www.pico-8.com
|
||||
version 42
|
||||
__lua__
|
||||
function _init()
|
||||
game_over=false
|
||||
make_cave()
|
||||
make_player()
|
||||
end
|
||||
|
||||
function _update()
|
||||
if (not game_over) then
|
||||
update_cave()
|
||||
move_player()
|
||||
check_hit()
|
||||
else
|
||||
if (btnp(5)) _init()
|
||||
end
|
||||
end
|
||||
|
||||
function _draw()
|
||||
cls()
|
||||
draw_cave()
|
||||
draw_player()
|
||||
|
||||
if (game_over) then
|
||||
print("game over!",44,44,7)
|
||||
print("your scrore:"..player.score,34,54,7)
|
||||
print("press ❎ to play again!",18,72,6)
|
||||
else
|
||||
print("score:"..player.score,2,2,7)
|
||||
end
|
||||
end
|
||||
|
||||
-->8
|
||||
function make_player()
|
||||
player={}
|
||||
player.x=24
|
||||
player.y=60
|
||||
player.dy=0
|
||||
player.rise=1
|
||||
player.fall=2
|
||||
player.dead=3
|
||||
player.speed=2
|
||||
player.score=0
|
||||
end
|
||||
|
||||
function draw_player()
|
||||
sprite=1
|
||||
if (game_over) then
|
||||
sprite=player.dead
|
||||
elseif (player.dy<0) then
|
||||
sprite=player.rise
|
||||
else
|
||||
sprite=player.fall
|
||||
end
|
||||
spr(sprite,player.x,player.y)
|
||||
end
|
||||
|
||||
function move_player()
|
||||
gravity=0.2
|
||||
player.dy+=gravity
|
||||
if (btnp(⬆️)) then
|
||||
player.dy-=3
|
||||
sfx(0)
|
||||
end
|
||||
player.y+=player.dy
|
||||
player.score+=player.speed
|
||||
end
|
||||
|
||||
function check_hit()
|
||||
for i=player.x,player.x+7 do
|
||||
if (cave[i+1].top>player.y) or (cave[i+1].btm<player.y) then
|
||||
game_over=true
|
||||
sfx(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-->8
|
||||
function make_cave()
|
||||
cave={{["top"]=4,["btm"]=119}}
|
||||
top=45
|
||||
btm=85
|
||||
end
|
||||
|
||||
function update_cave()
|
||||
if(#cave>player.speed) then
|
||||
for i=1,player.speed do
|
||||
del(cave,cave[1])
|
||||
end
|
||||
end
|
||||
|
||||
while (#cave<128) do
|
||||
local col={}
|
||||
local up=flr(rnd(7)-3)
|
||||
local down=flr(rnd(7)-3)
|
||||
col.top=mid(3,cave[#cave].top+up,top)
|
||||
col.btm=mid(btm,cave[#cave].btm+down,124)
|
||||
add(cave,col)
|
||||
end
|
||||
end
|
||||
|
||||
function draw_cave()
|
||||
top_color=5
|
||||
btm_color=5
|
||||
for i=1,#cave do
|
||||
line(i-1,0,i-1,cave[i].top,top_color)
|
||||
line(i-1,127,i-1,cave[i].btm,btm_color)
|
||||
end
|
||||
end
|
||||
__gfx__
|
||||
0000000000aaaa0000aaaa0000888800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000aaaaaa00aaaaaa008888880000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00700700aa0aa0aaaa0aa0aa88888888000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00077000aaaaaaaaaaaaaaaa88988988000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00077000aaaaaaaaaaaaaaaa88888888000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00700700aa0000aaaaa00aaa88899888000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000aa00aa00aa00aa008988980000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000aaaa0000aaaa0000888800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
__sfx__
|
||||
000400001105012050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000a00002c05000000260501e0001f050070400704008040070300803008030070300801008010070100700000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
Reference in New Issue
Block a user