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-- S Q U E E Z E R 25-- ================================================================================================ 26 27local STATE_CLAMP = 1000 28local STATE_CLAMPED = 1001 29local STATE_UNCLAMP = 1002 30local STATE_GRABBED = 1003 31 32 33-- ================================================================================================ 34-- L O C A L V A R I A B L E S 35-- ================================================================================================ 36 37v.clampDelay = 0 38 39-- ================================================================================================ 40-- FUNCTIONS 41-- ================================================================================================ 42 43function init(me) 44 setupBasicEntity( 45 me, 46 "squeezer-head", -- texture 47 20, -- health 48 2, -- manaballamount 49 2, -- exp 50 1, -- money 51 48, -- collideRadius (for hitting entities + spells) 52 STATE_IDLE, -- initState 53 256, -- sprite width 54 512, -- sprite height 55 1, -- particle "explosion" type, maps to particleEffects.txt -1 = none 56 1, -- 0/1 hit other entities off/on (uses collideRadius) 57 2000, -- updateCull -1: disabled, default: 4000 58 1 59 ) 60 61 -- entity_initPart(partName, partTexture, partPosition, partFlipH, partFlipV, 62 -- partOffsetInterpolateTo, partOffsetInterpolateTime 63 entity_initPart(me, 64 "FlipperLeft", 65 "squeezer-flipper", 66 -8, 67 0, 68 0, 69 0, 70 0) 71 72 entity_initPart(me, 73 "FlipperRight", 74 "squeezer-flipper", 75 8, 76 0, 77 0, 78 1, 79 0) 80 81 entity_scale(me, 0.8, 0.8) 82 83 entity_setDeathParticleEffect(me, "TinyGreenExplode") 84 entity_setDropChance(me, 10, 1) 85end 86 87function update(me, dt) 88 entity_handleShotCollisions(me) 89 if not entity_hasTarget(me) then 90 entity_findTarget(me, 1000) 91 else 92 if v.clampDelay > 0 then 93 v.clampDelay = v.clampDelay - dt 94 if v.clampDelay < 0 then 95 v.clampDelay = 0 96 end 97 end 98 if entity_hasTarget(me) then 99 if not(entity_getState(me)==STATE_GRABBED) then 100 if not(entity_isTargetInRange(me,64)) then 101 entity_moveTowardsTarget(me,dt, 900) 102 else 103 entity_doFriction(me,dt, 1000) 104 end 105 if entity_getState(me)==STATE_IDLE and entity_isTargetInRange(me,64) and v.clampDelay==0 then 106 entity_setState(me,STATE_CLAMP, 0.25) 107 end 108 if entity_getState(me)==STATE_CLAMPED then 109 entity_doFriction(me,dt, 500) 110 if entity_isTargetInRange(me,96) then 111 entity_grabTarget(me) 112 avatar_fallOffWall() 113-- entity_hurtTarget(1) 114 entity_setState(me, STATE_GRABBED, 8) 115 end 116 end 117 end 118 end 119 end 120 --entity_doEntityAvoidance(me, dt, 0, 1); 121 entity_doCollisionAvoidance(me, dt, 4, 1.0); 122 entity_rotateToVel(me, 0, 180) 123 entity_updateMovement(me, dt) 124end 125 126function enterState(me) 127 if entity_getState(me)==STATE_IDLE then 128 entity_setMaxSpeed(me, 400) 129 entity_partRotate(me, "FlipperLeft", 4, 1, -1, 1, 1) 130 entity_partRotate(me, "FlipperRight", -4, 1, -1, 1, 1) 131 elseif entity_getState(me)==STATE_CLAMP then 132 entity_partRotate(me, "FlipperLeft", -64, entity_getStateTime(me), 0, 0, 0) 133 entity_partRotate(me, "FlipperRight", 64, entity_getStateTime(me), 0, 0, 0) 134 elseif entity_getState(me)==STATE_UNCLAMP then 135 entity_partRotate(me, "FlipperLeft", 0, 1) 136 entity_partRotate(me,"FlipperRight", 0, 1) 137 end 138end 139 140function exitState(me) 141 if entity_getState(me)==STATE_CLAMP then 142 entity_setState(me, STATE_CLAMPED, 0.2) 143 elseif entity_getState(me)==STATE_CLAMPED then 144 entity_setState(me, STATE_UNCLAMP, 1) 145 elseif entity_getState(me)==STATE_UNCLAMP then 146 entity_setState(me, STATE_IDLE, -1) 147 elseif entity_getState(me)==STATE_GRABBED then 148 entity_releaseTarget(me) 149 entity_pushTarget(me, 1000) 150 entity_setState(me, STATE_UNCLAMP, 1) 151 end 152end 153