]> git.r.bdr.sh - rbdr/pico-engine/blob - scripts/npc_walker.lua
first commit
[rbdr/pico-engine] / scripts / npc_walker.lua
1 --Configuration for the Jumper
2 this.actorname = "Enemy: Walker"
3 this.enemy = enemy_evil
4 this.controllable = false
5 this.speed = 2
6 this.physics = true
7
8 print(">>> Entity Created - "..this.actorname);
9
10 function this.walk(this)
11 if(this:get_currentdirection() == left) then
12 if ( this:can_move(left, this:get_x(), this:get_y()) and
13 not this:can_move(down, this:get_x()+this:get_ownspeed(), this:get_y())) then
14 if this:get_collision(left) then
15 this:set_currentdirection(right)
16 else
17 this:set_ownspeed(-this.speed)
18 end
19 this:set_oldclip(1)
20 else
21 this:set_currentdirection(right)
22 this:set_ownspeed(this.speed)
23 end
24 end
25
26 if(this:get_currentdirection() == right) then
27 if ( this:can_move(right, this:get_x(), this:get_y()) and
28 not this:can_move(down, this:get_x()+this:get_ownspeed(), this:get_y())) then
29 if this:get_collision(right) then
30 this:set_currentdirection(left)
31 else
32 this:set_ownspeed(this.speed)
33 end
34 this:set_oldclip(2)
35 else
36 this:set_currentdirection(left)
37 this:set_ownspeed(-this.speed)
38 end
39 end
40 end
41
42 function this.act(this)
43 this:walk()
44 end
45
46 --END