Version 0.2
Pros
- Ledges (top only).
- Moving platforms.
- Crates that can push crates on moving platforms whilst you stand on top.
- Reads the map as level geometry.
- The above features can be removed to retrieve tokens.
- Can probably be optimised.
Cons
- No slopes.
- 2618 tokens (the raw engine is 1711 but you still need to make a player, enemies, update, etc).
- First come, first served resolution: You only get 1 collision contact (you have to be creative to get more).
Updates
Updated this page and rewrote the engine to use less tokens and be more extendable. Only saved 252 tokens sadly but every little helps.
Nice work!
I wonder how you handle the collision between sprites. Could you give me some hints please?
1
This block of code looks at a part of the map and returns it as a list of objects with an x,y position and a w,h size. It also returns the sprite id. These are treated like the other rectangles you collide with.
--return a table of objects describing tiles on the map --ignore: do not return anything with this flag --result: a table of results to add to function mapobjects(x,y,w,h,ignore,result) result,ignore = result or {},ignore or 0 local xmin, ymin = flr(x/8),flr(y/8) -- have to deduct a tiny amount, or we end up looking at a neighbour local xmax, ymax = flr((x+w-0.0001)/8),flr((y+h-0.0001)/8) local rxmin,rymin,rxmax,rymax = blokmap.x,blokmap.y,blokmap.x+blokmap.w-1,blokmap.y+blokmap.h-1 for c=xmin,xmax do for r=ymin,ymax do --bounds check if c<rxmin or r<rymin or c>rxmax or r>rymax then add(result, {x=c*8,y=r*8,w=8,h=8,flag=f_outside,sp=0}) else local sp=mget(c,r) local f = fget(sp) if f > 0 and band(f, ignore) == 0 then add(result, {x=c*8,y=r*8,w=8,h=8,flag=f,sp=sp}) end end end end return result end |
So, there is no collision between sprites. There is only collision between rectangles, and the map is scanned for implicit rectangles to collide with. The sprites are all drawn afterwards.
[Please log in to post a comment]