So what Im trying to do is have an enemy fire randomly, but when the bullet goes off screen to signal to the enemy and allow the enemy to fire again. Every instance of an Enemy can only have One active instance of Bullet at any time. So far I am simply testing the fire and refire implementation. The function shoot is called of the instance of Enemy like the following:
function enemy:shoot()
--Calls Bullet Obj file
local Bullet = require "Bullet";
--Movement time per space
local DEFAULTTIME = 5;
--checking if property, there currently is an active bullet instance in scene
if self.activeBul ==false then
--move the bullet
self.bullet:trajectBullet({x=self.sprite.x,y=display.contentHeight, time = DEFAULTTIME* (display.contentHeight-self.sprite.y)});
--there is now an active Bullet linked to this enemy
self.activeBul = true;
else
end
end
all that is happening for now in the trajectBullet is the movement implementation. Im trying to figure out now how I would be able to let the linked enemy instance know its bullet is off screen. Im fairly new to lua and Corona SDK so im still getting a grasp on how best to process things so please bear with me a simple outline of what im looking for is below
--random enemy fire
--move Bullet location on top of enemy(appears enemy fires)
--makes linked bullet visible
--simulates trajectory
CASE:* doesn't hit anything and goes off screen*
--hides Bullet
--signals to linked enemy it can fire again(changing activeBul to false)
Couple things to keep in mind, I have both Bullet and Enemy as metatables. Also the Bullet instance is also created the same time the enemy is created. So the the enemy never creates multiple Bullet instances, just hides and relocates it firing.
Im really looking for insight On how I should go about getting this to work properly, any advice will be appreciated
require
-ing the Bullet.lua file when the enemy shoots. The enemy metatable should contain a reference to the Bullet class, which each instance leverages. – HennyH