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 23-- ================================================================================================ 24-- I C E C H U N K C O M M O N S C R I P T 25-- ================================================================================================ 26 27-- ================================================================================================ 28-- L O C A L V A R I A B L E S 29-- ================================================================================================ 30 31v.n = 0 32 33v.chunkSize = 0 34v.width = 0 35v.dir = -1 36 37-- ================================================================================================ 38-- F U N C T I O N S 39-- ================================================================================================ 40 41function v.commonInit(me, size) 42 v.maxSpeed = 321 + math.random(32) 43 v.chunkSize = size 44 45 setupBasicEntity( 46 me, 47 "IceChunk/Large", -- texture 48 8, -- health 49 1, -- manaballamount 50 1, -- exp 51 0, -- money 52 64, -- collideRadius (for hitting entities + spells) 53 STATE_IDLE, -- initState 54 512, -- sprite width 55 512, -- sprite height 56 1, -- particle "explosion" type, maps to particleEffects.txt -1 = none 57 1, -- 0/1 hit other entities off/on (uses collideRadius) 58 4000 -- updateCull -1: disabled, default: 4000 59 ) 60 61 loadSound("IceChunkBreak") 62 63 entity_setEntityType(me, ET_NEUTRAL) 64 --entity_setAllDamageTargets(me, false) 65 --entity_setDamageTarget(me, DT_AVATAR_LIZAP, false) 66 entity_setDamageTarget(me, DT_AVATAR_BITE, false) 67 68 entity_setDeathScene(me, true) 69 70 -- SLIGHT SCALE AND COLOUR VARIATION 71 local sz = 0.8 + (math.random(400) * 0.001) 72 entity_scale(me, sz, sz) 73 local cl = 1.0 - (math.random(2345) * 0.0001) 74 entity_color(me, cl, cl, cl) 75 76 -- IF LARGE 77 if v.chunkSize <= 0 then 78 v.chunkSize = 0 79 entity_setTexture(me, "IceChunk/Large") 80 v.width = 154 81 entity_setHealth(me, 8) 82 83 -- IF MEDIUM 84 elseif v.chunkSize == 1 then 85 v.chunkSize = 1 86 entity_setTexture(me, "IceChunk/Medium") 87 v.width = 76 88 entity_setHealth(me, 4) 89 v.maxSpeed = v.maxSpeed * 1.23 90 91 -- IF SMALL 92 else 93 v.chunkSize = 2 94 entity_setTexture(me, "IceChunk/Small") 95 v.width = 42 96 entity_setHealth(me, 2) 97 v.maxSpeed = v.maxSpeed * 1.54 98 end 99 100 v.width = v.width * sz 101 entity_setCollideRadius(me, v.width) 102 entity_setDeathSound(me, "") 103 entity_alpha(me, 0.9) 104end 105 106function postInit(me) 107 v.n = getNaija() 108 109 entity_setMaxSpeed(me, v.maxSpeed) 110 entity_rotate(me, randAngle360()) 111 entity_addRandomVel(me, 123) 112 113 if chance(50) then v.dir = 1 end 114end 115 116function update(me, dt) 117 entity_clearTargetPoints(me) 118 119 -- ROTATE GENTLY 120 local rotSpeed = (entity_getVelLen(me)/300) + 1 121 if entity_velx(me) < 0 then v.dir = -1 122 else v.dir = 1 end 123 entity_rotateTo(me, entity_getRotation(me) + (rotSpeed * v.dir)) 124 125 -- IF LARGE 126 if v.chunkSize == 0 then 127 -- LOCK ON TO BIG CHUNK 128 if entity_touchAvatarDamage(me, v.width*1.1, 0) then 129 if avatar_isBursting() and entity_setBoneLock(v.n, me) then 130 else 131 local vecX, vecY = entity_getVectorToEntity(me, v.n, 1000) 132 entity_addVel(v.n, vecX, vecY) 133 end 134 end 135 136 if entity_getBoneLockEntity(v.n) ~= me and entity_touchAvatarDamage(me, v.width, 0, 321) then 137 end 138 139 -- IF MEDIUM 140 elseif v.chunkSize == 1 then 141 -- NAIJA COLLISION 142 if entity_getBoneLockEntity(v.n) ~= me and entity_touchAvatarDamage(me, v.width, 0, 210) then 143 if avatar_isBursting() then 144 entity_moveTowards(me, entity_x(getNaija()), entity_y(getNaija()), 1, -456) 145 else 146 entity_moveTowards(me, entity_x(getNaija()), entity_y(getNaija()), 1, -87) 147 end 148 end 149 150 -- IF SMALL 151 elseif v.chunkSize == 2 then 152 -- NAIJA COLLISION 153 if entity_getBoneLockEntity(v.n) ~= me and entity_touchAvatarDamage(me, v.width, 0, 128) then 154 if avatar_isBursting() then 155 entity_moveTowards(me, entity_x(getNaija()), entity_y(getNaija()), 1, -1234) 156 else 157 entity_moveTowards(me, entity_x(getNaija()), entity_y(getNaija()), 1, -128) 158 end 159 end 160 end 161 162 -- AVOIDANCE 163 if entity_getBoneLockEntity(v.n) ~= me then entity_doEntityAvoidance(me, dt, v.width*1.1, 1.23) end 164 entity_doCollisionAvoidance(me, dt, ((v.width*0.01)*7)+1, 0.421) 165 -- MOVEMENT 166 if entity_getVelLen(me) > 64 then entity_doFriction(me, dt, 42) end 167 entity_updateMovement(me, dt) 168 -- SHOT COLLISIONS 169 entity_handleShotCollisions(me) 170end 171 172function enterState(me) 173 if entity_getState(me) == STATE_IDLE then 174 175 elseif entity_getState(me) == STATE_DEATHSCENE then 176 local deathTime = 0.23 177 entity_setStateTime(me, deathTime) 178 entity_alpha(me, 0, deathTime) 179 entity_scale(me, 0, 0, deathTime) 180 entity_delete(me, deathTime) 181 182 entity_sound(me, "IceChunkBreak") 183 184 if v.chunkSize ~= 2 then 185 for i=1,3 do 186 local newChunk 187 if v.chunkSize == 0 then 188 newChunk = createEntity("IceChunkMedium", "", entity_x(me) + (math.random(8) - 4), entity_y(me) + (math.random(8) - 4)) 189 else 190 newChunk = createEntity("IceChunkSmall", "", entity_x(me) + (math.random(4) - 2), entity_y(me) + (math.random(4) - 2)) 191 end 192 entity_moveTowards(newChunk, entity_x(me), entity_y(me), 1, -321) 193 end 194 end 195 end 196end 197 198function exitState(me) 199end 200 201function hitSurface(me) 202 203 204end 205 206function damage(me, attacker, bone, damageType, dmg) 207 return true 208end 209 210function activate(me) 211end 212