English Pig script

9 replies
Goto Page
To the start Previous 1 Next To the start
21.10.12 08:32:58 am
Up
kalis
User
Offline Off
hello every one
Code:
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 ?
21.10.12 08:59:49 am
Up
mafia_man
User
Offline Off
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?
21.10.12 09:02:23 am
Up
kalis
User
Offline Off
ok here
Code:
1
2
3
4
pig = { pigx, pigy}

pig[1] = (map('xsize')*32) / 2
pig[2] = (map('ysize')*32) / 2
21.10.12 09:03:17 am
Up
Infinite Rain
Reviewer
Offline Off
I think it's better for you to show us the full script.
A thousand may fall at your side, ten thousand at your right hand, but it will not come near you. You will only look with your eyes and see the recompense of the wicked. - Psalm 91:7-8 ESV
21.10.12 09:06:13 am
Up
mafia_man
User
Offline Off
Your code is totally brainfuck I don't understand what's it going to do.

Code:
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);
21.10.12 09:06:49 am
Up
EngiN33R
Moderator
Offline Off
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.
I code, therefore I exist. | Visit my blog for Lua tips and other interesting info
21.10.12 09:10:15 am
Up
kalis
User
Offline Off
ok full script
Code:
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
21.10.12 06:54:22 pm
Up
Me Gusta
User
Offline Off
To enable this pig system to who mod?
22.10.12 05:12:37 am
Up
kalis
User
Offline Off
what you mean ?
31.10.12 03:39:18 pm
Up
Assasin ezio
User
Offline Off
no
To the start Previous 1 Next To the start