Log In  

If you all don't care again I need help with object pickups in my game when you pickup an object (artifact) you get a score of 1 point. What I need to know is how to add a spawner for that object and how to make the player pick it up.

Many thanks.

BTW I tried to use a YouTube tutorial with no luck

--pickups
function ipickups()
 pu={
 x=63,
 y=50,
 act=true,
 }
 artifacts=0
end

function upickups()
 if pu.act then
  if abs(px-pu.x)<=4 and abs(py-pu.y)<=4 then
   pu.act=false
 artifacts+=1
  end
 end
end

function dpickups()
 if pu.act then
  spr(6,pu.x,pu.y,4,4)
 end
 print("artifacts: "..artifacts)
end
P#147921 2024-05-04 19:17

So basically you want to have this code in init()

for x=0,15 do
 for y=0,15 do

   if mget(x,y)==Object_Sprite then
     Spawn_Object(x,y)
     mset(x,y,0)
   end

 end
end

The code checks each tile, and if its (for example ) a coin then it spawns a coin.
You also need to remove the tile, so you just place tile 0 there.
I hope that was you'r question, good luck :)

P#147922 2024-05-04 19:41

Also I recommend you this code as well:

function SpawnObj(x,y)

 add(objs,{
  x=x,
  y=y,
  sp=1,
  draw=function(o)
   spr(o.sp,o.x,o.y)
   if collision() then
    points+=1
    del(objs,o)
   end
  end
})

end

function _init()
 objs={}
end

function _draw()
 cls()

 for o in all(objs) do
  o:draw
 end
end

Thats the classic way to make objects in Pico-8.

P#147924 2024-05-04 19:48 ( Edited 2024-05-04 19:48)
P#147969 2024-05-05 22:29

[Please log in to post a comment]