Forum

> > CS2D > Scripts > Pig script
Forums overviewCS2D overview Scripts overviewLog in to reply

English Pig script

9 replies
To the start Previous 1 Next To the start

old Pig script

kalis
User Off Offline

Quote
hello every one
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
check_x = math.floor(pig[1]*32+16)
        	  	 	check_y = math.floor(pig[2]*32+16)

        	  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)
why pig image doesn't appear ?
i think the fail in "math.floor" !
And how i can make my pig random move on the ground ?

old Re: Pig script

mafia_man
User Off Offline

Quote
Could you post whole script, because we don't know which value represents what. For example pig[1] is it a tile sized value or pixels?

old Re: Pig script

kalis
User Off Offline

Quote
ok here
1
2
3
4
pig = { pigx, pigy}

pig[1] = (map('xsize')*32) / 2
pig[2] = (map('ysize')*32) / 2

old Re: Pig script

mafia_man
User Off Offline

Quote
Your code is totally brainfuck I don't understand what's it going to do.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
check_x = math.floor(pig[1] / 32);
	check_y = math.floor(pig[2] / 32);
	
	if check_x < map("xsize") and check_y < map("ysize") then
		if tile(check_x, check_y, "walkable") then
			pig[1] = check_x * 32 + 16;
			pig[2] = check_y * 32 + 16;
			rot_change = 0;
		else
			pig[1] = fix_x;
			pig[2] = fix_y;
		end
	end
	
	imagepos(pig.img, pig[1], pig[2], autorot);

old Re: Pig script

EngiN33R
Moderator Off Offline

Quote
Why do you perform the tile to pixel conversion on pixel coordinates? According to your second post, the position is the middle of the map in pixels, yet you multiply that position by 32 and add 16 as if it were in tiles. Again, as said earlier, without the full code we aren't much help.

old Re: Pig script

kalis
User Off Offline

Quote
ok full script
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
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview