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-- R O T   C R A B
25-- ================================================================================================
26
27
28-- ================================================================================================
29-- L O C A L  V A R I A B L E S
30-- ================================================================================================
31
32v.fireDelay = 2
33v.moveTimer = 0
34
35-- ================================================================================================
36-- FUNCTIONS
37-- ================================================================================================
38
39function init(me)
40	setupBasicEntity(me,
41	"rotcrab/head",				-- texture
42	20,								-- health
43	2,								-- manaballamount
44	2,								-- exp
45	1,								-- money
46	20,								-- collideRadius (for hitting entities + spells)
47	STATE_IDLE,						-- initState
48	256,							-- sprite width
49	256,							-- sprite height
50	1,								-- particle "explosion" type, maps to particleEffects.txt -1 = none
51	1,								-- 0/1 hit other entities off/on (uses collideRadius)
52	4000							-- updateCull -1: disabled, default: 4000
53	)
54
55	--entity_offset(0, 128)
56
57	-- entity_initPart(partName, partTexture, partPosition, partFlipH, partFlipV,
58	-- partOffsetInterpolateTo, partOffsetInterpolateTime
59	entity_initPart(me,
60	"ClawLeft",
61	"rotcrab/claw",
62	-64,
63	-48,
64	0,
65	1,
66	0)
67
68	entity_initPart(me,
69	"ClawRight",
70	"rotcrab/claw",
71	64,
72	-48,
73	0,
74	0,
75	0)
76
77	esetv(me, EV_WALLOUT, 40)
78
79	entity_initPart(me, "LegsLeft", "rotcrab/leg", -64, 48, 0, 1, 0)
80	entity_initPart(me, "LegsRight", "rotcrab/leg", 64, 48, 0, 0, 0)
81
82	entity_partRotate(me, "ClawLeft", -32, 0.5, -1, 1, 1);
83	entity_partRotate(me, "ClawRight", 32, 0.5, -1, 1, 1);
84
85	entity_partRotate(me, "LegsLeft", 16, 0.25, -1, 1, 1);
86	entity_partRotate(me, "LegsRight", -16, 0.25, -1, 1, 1);
87
88	entity_scale(me, 0.5, 0.5)
89
90	entity_setDeathParticleEffect(me, "Explode")
91
92	entity_clampToSurface(me)
93end
94
95function update(me, dt)
96
97	if entity_touchAvatarDamage(me, 96, 1, 1000) then
98		setPoison(1, 10)
99	end
100	entity_handleShotCollisions(me)
101	-- dt, pixelsPerSecond, climbHeight, outfromwall
102	entity_moveAlongSurface(me, dt, 200, 6, 40) --64 -- 54
103	entity_rotateToSurfaceNormal(me, 0.1)
104	-- entity_rotateToSurfaceNormal(0)
105	v.moveTimer = v.moveTimer + dt
106	if v.moveTimer > 60 then
107		entity_switchSurfaceDirection(me)
108		v.moveTimer = 0
109	end
110	if not(entity_hasTarget(me)) then
111		entity_findTarget(me, 1200)
112	else
113		if v.fireDelay > 0 then
114			v.fireDelay = v.fireDelay - dt
115			if v.fireDelay < 0 then
116				-- dmg, mxspd, homing, numsegs, out
117				--entity_fireAtTarget(me, "BlasterFire", 1, 400, 200, 3, 64)
118				v.fireDelay = 5
119			end
120		end
121	end
122end
123
124function enterState(me)
125	if entity_getState(me)==STATE_IDLE then
126	end
127end
128
129function exitState(me)
130end
131
132function hitSurface()
133end
134
135function damage(me, attacker, bone, damageType, dmg)
136	return true
137end
138
139function dieNormal(me)
140	if chance(50) then
141		spawnIngredient("RottenMeat", entity_getPosition(me))
142	end
143end
144