add levers, draw cursor coordinates

This commit is contained in:
Colin McMillen 2021-06-10 19:02:14 -04:00
parent 7c5e784116
commit c92508544f

View File

@ -44,14 +44,18 @@ function init_world()
drops = {} drops = {}
ramps = {} ramps = {}
levers = {}
add_ramp(50,20,15,10) add_ramp(50,20,15,10)
add_ramp(60,50,15,-15) add_ramp(60,50,15,-15)
add_ramp(48,60,20,0) add_ramp(52,60,14,0)
add_ramp(45,75,10,30) add_ramp(45,75,10,30)
add_ramp(65,76,0,10) add_ramp(64,76,0,10)
add_ramp(65,86,5,0) add_ramp(64,86,6,0)
add_ramp(70,76,0,10) add_ramp(70,76,0,10)
add_lever(30,30,20)
end end
function add_ramp(x,y,dx,dy) function add_ramp(x,y,dx,dy)
@ -63,9 +67,19 @@ function add_ramp(x,y,dx,dy)
add(ramps, r) add(ramps, r)
end end
function add_lever(x,y,len)
l = {}
l.x = x
l.y = y
l.len = len
l.angle = 0
add(levers, l)
end
function _update() function _update()
update_player() update_player()
update_drops() update_drops()
update_levers()
end end
function update_player() function update_player()
@ -94,6 +108,14 @@ function update_player()
end end
end end
function update_lever(l)
l.angle += 0.001
end
function update_levers()
foreach(levers, update_lever)
end
function update_drop(d) function update_drop(d)
if d.y == 127 or pget(d.x,d.y+1) == bg then if d.y == 127 or pget(d.x,d.y+1) == bg then
d.y += 1 d.y += 1
@ -135,21 +157,30 @@ end
function _draw() function _draw()
draw_world() draw_world()
spr(player.spr,player.x-1,player.y-1) spr(player.spr,player.x-1,player.y-1)
print("drops: "..#drops, 1, 6, white) print("("..player.x..","..player.y..")", 1, 1, white)
print("drops: "..#drops, 1, 7, white)
end end
function draw_world() function draw_world()
cls(bg) cls(bg)
foreach(drops, draw_drop) foreach(drops, draw_drop)
foreach(ramps, draw_ramp) foreach(ramps, draw_ramp)
foreach(levers, draw_lever)
end
function draw_drop(drop)
pset(drop.x, drop.y, white)
end end
function draw_ramp(r) function draw_ramp(r)
line(r.x,r.y,r.x+r.dx,r.y+r.dy,brown) line(r.x,r.y,r.x+r.dx,r.y+r.dy,brown)
end end
function draw_drop(drop) function draw_lever(l)
pset(drop.x, drop.y, white) dx = l.len * cos(l.angle)
dy = l.len * sin(l.angle)
line(l.x,l.y,l.x+dx,l.y+dy,brown)
rectfill(l.x-1,l.y-1,l.x+1,l.y+1,black)
end end
__gfx__ __gfx__