Skip to content

Examples

Joshua Murphy edited this page Jul 19, 2016 · 10 revisions

straifer.lua

Straifer locks onto the closest enemy, then moves left and right while shooting.

function update()
	
	local enemy = game.findClosestEnemy()
	if enemy != nil then
	
		if game.time % 150 < 75 then
			this.moveLeft()
		else
			this.moveRight()
		end
		
		this.turnToward(enemy)
		if this.isFacingEnemy() then
			this.moveForward(.2)
			this.shoot()
		end
		
	end
	
end

charger.lua

Charger locks onto the weakest enemy, then rushes toward it while moving left and right.

function update()
	
	local enemy = game.findWeakestEnemy()
	if enemy != nil then
	
		if game.time % 100 < 50 then
			this.moveLeft()
		else
			this.moveRight()
		end
	
		this.turnToward(enemy)
		
		local dist = game.getDistanceTo(enemy)
		if dist > 100 then
			this.moveForward()
		else
			this.moveBackward()
		end
		
		if this.isFacing(enemy) then
			this.shoot()
		end
		
	end
end

aimer.lua

Aimer doesn't shoot directly at its target, but rather where it thinks the target will be when the bullet lands. Aimer also attempts to dodge bullets after they're shot at it.

local dodge = 0

function update()
	
	local enemy = game.findClosestEnemy()
	if enemy != nil then
		
		local pos = enemy.position
		local vel = enemy.velocity
		local dist = game.getDistanceTo(enemy)
		
		vel = vel * dist / this.bulletSpeed
		pos = pos + vel
		
		this.turnToward(pos)
		this.shoot()
		
		if dodge < 0 then
			dodge = dodge + 1
			this.moveLeft()
		elseif dodge > 0 then
			dodge = dodge - 1
			this.moveRight()
		end
		
	end
		
end
			
function onFighterShotBullet(fighter)
	if fighter.isFacing(this) then
		if game.time % 100 < 50 then
			dodge = 25
		else
			dodge = -25
		end
	end
end

Clone this wiki locally