Skip to content

Instantly share code, notes, and snippets.

@maykelsb
Created May 7, 2013 01:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maykelsb/5529672 to your computer and use it in GitHub Desktop.
Save maykelsb/5529672 to your computer and use it in GitHub Desktop.
-- 1)
function enemy:shoot()
local Bullet = require "Bullet";
Bullet.owner = self;
-- the same as your previous code
end;
function enemy:canShootAgain()
self.activeBul = false;
end;
-- When you want the enemy to shoot again, just call canShootAgain from bullet
bullet.owner:canShootAgain();
-- 2)
function enemy:shoot()
local Bullet = require "Bullet";
Bullet.owner = self;
-- the same as your previous code
end;
function enemy:canShootAgain()
self.activeBul = false;
end;
-- When you want the enemy to shoot again, just call canShootAgain from bullet
bullet.owner:dispatchEvent({name = 'canShootAgain'});
-- Add this to the end of your enemy construction
enemy:addEventListener('canShootAgain', enemy);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment