Collision system added, cam needs work

This commit is contained in:
Alan Youngblood 2022-08-11 22:05:07 -04:00
parent a13bd9a932
commit 0282c21b18

View File

@ -31,6 +31,7 @@ end
--<<<=======init========>>> --<<<=======init========>>>
function _init() function _init()
_init_rain() _init_rain()
make_player()
sx = 0 sy = 13 sx = 0 sy = 13
px = 28 py = 28 px = 28 py = 28
sun = {} sun = {}
@ -61,14 +62,21 @@ function _init()
confirm_trigger=false confirm_trigger=false
cancel_trigger=false cancel_trigger=false
camx=0
camy=0
end end
--<<<=====update======>>> --<<<=====update======>>>
function _update() function _update()
camx = peek2(0x5f28)
camy = peek2(0x5f2a)
if (crossbar==false) then if (crossbar==false) then
if (btn(0)) then plyr.x=plyr.x-1 plyani.f1=34 plyani.f2=35 plyr.flp=true plyr.ymov=false end --⬅️ move_player()
if (btn(1)) then plyr.x=plyr.x+1 plyani.f1=34 plyani.f2=35 plyr.flp=false plyr.ymov=false end --➡️ --if (btn(0)) then plyr.x=plyr.x-1 plyani.f1=34 plyani.f2=35 plyr.flp=true plyr.ymov=false end --⬅️
if (btn(2)) then plyr.y=plyr.y-1 plyani.f1=36 plyani.f2=36 plyr.flp=false plyr.ymov=true end --⬆️ --if (btn(1)) then plyr.x=plyr.x+1 plyani.f1=34 plyani.f2=35 plyr.flp=false plyr.ymov=false end --➡️
if (btn(3)) then plyr.y=plyr.y+1 plyani.f1=33 plyani.f2=33 plyr.flp=false plyr.ymov=true end --⬇️ --if (btn(2)) then plyr.y=plyr.y-1 plyani.f1=36 plyani.f2=36 plyr.flp=false plyr.ymov=true end --⬆️
--if (btn(3)) then plyr.y=plyr.y+1 plyani.f1=33 plyani.f2=33 plyr.flp=false plyr.ymov=true end --⬇️
end end
if crossbar then if crossbar then
if (crossbarnum==0) then if (crossbarnum==0) then
@ -107,6 +115,8 @@ end
function _draw() function _draw()
cls() cls()
pal() pal()
--center camera on player
camera_follow()
--do the shaking --do the shaking
doshake() doshake()
--sky --sky
@ -116,7 +126,10 @@ function _draw()
--map --map
rectfill(0,17,64,64,4) rectfill(0,17,64,64,4)
map(0,0,0,12,33,18) map(0,0,0,12,33,18)
spr(plyr.sprt,plyr.x,plyr.y,1,1,plyr.flp) --player
spr(p.sprt,p.x,p.y)
-- spr(plyr.sprt,plyr.x,plyr.y,1,1,plyr.flp)
--celestial bodies
sun.tmr = sun.tmr+1 sun.tmr = sun.tmr+1
if sun.tmr>=320 then --64 if sun.tmr>=320 then --64
sun.x = 0 sun.x = 0
@ -193,6 +206,8 @@ function _draw()
line(21,2,30,2,8) line(21,2,30,2,8)
spr(50,32,0) spr(50,32,0)
line(37,2,46,2,12) line(37,2,46,2,12)
print(camx,48,0,10)
print(camy,56,0,11)
end end
function doshake() function doshake()
@ -267,6 +282,113 @@ function _draw_rain()
end end
end end
end end
-->8
--player functions
function make_player()
p={}
p.x=28
p.y=28
p.dx=0
p.dy=0
p.w=7
p.h=7
p.sprt=32
end
function move_player()
if (btn(⬅️)) p.dx-=1
if (btn(➡️)) p.dx+=1
if (btn(⬆️)) p.dy-=1
if (btn(⬇️)) p.dy+=1
if (can_move(p.x+p.dx,p.y,p.w,p.h)) then
p.x+=p.dx
end
if (can_move(p.x,p.y+p.dy,p.w,p.h)) then
p.y+=p.dy
end
p.dx,p.dy=0,0
end
-->8
--collision functions
function can_move(x,y,w,h)
if (solid(x,y-12)) return false
if (solid(x+w,y-12)) return false
if (solid(x,y+h-12)) return false
if (solid(x+w,y+h-12)) return false
return true
end
function solid(x,y)
local map_x=flr(x/8)
local map_y=flr(y/8)
local map_sprite=mget(map_x,map_y)
local flag=fget(map_sprite)
return flag==1
end
-->8
--camera follow functions
--this function will move the
--camera to always put the
--player at the center.
function camera_follow()
--the camera shows 128 pixels
--across and 128 pixels down.
--by default, the pixels it
--shows start at coordinate
--0,0 and go to 127,127. this
--is why pixel coordinate 8,4
--would also show up the screen
--at coordinate 8,4.
--you can change which block of
--pixels are shown with the
--camera() function. by giving
--the camera() function a new
--x,y coordinate, you can
--tell the camera to start
--drawing from that new
--coordinate instead. if you
--used camera(100,100) then the
--camera would draw the pixel
--at 100,100 to the screen
--coordinate 0,0. this means
--that pset(108,104,1) would
--draw a pixel at screen
--coordinate 8,4.
--since the camera position is
--where the top-left corner of
--the screen is, if we want to
--keep the player in the middle
--of the screen, we need to
--set the camera's x,y to the
--player's x,y minus 60.
cam_x=p.x-28
cam_y=p.y-28
--if the player is on the
--edge of the map, keeping
--player centered means you'll
--see past the edge of the map.
--we can use the mid() function
--to make sure the camera
--position can't move past
--coordinates that would show
--past the edge of the map.
cam_x=mid(0,cam_x,896)
cam_y=mid(0,cam_y,128)
--change the camera position
camera(cam_x,cam_y)
end
__gfx__ __gfx__
65566600000003b0004400000007000070000070000c000000007a9000007770000800000666650077777777000880000011110000007000000a900000006d00 65566600000003b0004400000007000070000070000c000000007a9000007770000800000666650077777777000880000011110000007000000a900000006d00
6666656000003b3004ff4440000700000700070000c6c0000007a9000007777700088008000056d0711111110888888001999910000766000a0000900006d000 6666656000003b3004ff4440000700000700070000c6c0000007a9000007777700088008000056d0711111110888888001999910000766000a0000900006d000
@ -297,11 +419,14 @@ __gfx__
0aaa00008ee200000c6c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0aaa00008ee200000c6c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00a0000088820000cc6c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00a0000088820000cc6c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0a000000082000000cc0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0a000000082000000cc0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
__gff__
0000000000000000000000000000000000000000000000000000000000010000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
__map__ __map__
1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d262626262600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d262626262600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1d25252525252525252525252525252525252525252525252525252525262626262600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 1d25252525252525252525252525252525252525252525252525252525262626262600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1d25252525252525252525252525252525252525252525252525252525262626262600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 1d25252525252525252525252525252525252525252525252525252525262626262600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1d25252529292929292925252525292925252525252525252525252525262626262600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 1d25252629292929292925252525292925252525252525252525252525262626262600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1d25252929292929292929252529292925252525252525252525252525262626262600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 1d25252929292929292929252529292925252525252525252525252525262626262600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1d25252929292929292929292929292525252525252529292525252525262626262600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 1d25252929292929292929292929292525252525252529292525252525262626262600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1d25252529292929292929292929252525252525252929292925252525262626262600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 1d25252529292929292929292929252525252525252929292925252525262626262600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000