[class] Shoot class
Posted: Mon Oct 23, 2017 9:03 am
Hello world !
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
Step 2\ Initialize the class.In the first and the second argument,set the position of the gun and in the third argument,the speed.
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.
Step 3\Change the sprite of the bullet
By default,the sprite of the bullet is a circle.You can change the bullet with an 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
If the bullet isn't an image,you can change the color of the circle with this function
Step 4\Change the position
The player isn't motionless ! If he change position,call this function with position of the player in argument.
Step 5\Make it fire
Make a bullet and set the target with position given in arguments.
Step 6\Display all
Call draw function for display bullets and update (don't miss the dt argument) for update position of the bullet.
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 !
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 !