1-- Copyright (C) 2007, 2010 - Bit-Blot 2-- 3-- This file is part of Aquaria. 4-- 5-- Aquaria is free software; you can redistribute it and/or 6-- modify it under the terms of the GNU General Public License 7-- as published by the Free Software Foundation; either version 2 8-- of the License, or (at your option) any later version. 9-- 10-- This program is distributed in the hope that it will be useful, 11-- but WITHOUT ANY WARRANTY; without even the implied warranty of 12-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13-- 14-- See the GNU General Public License for more details. 15-- 16-- You should have received a copy of the GNU General Public License 17-- along with this program; if not, write to the Free Software 18-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 20if not v then v = {} end 21if not AQUARIA_VERSION then dofile("scripts/entities/entityinclude.lua") end 22 23v.n = 0 24v.attackDelay = 2 25 26local STATE_GETREADY = 1000 27local STATE_FIRING = 1001 28 29v.body = 0 30 31function init(me) 32 setupEntity(me) 33 entity_setEntityType(me, ET_ENEMY) 34 entity_initSkeletal(me, "Guardian") 35 36 entity_generateCollisionMask(me) 37 38 entity_setHealth(me, 64) 39 entity_setDeathScene(me, true) 40 entity_setState(me, STATE_WAIT) 41 entity_setCullRadius(me, 2000) 42 entity_scale(me, 2, 2) 43 entity_setDeathScene(me, true) 44 45 v.body = entity_getBoneByName(me, "Body") 46 47 entity_setTargetRange(me, 2024) 48 49 entity_setUpdateCull(me, 3000) 50 51 loadSound("Guardian-Die") 52 loadSound("Guardian-Attack") 53end 54 55function postInit(me) 56 v.n = getNaija() 57 entity_setTarget(me, v.n) 58 59 local node = entity_getNearestNode(me, "FLIP") 60 if node ~= 0 and node_isEntityIn(node, me) then 61 entity_fh(me) 62 end 63end 64 65function update(me, dt) 66 --entity_updateMovement(me, dt) 67 68 if entity_isState(me, STATE_WAIT) then 69 if entity_isEntityInRange(me, v.n, 600) then 70 entity_setState(me, STATE_GETREADY) 71 end 72 end 73 74 if entity_isState(me, STATE_IDLE) then 75 v.attackDelay = v.attackDelay - dt 76 if v.attackDelay <= 0 then 77 if not entity_isEntityInRange(me, v.n, 1024) or chance(10) then 78 entity_setState(me, STATE_FIRING) 79 else 80 entity_setState(me, STATE_ATTACK) 81 end 82 end 83 84 end 85 86 if not entity_isState(me, STATE_WAIT) then 87 overrideZoom(0.6, 1) 88 end 89 90 entity_handleShotCollisionsSkeletal(me) 91 local bone = entity_collideSkeletalVsCircle(me, v.n) 92 if bone ~= 0 then 93 if entity_isfh(me) then 94 entity_addVel(v.n, 2000, 0) 95 else 96 entity_addVel(v.n, -2000, 0) 97 end 98 entity_damage(v.n, me, 1) 99 end 100 101 if entity_isfh(me) then 102 if entity_x(v.n) > entity_x(me) then 103 entity_addVel(v.n, 1000, 0) 104 end 105 else 106 if entity_x(v.n) > entity_x(me) then 107 entity_addVel(v.n, -1000, 0) 108 end 109 end 110 entity_clearTargetPoints(me) 111 entity_addTargetPoint(me, bone_getWorldPosition(v.body)) 112end 113 114function enterState(me) 115 if entity_isState(me, STATE_IDLE) then 116 entity_animate(me, "ready", -1) 117 elseif entity_isState(me, STATE_WAIT) then 118 entity_animate(me, "wait", -1) 119 elseif entity_isState(me, STATE_GETREADY) then 120 entity_setStateTime(me, entity_animate(me, "getReady")) 121 elseif entity_isState(me, STATE_ATTACK) then 122 playSfx("Guardian-Attack") 123 if entity_y(v.n) < entity_y(me) then 124 entity_setStateTime(me, entity_animate(me, "attack")) 125 else 126 entity_setStateTime(me, entity_animate(me, "attack2")) 127 end 128 elseif entity_isState(me, STATE_DEATHSCENE) then 129 playSfx("Guardian-Die") 130 shakeCamera(4, 4) 131 overrideZoom(0.5, 0.5) 132 entity_setStateTime(me, 99) 133 cam_toEntity(me) 134 entity_setInvincible(v.n, true) 135 watch(entity_animate(me, "die")) 136 entity_color(me, 0, 0, 0, 1) 137 watch(1) 138 entity_setStateTime(me, 0.01) 139 entity_setInvincible(v.n, false) 140 cam_toEntity(v.n) 141 elseif entity_isState(me, STATE_FIRING) then 142 entity_setStateTime(me, entity_animate(me, "firing")) 143 end 144end 145 146function exitState(me) 147 if entity_isState(me, STATE_ATTACK) then 148 v.attackDelay = 3 149 entity_setState(me, STATE_IDLE) 150 elseif entity_isState(me, STATE_GETREADY) then 151 entity_setState(me, STATE_IDLE) 152 elseif entity_isState(me, STATE_DEATHSCENE) then 153 overrideZoom(0, 0.5) 154 elseif entity_isState(me, STATE_FIRING) then 155 entity_setState(me, STATE_IDLE) 156 end 157end 158 159function damage(me, attacker, bone, damageType, dmg) 160 if entity_isState(me, STATE_WAIT) then 161 entity_setState(me, STATE_GETREADY) 162 return false 163 end 164 if bone == v.body then 165 return true 166 end 167 168 return false 169end 170 171function animationKey(me, key) 172 if entity_isState(me, STATE_FIRING) then 173 if key == 2 or key == 4 or key == 6 then 174 local s = createShot("Guardian", me, v.n, entity_getPosition(me)) 175 if key == 2 then 176 shot_setAimVector(s, -400, -100) 177 elseif key == 4 then 178 shot_setAimVector(s, -400, 0) 179 elseif key == 6 then 180 shot_setAimVector(s, -400, 100) 181 end 182 end 183 end 184end 185 186function hitSurface(me) 187end 188 189function songNote(me, note) 190end 191 192function songNoteDone(me, note) 193end 194 195function song(me, song) 196end 197 198function activate(me) 199end 200 201