Log In  
Follow
lil_blizzard
[ :: Read More :: ]

Cart #twinbeeclone-0 | 2019-05-21 | Code ▽ | Embed ▽ | No License

Beginner here, so forgive me if I'm missing something obvious. I'm currently working on a simple clone of Twin Bee to learn a little bit about design. I'm running into a blockade due to my lack of programming experience, so I'm hoping someone may have some answers from me.

I've got clouds that fall from the top of the screen. The function that sets all the variables for the cloud table looks like this:

function spawncloud()
 local c = {
  x = rnd(95)+16,
  y = -16,
  dy = rnd(.5)+.75,
  sp = 5,
  hb = {x1=0,y1=0,x2=13,y2=1}
 }
 -- bell properties - is it necessary for me to declare
 -- these properties within the spawncloud function
 -- because the bell position depends on the cloud position? 
 local b = {
  x=c.x,
  y=c.y,
  boost=3,
  dy=0,
  sp=7,
  hb={x1=0,y1=0,x2=3,y2=3}
 }
 --add to cloud table
 add(clouds,c)
 --add to bell table
 add(bells, b)
end

The cloud spawn perfectly when I iterate through the cloud array in the _draw() function.

My next objective is spawning a bell when my bullet hit's one of these clouds. As you can see in the spawncloud() function above, I'm setting up a local table for the bells as well, because their x&y variables are dependent on those of the cloud. I would like to have an entirely separate spawnbell() function so I can call it when necessary, but I'm not quite sure how I would go about this because of the dependent x&y variables.

Additionally, my collision seems to be working about 75% of the time, so any help with making that more consistent would be greatly appreciated. I've borrowed the code from another project, so I'm not 100% clear on what it's doing. Here's what that code looks like:

--creating a box collider
function abs_box(s)
 local box = {}
 box.x1 = s.hb.x1 + s.x
 box.y1 = s.hb.y1 + s.y
 box.x2 = s.hb.x2 + s.x
 box.y2 = s.hb.y2 + s.y
 return box
end

--collision function
function coll(a,b)
 --create relative hitboxes
 local box_a = abs_box(a)
 local box_b = abs_box(b)

 if box_a.x1 > box_b.x2 or
    box_a.y1 > box_b.y2 or
    box_b.x1 > box_a.x2 or
    box_b.y1 > box_a.y2 then
    return false
  end
 return true
end

--check if our bullet is colliding
--with our cloud
function checkbulletcoll()
 for e in all(bullets) do
    for c in all(clouds) do
    if coll(e,c) then
    --delete bullet if collision
        del(bullets,e)
        end
    end
 end
end

Please let me know if there's additional code you'd like to see.
Thanks for the help!

P#64663 2019-05-22 00:06 ( Edited 2019-05-22 00:10)

Follow Lexaloffle:          
Generated 2024-03-28 18:28:35 | 0.066s | Q:9