through wall with transition

Hi everyone

I am using transition to move the snake in snake's game. I use an array to manage parts of the snake. When the snake moving, the postion of part is updated by previous part. But i can't make the snake go through wall . You can view code to understand more trouble.

P/s: you chose "not wall" at game type in Settings .

who can help me? please

Isn't the wall supposed to block the snake? Why do you want to have the snake go through a wall?

Is the issue that you don't want a wall created if "No Wall" is selected? Or that you want the wall still displayed but the snake goes through it?

If you want it displayed but the snake can go through it, I changed this:

1
2
3
4
5
6
7
for i= 1,#blockpoint_x do
                count = count + 1
                blockpoint[count] = display.newImage("image/wall.png",blockpoint_x[i],blockpoint_y[i])
                blockpoint[count].name = "wall"
                if (checkWall ==1) then physics.addBody( blockpoint[count],"static") end
                backGroundGroup:insert(blockpoint[count] )
        end

Thanks. But this is not my issue. In game, when "Not Wall" is selected, all chicks will be disappeared if the snake move up to edges. it is not right. I want to make each of chick disappeared at this edge and appeareared at opposite edge.

I just tested it again and walked off the left and the chicks all disappeared then appeared on the right following the hen.
Then I went off the bottom. They disappeared and reappeared at the top following the hen again.

Am I missing something still?

Or is the issue that they ALL disappear instead of one by one?

yes. Can you make it dissapeared and reappeared one by one?

I'm working on it. It looks like from the code that this pseudo logic is happening:

If hen reaches bottom of the screen, move it to the top and place all chicks above the hen so they will follow down the screen.

Instead of:

If hen reaches the bottom of the screen, move it to the top. If each chick reaches the bottom of the screen, move them one by one to the top only if their .y value >320.

Do you understand what I mean?
I will look at what code can be changed for this.

The problem is they are ALL being moved to the top of the screen when the hen reaches the bottom, rather than checking the .y value of the hen then each of the chicks and only moving the hen OR chicks which reach the bottom.

I replaced this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
                if(self.part[1].direction == "down") then 
                for j = 1,#self.part do
                        if (self.part[j].y > 320) then
                                self.part[j].y = 0
                                function actionDown(partI)
                                        self.part[partI]:removeSelf()
                                        self.part[partI] = newPart("tail")
                                        self.part[partI].x = self.part[1].x
                                self.part[partI].y = 0 - partI * space
                                snake.part[partI].direction = snake.part[partI - 1].predirection
                                snake.part[partI].predirection = ""
                                end
                                --for i=2,#self.part do                         
                                        local timeDelay = timer.performWithDelay(snake.speed, actionDown(j),1)
                                end
                        end
                end

Also, the logic here will depend on if self.part[1].direction continues to be "down". If you change direction once the hen appears at the top, then this may not execute properly.

But part.y is updated by the previous part. So when hens reaches the bottom of the screen,I set the head.y = 0,chicks will be transition immediately from bottom to top because i moving the chick to the previous chicks. this issue is the transition. it need the target to MOVE.

Hi BilBy

do you have another way to solve this problem?..

Maybe comments will help.
You are only checking to see if the hen goes off the screen, then move everything (including hen and all chicks) to the other side of the screen.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
if(self.part[1].direction == "right") then -- if the hen is heading right then
  if(self.part[1].x > 480 ) then -- if the hen has reached the right hand side then
    self.part[1].x = 0 -- hen moves x to 0
    function actionRight(partI) -- start function
        self.part[partI]:removeSelf() -- remove chick
        self.part[partI] = newPart("tail") -- create tail at this spot
        self.part[partI].x = 0 - partI * space -- move chick behind hen
        self.part[partI].y = self.part[1].y -- set y of chick to y of hen
        snake.part[partI].direction = snake.part[1].predirection -- set direction the same as hen's predirection
        snake.part[partI].predirection = "" -- set predirection for chick to nothing
    end
    for i=2,#self.part do -- for each chick                             
    local timeDelay = timer.performWithDelay(snake.speed, actionRight(i),1) -- call function for each chick
        end
    end
end

So if I understand the logic correctly, it says:

If hen reaches right-hand side (480) then move it to the left and after a short delay, move all chicks behind the hen at the left.

Perhaps it would be better to test if each self.part[] hits 480 and move each then to 0.

Right. Problem is it. I can't make the part move one by one when it reach the egde. I was apply your advice, but it dont't work directly.Can you edit code and if it work, please send me all project.

My email : trungnq@ftl.vn

Many thanks.

views:2447 update:2012/2/12 11:34:30
corona forums © 2003-2011