I have started my first game in corona SDK and have covered a lot but now I’m stuck to a laser functionality for the weapons , have not much idea how can I implement this . any guidance please ? I want to throw laser on fire function which have collision effect other particles.Thanks in advance.
Share
Well that is a fairly broad question so I can only answer that on a high level. First off, look at my sample OOP framework for one way to do object oriented programming in Lua:
http://developer.anscamobile.com/code/object-oriented-sample-game-framework
Now whether you use this approach or some other technique to achieve OOP, what you want to do is create a Laser object and every time the player fires instantiate a Laser object at the weapon’s position. Then in the Laser’s constructor set an enterFrame listener that will move it forward a little bit every frame. By moving a little bit every frame, the laser will smoothly animate forward.
As for collision, if you are using physics in your game then you could make your lasers into physics objects to handle collisions that way. Alternatively, you can do a simple distance check with the laser against every enemy on screen; when the laser is close to an enemy that means the laser hit that enemy.