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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
pig = { pigx, pigy, pigeat, pigwater, pighap}
pig[1] = (map('xsize')*32) / 2
pig[2] = (map('ysize')*32) / 2
pig.img = 0
local rot_change = 0
pig.rot = 45
pig.speed = 1
----change image you want !--------
pig.PATH_LOAD_IMG_HERE = image('gfx/chicken.bmp',pig[1],pig[2],1)
local fix_x,fix_y,npc_x,npc_y
addhook("startround","restart_value")
function restart_value(mode)
	if pig.img ~= 0 then
		freeimage(pig.img)
	end
	pic.img = 0
	pig[1] = (map('xsize')*32) / 2
	pig[2] = (map('ysize')*32) / 2
end
local autorot
addhook("always","move")
function move()
	if pig.img == 0 then
		pig.img = pig.PATH_LOAD_IMG_HERE
		imagealpha(pig.img,1)
	end
	if pig.img ~= 0 then
		local rot = math.rad(pig.rot)
		local angel = math.deg(rot)
		autorot = math.random(-2,2)*math.pi/2
				if rot_change > 0 then
					pig.rot = math.random(1,180)
				else
					pig.rot = pig.rot
				end
	 	check_x = math.floor(pig[1]*32+16)
	 	 	check_y = math.floor(pig[2]*32+16)
				fix_x = pig[1] - math.sin(rot) * pig.speed
				fix_y = pig[2] + math.cos(rot) * pig.speed/3
	 if check_x < map('xsize')*32 and check_y < map('ysize')*32 then
			if tile(check_x/32,check_y/32,'walkable') then
					pig[1] = check_x
					pig[2] = check_y
					rot_change = 0
	 	 else
					
					pig[1] = fix_x
					pig[2] = fix_y
					rot_change = 2
			end
				
		end
				imagepos(pig.img,pig[1],pig[2],autorot)
	end
end