-- game loop
function _init()
gamestart()
_upd=update_game()
_drw=draw_game()
end
function _update()
frm+=1
_upd()
end
function _draw()
_drw()
end
function gamestart()
frm=1
col=false
----------------
--menus
----------------
men_main={
items={"start game","controls"},
menx=10,
meny=10,
curx=2,
cury=10,
menoff=7
}
----------------
--player
----------------
p={
sp=1,
x=48,
xo=0,
y=40,
yo=0,
w=8,
h=8,
ymt=0,
spd=1,
flp=false,
dx=0,
dy=0,
--gravity/collision stuff
hbx1=1,
hbx2=6,
hby1=7,
hby2=1,
grv=0.2,
acc=0.5,
landed=false,
jumping=false,
running=false,
falling=false,
dashing=false,
rolling=false,
attacking=false,
itemgrab=false,
--animation (in sprite #)
frame=0,
anim_idle=1,
anim_walk={1,2,3,4},
anim_jf=5,
anim_atk={1,4,6},
anim_dashing=8,
anim_rolling={9,10,11,9},
anim_attacking=6,
anim_itemgrab=7,
--game stats
mhp=10,
chp=10,
atk=1,
def=1,
agi=1.1,--1.1 beacuse fucking math
}
inv={}
abilities={}
----------------
--tiles
----------------
--collision
t={--x1=l x2=r y1=t y2=b
wall={x1=4,x2=6,y1=0,y2=7},
floor={x1=0,x2=7,y1=4,y2=7}
}
end
-->8
-- updates
function update_game()
--player---------------------
-----------------------------
p.frame+=1
if p.frame==5 then
p.frame=1
end
if (btn(⬅️)) then
p.dx=-1
p.flp=true
p.running=true
elseif (btn(➡️)) then
p.dx=1
p.flp=false
p.running=true
else
p.dx=0
p.running=false
end
--collisions & gravity
local ly=p.y
p.dy+=p.grv
--check collision left and right
if p.dx<0 then
if collide_map(p,"left",0) then
p.dx=0
end
elseif p.dx>0 then
if collide_map(p,"right",0) then
p.dx=0
end
end
--jump
if btnp(⬆️)
and p.landed then
p.dy-=2
p.landed=false
end
--check collision up and down
if p.dy>0 then
p.falling=true
p.landed=false
p.jumping=false
if collide_map(p,"down",0) then
p.landed=true
p.falling=false
p.dy=0
p.y-=((p.y+p.h+1)%8)-1
end
elseif p.dy<0 then
p.jumping=true
if collide_map(p,"up",0) then
p.dy=0
end
end
p.x+=p.dx
p.y+=p.dy
--animation
if p.jumping or p.falling then
p.sp=p.anim_jf
elseif p.running then
if frm%5<=4 then
p.sp=p.anim_walk[p.frame]
end
elseif p.attacking then
p.sp=p.anim_attack
else --player idle
p.sp=1
end
end
function update_mm()
upd_menu(men_main)
end
-->8
-- draws
function draw_game()
cls()
map()
spr(p.sp,p.x,p.y,1,1,p.flp)
camera(p.x-60,p.y-60)
print(p.dx,1+p.x-59,1+p.y-59,8)
print(p.dy,9+p.x-59,1+p.y-59,8)
end
function draw_mm()
cls()
menutext(men_main.items,men_main.menx,men_main.meny,8)
drw_menucur(men_main)
end
-->8
--functions
function does_tile(flag,x,y) -- bool
tile=mget(x,y)
has_flag=fget(tile,flag)
return has_flag
end
function collide_map(obj,aim,flag)
--obj = table needs x,y,w,h
--aim = left,right,up,down
local x=obj.x local y=obj.y
local w=obj.w local h=obj.h
local x1=0 local y1=0
local x2=0 local y2=0
if aim=="left" then
x1=x-1 y1=y
x2=x y2=y+h-1
elseif aim=="right" then
x1=x+w-1 y1=y
x2=x+w y2=y+h-1
elseif aim=="up" then
x1=x+2 y1=y-1
x2=x+w-3 y2=y
elseif aim=="down" then
x1=x+2 y1=y+h
x2=x+w-3 y2=y+h
end
--pixels to tiles
x1/=8 y1/=8
x2/=8 y2/=8
if fget(mget(x1,y1), flag)
or fget(mget(x1,y2), flag)
or fget(mget(x2,y1), flag)
or fget(mget(x2,y2), flag) then
return true
else
return false
end
end
-->8
--menu
function startmenu(menutable)
end
function menutext(menutable,x,y,off)
for i=1, #menutable do
print(menutable[i],x,y+menutable.off*i)
end
end
function drw_menucur(menutable)
local x1 = menutable.curx-8
local y1 = menutable.cury-10
local x2 = x1+12
local y2 = y1+6
rectfill(x1,y1,x2,y2,7)
end
function upd_menu(menutable)
if btnp(⬆️) then
menutable.cury-=7
end
if btnp(⬇️) then
menutable.cury+=7
end
-- if btnp(❎) then menuacc(menutable)
-- if btnp(🅾️) then menuden(menutable)
end