I have some randomly sized rectangles that I need to get the width and length of to determine if there's a collision to do.
Here is my enemy_load() function
Code: Select all
enemy = {}
enemy.x1=0
enemy.x2=love.graphics.getWidth()
enemy.y1=0
enemy.y2=love.graphics.getHeight()
enemy.minSize1=15
enemy.minSize2=enemy.minSize1*2
enemy.maxSize1=30
enemy.maxSize2=enemy.maxSize1*2
enemy.initspeed=20
enemy.timer_init=1
enemy.timer=enemy.timer_init
function enemy_spawn(x,y,width,height,speed,r,g,b)
table.insert(enemy, {x=x,y=y,width=width,height=height,speed=speed,r=r,g=g,b=b})
end
When A timer comes up, this runs:
Code: Select all
enemy_spawn(math.random(e.x1,e.x2),math.random(e.y1,e.y2),math.random(e.minSize1,e.minSize2),math.random( e.maxSize1,e.maxSize2),enemy.initspeed,math.random(0,255),math.random(0,255),math.random(0,255))
Code: Select all
for i,v in ipairs(enemy) do
for bi,bv in ipairs(bullet) do
if bv.x > v.x+v.width or bv.x < bv.width-bv.w or bv.y < v.y+v.height or bv.y > v.height-v.height then
end
end
I'm probably missing something obvious!
I should warn that my code is a warzone of uncommented, unorganized scrap. I'm simply doing a crummy game to learn things for better things. Hopefully that doesn't stop one of you smart people from helping me out!
Cheers!
Edit: I commeted out my bugged collision code. Here is a version of the game that's "playable." You should see what's up. Right now 1,2 and 3 change the RGB colors of the character and the bullets it fires. The goal is that you have to get your RGB colors close to the enemy's RGB colors(which are completely random at spawn) and it will kill them/make them lose health.
Also the border has a threshold like that already, if your RGBs are more than 40 units away, it will make the walls grow, if you're within 40, it'll make them grow. Still have to polish how it works, but right now it's just testing an idea I have.
Doesn't really play well but it's the best I've done so far.