Creating and Destroying ememies. [ANSWERED]
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- WolfNinja2
- Party member
- Posts: 150
- Joined: Wed Oct 24, 2012 10:10 pm
Creating and Destroying ememies. [ANSWERED]
Hey this seems like a big request, but can anyone give me a semi-beginner tutorial on creating enimies and detecting if a hitbox between a bullet or player intersects a enemies hit box. Thanks! I have posted what I have so far.
- Attachments
-
- Galactica-type game.love
- (2.18 KiB) Downloaded 90 times
Last edited by WolfNinja2 on Fri Jul 19, 2013 1:09 am, edited 1 time in total.
-
- Prole
- Posts: 3
- Joined: Wed Jul 17, 2013 9:30 am
Re: Creating and Destroying ememies.
I haven't checked the code out yet (because it's telling me it's an invalid zip file, or it's just my computer stuffing up) but for your creating enemies question, you could just create a table that stores no. of enemies in that table. I'm pretty inexperienced, so better people can correct me if I'm wrong.
indention might be wrong and whatnot, but this code tells it to create a table called "enemies", with 7 tables inside it called "enemy" that have the width, height, x-pos and y-pos. For your question about bullets and it colliding with enemies, it has something to do with the CheckCollision() function.
There have been a lot of questions asked about CheckCollision and how it works so just search those up.
I can't get the link right now but search up in google: Love2d pew pew and click on the first link, it'll show you a pretty rough tutorial on making a space-invaders esque game.
Code: Select all
enemies = {}
for i = 1, 7 do
enemy = {}
enemy.width = 30
enemy.height = 10
enemy.x = i*100
enemy.y = enemy.height + 50
table.insert(enemies, enemy)
end
indention might be wrong and whatnot, but this code tells it to create a table called "enemies", with 7 tables inside it called "enemy" that have the width, height, x-pos and y-pos. For your question about bullets and it colliding with enemies, it has something to do with the CheckCollision() function.
Code: Select all
function CheckCollision(ax1, ay1, aw, ah, bx1, by1, bw, bh)
local ax2,ay2,bx2,by2 = ax1 + aw, ay1 + ah, bx1 + bw, by1 + bh
return ax1 < bx2 and ax2 > bx1 and ay1 < by2 and ay2 > by1
end
There have been a lot of questions asked about CheckCollision and how it works so just search those up.
I can't get the link right now but search up in google: Love2d pew pew and click on the first link, it'll show you a pretty rough tutorial on making a space-invaders esque game.
I'm a slow learner, don't get mad if I don't get it after the 25th time :/
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest