Created
August 16, 2024 03:20
-
-
Save turnipsoup/e36a232ec90535612e5dd94ae1f48104 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
pl = { | |
sp_size=16,x=100,y=100,anim=false,sp=48, | |
fall=false,jump=false,jumping=false, | |
speed=1,gspeed=2,jspeed=1,jtick=8, | |
upblock=false,lblock=false,rblock=false | |
} | |
function pl:draw_player() | |
if not pl.anim then | |
spr(48,pl.x,pl.y) | |
end | |
end | |
function pl:detect_col() | |
-- Down | |
if fget(mget(flr(self.x/pl.sp_size),flr((self.y+pl.sp_size)/pl.sp_size))) == 128 then | |
self.fall = false | |
self.jump = false | |
self.y = flr(self.y / pl.sp_size) * pl.sp_size | |
elseif fget(mget(flr((self.x+pl.sp_size-1)/pl.sp_size),flr((self.y+pl.sp_size)/pl.sp_size))) == 128 then | |
self.fall = false | |
self.jump = false | |
self.y = flr(self.y / pl.sp_size) * pl.sp_size | |
else | |
self.fall = true | |
end | |
-- Up | |
if fget(mget(flr(self.x/pl.sp_size),flr(self.y/pl.sp_size))) == 128 then | |
self.upblock = true | |
self.y = flr((self.y+pl.sp_size) / pl.sp_size) * pl.sp_size | |
elseif fget(mget(flr(self.x+pl.sp_size-1/pl.sp_size),flr(self.y/pl.sp_size))) == 128 then | |
self.upblock = true | |
self.y = flr((self.y+pl.sp_size) / pl.sp_size) * pl.sp_size | |
else | |
self.upblock = false | |
end | |
-- Left | |
if fget(mget(flr((self.x-1)/pl.sp_size),flr(self.y/pl.sp_size))) == 128 then | |
self.lblock = true | |
self.x = flr(self.x / pl.sp_size) * pl.sp_size | |
elseif fget(mget(flr((self.x-1)/pl.sp_size),flr((self.y+pl.sp_size-1)/pl.sp_size))) == 128 then | |
self.lblock = true | |
self.x = flr(self.x / pl.sp_size) * pl.sp_size | |
else | |
self.lblock = false | |
end | |
-- Right | |
if fget(mget(flr((self.x+pl.sp_size)/pl.sp_size),flr(self.y/pl.sp_size))) == 128 then | |
self.rblock = true | |
self.x = flr(self.x / pl.sp_size) * pl.sp_size | |
elseif fget(mget(flr((self.x+pl.sp_size)/pl.sp_size),flr((self.y+pl.sp_size-1)/pl.sp_size))) == 128 then | |
self.rblock = true | |
self.x = flr(self.x / pl.sp_size) * pl.sp_size | |
else | |
self.rblock = false | |
end | |
end | |
function pl:gravity() | |
if self.fall and not self.jumping then | |
self.y += self.gspeed | |
end | |
end | |
function pl:handle_move() | |
if btn(0) and not self.lblock then | |
self.x -= self.speed | |
self.fh = true | |
end | |
if btn(1) and not self.rblock then | |
self.x += self.speed | |
self.fh = false | |
end | |
end | |
function pl:handle_jump() | |
if btnp(2) and not self.upblock and not self.jump then | |
self.jump = true | |
self.jumping = true | |
self.jtick = 8 | |
end | |
if self.jtick > 0 and not self.upblock then | |
self.y -= self.jspeed | |
end | |
if self.jtick > 0 then | |
self.jtick -= 1 | |
end | |
if self.jtick <= 0 then | |
self.jtick = 0 | |
self.jumping = false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment