Code: Select all
#-----------------------------------------------------------------------
define constant(1, timer:camera)
#-----------------------------------------------------------------------
plotscript, on new game, begin
init game
end
#-----------------------------------------------------------------------
script, init game, begin
set hero speed(me, 6)
camera handler
end
script, camera handler, begin
variable(x, y, sx, sy)
x := (hero pixel x(me) + 10) / 20
y := (hero pixel y(me) + 10) / 20
sx := x ,mod, 16
sy := y ,mod, 10
if(sx == 0) then(scrolling action(-1, 0))
elseif(sx == 15) then(scrolling action(1, 0))
elseif(sy == 0) then(scrolling action(0, -1))
elseif(sy == 9) then(scrolling action(0, 1))
put camera on screen by tile(hero x(me), hero y(me))
set timer(timer:camera, 0, 1, @camera handler)
end
script, scrolling action, xgo, ygo, begin
suspend player
cancel hero walk(me)
wait for hero(me)
pan camera screenwise(xgo, ygo)
walk hero relative(me, xgo * 2, ygo * 2)
wait for camera
wait for hero(me)
resume player
end
script, walk hero relative, rank, xgo, ygo, begin
if(xgo < 0) then(walk hero(rank, left, abs(xgo)))
if(xgo > 0) then(walk hero(rank, right, abs(xgo)))
if(ygo < 0) then(walk hero(rank, up, abs(ygo)))
if(ygo > 0) then(walk hero(rank, down, abs(ygo)))
end
script, pan camera screenwise, xgo, ygo, begin
# Pan the camera one screen in the given direction
if(xgo < 0) then(pan camera(left, 16, 10))
if(xgo > 0) then(pan camera(right, 16, 10))
if(ygo < 0) then(pan camera(up, 10, 10))
if(ygo > 0) then(pan camera(down, 10, 10))
end
script, put camera on screen by tile, tx, ty, begin
# Set the camera so that the selected tile coordinates will be on-screen
put camera(tx / 16 * 16 * 20, ty / 10 * 10 * 20)
end
Yes, this was inspired by playing Xoo Xeno Xafari, which I believe uses a whole bunch of 16x16 maps connected with regular doors-- but it just got me thinking, how would you script this if you wanted to make it a single map?