aboutsummaryrefslogtreecommitdiff
path: root/scripts/npc_walker.lua
blob: 1537464e5d02cfaedefec6ff6e7a82bbdf069d2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
--Configuration for the Jumper
this.actorname = "Enemy: Walker"
this.enemy			= enemy_evil
this.controllable	= false
this.speed			= 2
this.physics		= true

print(">>> Entity Created - "..this.actorname);

function this.walk(this)
	if(this:get_currentdirection() == left) then
		if ( this:can_move(left, this:get_x(), this:get_y()) and 
			not this:can_move(down, this:get_x()+this:get_ownspeed(), this:get_y())) then
			if this:get_collision(left) then
				this:set_currentdirection(right)
			else
				this:set_ownspeed(-this.speed)
			end
			this:set_oldclip(1)
		else
			this:set_currentdirection(right)
			this:set_ownspeed(this.speed)
		end
	end
	
	if(this:get_currentdirection() == right) then
		if ( this:can_move(right, this:get_x(), this:get_y()) and 
			not this:can_move(down, this:get_x()+this:get_ownspeed(), this:get_y())) then
			if this:get_collision(right) then
				this:set_currentdirection(left)
			else
				this:set_ownspeed(this.speed)
			end
			this:set_oldclip(2)
		else
			this:set_currentdirection(left)
			this:set_ownspeed(-this.speed)
		end
	end
end

function this.act(this)
	this:walk()
end

--END