I have a part in my game...Um i'll try to describe it..Imagine pong. But replace the two pongs with people that shoot at eachother! I have everything done exept how to shoot. I want the bullets to move at a slow speed, and when they make contact with the enemy the other player will earn a point. So really i just wanna know how to make a bullet(i already have a picture of a bullet soo..)
i WANT TO KNOW how to make a picture move slowly across the screen. And how to detect that it has contacted another image.!:D
Bullets!
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- baconhawka7x
- Party member
- Posts: 491
- Joined: Mon Nov 21, 2011 7:05 am
- Location: Oregon, USA
- Contact:
- Jasoco
- Inner party member
- Posts: 3725
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Bullets!
Other people will be along shortly to elaborate, but I'll give you a gist..
A bullet is basically a table index. Like so:
Where bullet_id would be the unique index in the bullet table of the current bullet.
You would move the bullet each frame like so:
Where DT is the Delta Time. i.e. how many milliseconds the current frame is from the previous frame. You probably know about DT, and know that it is passed to love.update anyway. If you don't understand DT, read up on it in the Wiki.
Where the For loop runs through every bullet in the bullet table.
In this scenario the bullet moves to the right. If you wanted to make it so bullets only move left or right you would use negative b.speed for left. (b.speed = -300) It gets more complex if you want to make bullets that can move at other angles than 90º/180º.
Now, as for collisions. It depends on the type of collision you need. Rectangular, circular, more complex. The basic gist is to check that the bullet x and y are within the object. Now, you could also give the bullet a radius or size if you wish.
You'd have to figure out which type of collision you need first.
Oh, and the important part is to destroy the bullet when it either collides or goes too far off screen to prevent slowdown. For instance:
A bullet is basically a table index. Like so:
Code: Select all
bullet[bullet_id] = {
x = 0,
y = 200,
speed = 300 --Pixels per frame to move at
}
You would move the bullet each frame like so:
Code: Select all
for i, b in pairs(bullet) do
b.x = b.x + b.speed * dt
end
Where the For loop runs through every bullet in the bullet table.
In this scenario the bullet moves to the right. If you wanted to make it so bullets only move left or right you would use negative b.speed for left. (b.speed = -300) It gets more complex if you want to make bullets that can move at other angles than 90º/180º.
Now, as for collisions. It depends on the type of collision you need. Rectangular, circular, more complex. The basic gist is to check that the bullet x and y are within the object. Now, you could also give the bullet a radius or size if you wish.
You'd have to figure out which type of collision you need first.
Oh, and the important part is to destroy the bullet when it either collides or goes too far off screen to prevent slowdown. For instance:
Code: Select all
bullet[bullet_id] = nil
- baconhawka7x
- Party member
- Posts: 491
- Joined: Mon Nov 21, 2011 7:05 am
- Location: Oregon, USA
- Contact:
Re: Bullets!
thank you i just have a quick question. Where would i put the table index?
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Bullets!
Help us help you: attach a .love.
- Jasoco
- Inner party member
- Posts: 3725
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Bullets!
More specifically in the function you call when you want to begin the game. Then destroy the whole thing when you end the game to free up memory.
Who is online
Users browsing this forum: Ahrefs [Bot] and 208 guests