Skip to content

Instantly share code, notes, and snippets.

@8bitgentleman
Created December 1, 2014 20:06
Show Gist options
  • Save 8bitgentleman/4290dbeae758d4c39c36 to your computer and use it in GitHub Desktop.
Save 8bitgentleman/4290dbeae758d4c39c36 to your computer and use it in GitHub Desktop.
QFO
local Enemy = require 'nodes/enemy'
local gamestate = require 'vendor/gamestate'
local sound = require 'vendor/TEsound'
local Timer = require 'vendor/timer'
local Projectile = require 'nodes/projectile'
local sound = require 'vendor/TEsound'
local utils = require 'utils'
local window = require 'window'
local camera = require 'camera'
local fonts = require 'fonts'
return {
name = 'qfo',
attackDelay = 1,
height = 60,
width = 218,
damage = 40,
attack_bb = true,
jumpkill = false,
knockback = 0,
player_rebound = 400,
antigravity = true,
bb_width = 218,
bb_height = 15,
--bb_offset = { x = -40, y = 10},
attack_width = 40,
--attack_offset = { x = -40, y = 10},
velocity = {x = 20, y = 50},
hp = 50,
tokens = 15,
hand_x = -40,
hand_y = 70,
dyingdelay = 2,
tokenTypes = { -- p is probability ceiling and this list should be sorted by it, with the last being 1
{ item = 'coin', v = 1, p = 0.9 },
{ item = 'health', v = 1, p = 1 }
},
animations = {
default = {
right = {'loop', {'1-3,1','1-3,2','1,3'}, .1},
left = {'loop', {'1-3,1','1-3,2','1,3'}, .1}
},
dying = {
right = {'once', {'2-3,3', '1-3,4','1-3,5','1-3,6','1-3,7','1-3,8','1-3,9'}, 0.1},
left = {'once', {'2-3,3', '1-3,4','1-3,5','1-3,6','1-3,7','1-3,8','1-3,9'}, 0.1}
},
enter = {
right = {'once', {'1,1'}, 0.25},
left = {'once', {'1,1'}, 0.25}
},
hurt = {
right = {'loop', {'1,1'}, .1},
left = {'loop', {'1,1'}, .1}
},
},
enter = function( enemy )
enemy.direction = math.random(2) == 1 and 'left' or 'right'
enemy.state = 'enter'
enemy.hatched = false
enemy.maxx = enemy.position.x + 24
enemy.minx = enemy.position.x - 24
end,
die = function( enemy )
enemy.props.spawn_pilot(enemy, direction)
end,
draw = function( enemy )
fonts.set( 'small' )
love.graphics.setStencil( )
local energy = love.graphics.newImage('images/enemies/bossHud/energy.png')
local bossChevron = love.graphics.newImage('images/enemies/bossHud/bossChevron.png')
local bossPic = love.graphics.newImage('images/enemies/bossHud/qfoBoss.png')
energy:setFilter('nearest', 'nearest')
bossChevron:setFilter('nearest', 'nearest')
bossPic:setFilter('nearest', 'nearest')
x, y = camera.x + window.width - 130 , camera.y + 10
love.graphics.setColor( 255, 255, 255, 255 )
love.graphics.draw( bossChevron, x , y )
love.graphics.draw( bossPic, x + 69, y + 10 )
love.graphics.setColor( 0, 0, 0, 255 )
love.graphics.printf( "QFO", x + 15, y + 15, 52, 'center' )
love.graphics.printf( "BOSS", x + 15, y + 41, 52, 'center' )
energy_stencil = function( x, y )
love.graphics.rectangle( 'fill', x + 11, y + 27, 59, 9 )
end
love.graphics.setStencil(energy_stencil, x, y)
local max_hp = 50
local rate = 55/max_hp
love.graphics.setColor(
math.min(utils.map(enemy.hp, max_hp, max_hp / 2 + 1, 0, 255 ), 255), -- green to yellow
math.min(utils.map(enemy.hp, max_hp / 2, 0, 255, 0), 255), -- yellow to red
0,
255
)
love.graphics.draw(energy, x + ( max_hp - enemy.hp ) * rate, y)
love.graphics.setStencil( )
love.graphics.setColor( 255, 255, 255, 255 )
fonts.revert()
end,
spawn_minion = function( enemy, direction, offset )
local node = {
x = enemy.position.x+offset,
y = enemy.position.y+40,
type = 'enemy',
properties = {
enemytype = 'alien'
}
}
local spawnedAlien = Enemy.new(node, enemy.collider, enemy.type)
enemy.containerLevel:addNode(spawnedAlien)
end,
spawn_pilot = function( enemy, direction)
local node = {
x = enemy.position.x,
y = enemy.position.y-25,
type = 'enemy',
properties = {
enemytype = 'alien_pilot'
}
}
local spawnedPilot = Enemy.new(node, enemy.collider, enemy.type)
enemy.containerLevel:addNode(spawnedPilot)
end,
update = function( dt, enemy, player, level )
if enemy.dead then return end
local direction = player.position.x > enemy.position.x + 40 and -1 or 1
local offset = math.random(0,200)
if enemy.position.x > enemy.maxx then
enemy.direction = 'left'
elseif enemy.position.x < enemy.minx then
enemy.direction = 'right'
end
if enemy.velocity.y > 1 and not enemy.hatched then
enemy.state = 'enter'
elseif math.abs(enemy.velocity.y) < 1 and not enemy.hatched then
Timer.add(2, function() enemy.hatched = true end)
elseif enemy.hatched then
enemy.last_attack = enemy.last_attack + dt
local pause = 2
if enemy.hp < 20 then
pause = 0.7
elseif enemy.hp < 50 then
pause = 1
end
if enemy.last_attack > pause then
enemy.props.spawn_minion(enemy, direction, offset)
--[[if enemy.hp < 80 and rand > 0.9 then
enemy.props.spawn_minion(enemy, direction)
elseif rand > 0.6 then
--should really spawn the churo enemy here but whatevs
enemy.props.spawn_minion(enemy, direction)
end]]
enemy.last_attack = -0
end
if enemy.velocity.y == 0 and enemy.hatched then
enemy.state = 'default'
end
if enemy.hp <=0 then
enemy.props.spawn_pilot(enemy, direction)
end
end
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment