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.chargeTimer = 0 25 26local STATE_CHARGEPREP = 1001 27local STATE_CHARGE = 1002 28 29function init(me) 30 setupEntity(me) 31 entity_setEntityType(me, ET_ENEMY) 32 entity_initSkeletal(me, "Scavenger") 33 --entity_setAllDamageTargets(me, false) 34 entity_setHealth(me, 28) 35 entity_setCullRadius(me, 1024) 36 37 entity_setCollideRadius(me, 80) 38 --entity_generateCollisionMask(me) 39 40 entity_setState(me, STATE_IDLE) 41 entity_setMaxSpeed(me, 500) 42 entity_setDeathScene(me, true) 43 44 entity_setDeathParticleEffect(me, "PinkExplode") 45 46 loadSound("Scavenger-Die") 47 loadSound("scavenger-attack") 48end 49 50function postInit(me) 51 v.n = getNaija() 52 entity_setTarget(me, v.n) 53end 54 55function update(me, dt) 56 if entity_isState(me, STATE_CHARGE) then 57 entity_touchAvatarDamage(me, entity_getCollideRadius(me), 1, 1000, 1.0) 58 else 59 entity_touchAvatarDamage(me, entity_getCollideRadius(me), 0.5) 60 end 61 entity_handleShotCollisions(me) 62 local bone = entity_collideSkeletalVsCircle(me, v.n) 63 if entity_isState(me, STATE_IDLE) then 64 if entity_isEntityInRange(me, v.n, 2048) then 65 entity_moveTowardsTarget(me, dt, 500) 66 entity_doCollisionAvoidance(me, dt, 4, 1) 67 entity_doEntityAvoidance(me, dt, 256, 0.5) 68 entity_doSpellAvoidance(me, dt, 512, 5) 69 if math.abs(entity_x(me)-entity_x(v.n)) > 100 then 70 entity_flipToEntity(me, v.n) 71 end 72 v.chargeTimer = v.chargeTimer + dt 73 if v.chargeTimer > 4 then 74 v.chargeTimer = 0 75 entity_setState(me, STATE_CHARGEPREP) 76 end 77 entity_rotate(me, 0, 0.5) 78 end 79 elseif entity_isState(me, STATE_CHARGE) then 80 entity_moveTowardsTarget(me, dt, 500) 81 if not entity_isFlippedHorizontal(me) then 82 entity_rotateToVel(me, 0.1, 90) 83 else 84 entity_rotateToVel(me, 0.1, -90) 85 end 86 end 87 88 89 entity_updateMovement(me, dt) 90end 91 92function enterState(me) 93 if entity_isState(me, STATE_IDLE) then 94 entity_animate(me, "idle", -1) 95 entity_setMaxSpeedLerp(me, 1.0, 0.2) 96 elseif entity_isState(me, STATE_CHARGEPREP) then 97 entity_setStateTime(me, entity_animate(me, "chargePrep")) 98 entity_clearVel(me) 99 entity_addVel(me, 0, -200) 100 elseif entity_isState(me, STATE_CHARGE) then 101 entity_sound(me, "scavenger-attack") 102 entity_animate(me, "charge") 103 entity_setMaxSpeedLerp(me, 4.0) 104 entity_setStateTime(me, 2.5) 105 entity_moveTowardsTarget(me, 1, 4000) 106 entity_flipToEntity(me, v.n) 107 elseif entity_isState(me, STATE_DEATHSCENE) then 108 entity_rotate(me, 0, 0.5) 109 entity_color(me, 0.5, 0.5, 0.5, 3) 110 entity_sound(me, "Scavenger-Die") 111 local t = entity_animate(me, "death") 112 entity_setStateTime(me, t) 113 local x, y = entity_getPosition(me) 114 while (isObstructed(x,y+16) == false) do 115 y = y + 20 116 end 117 entity_setPosition(me, x, y, t*0.5) 118 elseif entity_isState(me, STATE_GROW) then 119 entity_setStateTime(me, entity_animate(me, "grow")) 120 end 121end 122 123function exitState(me) 124 if entity_isState(me, STATE_CHARGEPREP) then 125 entity_setState(me, STATE_CHARGE) 126 elseif entity_isState(me, STATE_CHARGE) then 127 entity_setState(me, STATE_IDLE) 128 elseif entity_isState(me, STATE_GROW) then 129 entity_setState(me, STATE_IDLE) 130 end 131end 132 133function damage(me, attacker, bone, damageType, dmg) 134 if damageType == DT_AVATAR_BITE then 135 dmg = dmg * 1.5 136 end 137 return true 138end 139 140function animationKey(me, key) 141end 142 143function hitSurface(me) 144 if entity_isState(me, STATE_CHARGE) then 145 entity_setState(me, STATE_IDLE) 146 end 147end 148 149function songNote(me, note) 150end 151 152function songNoteDone(me, note) 153end 154 155function song(me, song) 156end 157 158function activate(me) 159end 160 161