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.glow = 0 25 26v.entToSpawn = "" 27v.ingToSpawn = "" 28v.amount = 0 29 30v.myNote = 0 31 32v.singingNote = false 33v.singTimer = 0 34 35v.back = false 36 37function init(me) 38 setupEntity(me) 39 entity_setEntityType(me, ET_NEUTRAL) 40 entity_initSkeletal(me, "ancient-plant") 41 42 v.glow = entity_getBoneByName(me, "glow") 43 bone_setVisible(v.glow, 1) 44 45 entity_animate(me, "idle", -1) 46 47 if entity_isFlag(me, 1) then 48 entity_setState(me, STATE_OPENED) 49 else 50 entity_setState(me, STATE_CLOSED) 51 end 52 53 local n1 = getNearestNodeByType(entity_x(me), entity_y(me), PATH_SETING) 54 if n1 ~= 0 and node_isEntityIn(n1, me) then 55 v.ingToSpawn = node_getContent(n1) 56 v.amount = node_getAmount(n1) if v.amount == 0 then v.amount = 1 end 57 else 58 local n2 = getNearestNodeByType(entity_x(me), entity_y(me), PATH_SETENT) 59 if n2 ~= 0 and node_isEntityIn(n2, me) then 60 v.entToSpawn = node_getContent(n2) 61 v.amount = node_getAmount(n2) if v.amount == 0 then v.amount = 1 end 62 end 63 end 64 65 v.myNote = getRandNote() 66 67 entity_setCanLeaveWater(me, true) 68 69 entity_setCullRadius(me, 512) 70 71 72 -- note: LAYER OVERRIDE 73 entity_setEntityLayer(me, -100) 74end 75 76function postInit(me) 77 v.n = getNaija() 78 entity_setTarget(me, v.n) 79 80 bone_setBlendType(v.glow, BLEND_ADD) 81 bone_alpha(v.glow, 0.4) 82 83 bone_scale(v.glow, 12, 12, 1, -1, 1) 84end 85 86function update(me, dt) 87 if entity_isState(me, STATE_CLOSED) then 88 if v.singingNote then 89 v.singTimer = v.singTimer + dt 90 if v.singTimer > 2 then 91 v.singingNote = false 92 v.singTimer = 0 93 entity_setState(me, STATE_OPEN) 94 end 95 end 96 end 97end 98 99function enterState(me) 100 if entity_isState(me, STATE_IDLE) then 101 elseif entity_isState(me, STATE_CLOSED) then 102 elseif entity_isState(me, STATE_OPENED) then 103 elseif entity_isState(me, STATE_OPEN) then 104 entity_setStateTime(me, 1) 105 106 entity_setFlag(me, 1) 107 108 local bx, by = bone_getWorldPosition(v.glow) 109 110 if v.ingToSpawn ~= "" or v.entToSpawn ~= "" then 111 playSfx("secret") 112 end 113 if v.ingToSpawn ~= "" then 114 for i=1,v.amount do 115 spawnIngredient(v.ingToSpawn, bx, by, 1, (i==1)) 116 end 117 elseif v.entToSpawn ~= "" then 118 for i=1,v.amount do 119 createEntity(v.entToSpawn, "", bx, by) 120 end 121 end 122 end 123end 124 125function exitState(me) 126 if entity_isState(me, STATE_OPEN) then 127 entity_setState(me, STATE_OPENED) 128 end 129end 130 131function damage(me, attacker, bone, damageType, dmg) 132 return false 133end 134 135function animationKey(me, key) 136end 137 138function hitSurface(me) 139end 140 141function songNote(me, note) 142 --[[ 143 if entity_isEntityInRange(me, v.n, 800) then 144 if entity_isState(me, STATE_CLOSED) then 145 if v.myNote == note then 146 147 if v.back then 148 local e = getFirstEntity() 149 while e ~= 0 do 150 if eisv(e, EV_TYPEID, EVT_ROCK) or eisv(e, EV_TYPEID, EVT_CONTAINER) then 151 if entity_isEntityInRange(me, e, 64) then 152 return 153 end 154 end 155 e = getNextEntity() 156 end 157 end 158 v.singingNote = true 159 v.singTimer = 0 160 end 161 end 162 end 163 ]]-- 164end 165 166function songNoteDone(me, note) 167 v.singingNote = false 168 v.singTimer = 0 169end 170 171function song(me, song) 172end 173 174function activate(me) 175end 176 177