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 R A B
25-- ================================================================================================
26
27-- ================================================================================================
28-- L O C A L   V A R I A B L E S
29-- ================================================================================================
30
31v.moveTimer = 0
32
33-- ================================================================================================
34-- F U N C T I O N S
35-- ================================================================================================
36
37function init(me)
38	setupBasicEntity(me,
39	"IceCrab/Body",					-- texture
40	18,								-- health
41	1,								-- manaballamount
42	0,								-- exp
43	0,								-- money
44	34,								-- collideRadius (for hitting entities + spells)
45	STATE_IDLE,						-- initState
46	128,							-- sprite width
47	128,							-- sprite height
48	1,								-- particle "explosion" type, maps to particleEffects.txt -1 = none
49	1,								-- 0/1 hit other entities off/on (uses collideRadius)
50	3210							-- updateCull -1: disabled, default: 4000
51	)
52
53	entity_setDeathParticleEffect(me, "Explode")
54
55	entity_initSkeletal(me, "IceCrab")
56	entity_scale(me, 1.1, 1.1)
57
58	esetv(me, EV_WALLOUT, 23)
59	entity_clampToSurface(me)
60end
61
62function postInit(me)
63	entity_setState(me, STATE_IDLE)
64
65	-- FLIP WITH A FLIP NODE
66	local node = entity_getNearestNode(me, "FLIP")
67	if node ~=0 then
68		if node_isEntityIn(node, me) then
69			entity_fh(me)
70		entity_switchSurfaceDirection(me)
71		end
72	end
73end
74
75function update(me, dt)
76	-- FLIP AFTER A WHILE
77	v.moveTimer = v.moveTimer + dt
78	if v.moveTimer > 42 then
79		entity_switchSurfaceDirection(me)
80		entity_fh(me)
81		v.moveTimer = 0
82	end
83
84	-- MOVEMENT
85	entity_moveAlongSurface(me, dt, 76)
86	entity_rotateToSurfaceNormal(me, 0.54)
87	-- COLLISIONS
88	entity_touchAvatarDamage(me, 56, 0.76, 321)
89	entity_handleShotCollisions(me)
90end
91
92function enterState(me)
93	if entity_getState(me) == STATE_IDLE then
94		entity_animate(me, "idle", LOOP_INF)
95	end
96end
97
98function damage(me, attacker, bone, damageType, dmg)
99	return true
100end
101
102function dieNormal(me)
103	if chance(50) then
104		spawnIngredient("IceChunk", entity_x(me), entity_y(me))
105	end
106end
107