I work on a fangame and one part of the game is a shooting game.
I searched a lot for use guns and bullet and I found this : http://love2d.org/wiki/Tutorial:Fire_Toward_Mouse
So i make this class for my game and I post it here for other who want to use this.
It's open-source (under the MIT license) and you can include it in your game,of course !Just put the shoot.lua in your project folder and use a "require 'shoot'"
In attachments,the .love file with a demo.
How to use-it ?
It is very simple.
Step 1\ Add the class in your game
Code: Select all
require 'shoot'
The default speed is 150,you can increment the value by 100 for more speed.
In the demo,the Xpos and Y pos is the center of the screen,and the speed is 250.
Code: Select all
war = shoot.init(xpos,ypos,speed)
Code: Select all
war.changeSprite(image)
Call this function with the path of the image.
If you call without arguments of the image can't be loaded,the bullet is by default a circle.
Step 3.1\Change the color
Code: Select all
war.changeColor(r,g,b)
Step 4\Change the position
Code: Select all
war.changePos(x,y)
Step 5\Make it fire
Code: Select all
war.fire(targetX,targetY)
Step 6\Display all
Code: Select all
function love.draw()
war.draw()
end
function love.update(dt)
war.update(dt)
end
You can read the code of the demo if you want more !
I hobe that you'll like it.
I you found a bug,reply in this post !