Obstacles

Obstacles define certain rectangular boundaries.
Walls define areas where the map height is raised.
It is important to know how locations are handled. The upper left corner of the map is position (0,0). It increments per-pixel of the map file, so the lower right corner is (384,480).

(common.lua)
The different types of obstacles are:

OBSTACLE_UNWALKABLE = 1
OBSTACLE_BULLETPROOF = 2
OBSTACLE_SLIP = 4
OBSTACLE_SLOW = 8
OBSTACLE_EXIT = 16

Obstacles are defined within the stage_OnStart() function with createObstacle()
A run down of its parameters is as follows:

createObstacle(x,y,wid,hei,value)

  • x,y - the upper left pixel that begins the bounding box
  • wid - the number of pixels it will span to the right
  • hei - how many pixels downwards the box reaches
  • value - the obstacle type: you may enter the word or corresponding number

createWall() works much the same, although for walls the value will increment the map height on a 1-to-1 basis. They also ramp down in the front, as described in

(common.lua)
function createWall(x,y,wid,hei,value)
local i=0
local z=0
for i=value,0,-1 do
setMapHeight(x,y+z,wid,hei,i)
z=z+1
end
end

So there's an object in your map you don't want people walking over like it's not there?
bg14.png
We will use this map as an example.
There is a huge break in the bridge, and were people to levitate over it would seem suspicious.
We want to make this area unwalkable.
Loading the image in our convenient image editor we find the pixel we want to grow our obstacle from.
I'm looking at (160,140) to be the upper-left corner. Dragging a box from there to where I feel it ends, I find my selection is 64 by 67 pixels. I'm ready to declare the obstacle.

createObstacle(160,140,64,67,OBSTACLE_UNWALKABLE)

I'm rather confident were I to load this it would appear to be working nicely.
However, when I approach the obstacle from above or the sides, it looks a bit funny.
Our hitbox is the thing being denied movement, so when i walk close to it my feet enter the area. You could counteract this by growing the field out, but there is an easier way.

(common.lua)
function createWall2(x,y,wid,hei,value)
createWall(x,y,wid,hei,value)
createObstacle(x-4,y-11,wid+8,hei+value+11,OBSTACLE_UNWALKABLE)
end

function createObstacle2(x,y,wid,hei,value)
createObstacle(x-4,y-11,wid+8,hei+11,value)
end

createObstacle2() will expand the bounding box four pixels on either side, and 11 pixels upwards.
createWall2() calls createWall(), while making an unwalkable obstacle in the same proportions.

  • OBSTACLE_EXIT, this is the field where you will leave the stage. Signify its location with setExitMarker(x,y)
  • OBSTACLE_BULLETPROOF probably allows movement but not projectiles, maybe
  • OBSTACLE_SLIP sounds annoying
  • OBSTACLE_SLOW doesn't sound much better
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.