Log In  

Cart #cratesncrushers-1 | 2021-09-07 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
11

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.

P#66704 2019-08-15 20:27 ( Edited 2021-09-07 19:35)

Nice work!
I wonder how you handle the collision between sprites. Could you give me some hints please?

P#69359 2019-10-27 15:13
:: st33d
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.

P#69442 2019-10-29 08:21

Thank you for your explanation! Really helpful.

P#69521 2019-10-31 14:01

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2021-09-16 16:31:28 | 0.018s | Q:20