spawn Flies help

What I am trying to accomplish is simple.. Basically I want the flies that the player has missed to come back somehow so that the player has an infinite amount of chances to catch all the flies.

I could do something like this

1
2
3
4
5
6
7
8
function transition_to_left()   
            transition.to(aFly, {time=2000, x = 0, y = aFly.y, onComplete = transition_to_right})
end
 
function transition_to_right()  
        transition.to(aFly, {time=2000, x = 2000, y = aFly.y, onComplete = transition_to_left})
end
transition_to_right()

I'm not sure what you mean.. but you can just do fly.x.. (or whatever your variable) is to the other end of the screen again..
Hope that helps!

Hi Larochepower the issue that is really confusing to me is on about line 53 or so

1
2
3
4
5
6
7
function removeFly(thisOne)
 thisOne:removeSelf()
    flies[thisOne.ID] = nil
 thisOne = nil
 --print("Fly Removed")
 fliesOnScreen = fliesOnScreen - 1
end

I found out what I needed to find out. Thanks for that!

Jake, I told you that you can experiment with the tries variable and line 100 that causes the game to be over.

comment out line 100 and change it to

if fliesOnScreen==0 and fliesCaught==XX then

where XX is the number of flies you need to catch

cheers,

?:)

Oh I get it now!

Thanks.. I'm sorry but I had forgotten you told me that.. This makes a lot more sense

Theres just one more thing that I am not sure how to put in code

1
if theFly.x > 1550 then

in english making the flies hover over the frog when not caught

in english making the flies hover over the frog when not caught

The entire code was written with the fact that the flies will fly from left to the right, so the flies that are reach the end of the screen are killed and new ones spawned.

Yes, you can use the scale with a -ve value to flip them, but a fly doing the moonwalk will look pretty lame. Since you will have to change the direction and so on.

The checkIfAnyFlyIsWithin is a generic routine to check for a fly's x co-ordinate if it falls in a particular range. If it does, it means that the fly can be caught or has been caught

Line 126 removes the fly when it goes off the screen.

If you can manage, then try to add a new field to the fly called direction, so instead of removing the fly at 1550, you just flip the direction and the fly starts to move in the reverse direction. and when it reaches 0, then it starts to move in the reverse direction again.

That way it will ping pong between the screen till it is caught.

Now if you want them to hover and buzz over the frog, like in this video, http://iphone.oz-apps.com/the-first-attempt-at-swarming-behaviour-like that is a totally different thing and beyond the scope of what you are trying to do in that code.

cheers,

?:)

O,o look what I found!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
local xdirection,ydirection = 1,1
local xpos,ypos = display.stageWidth*0.5,display.stageHeight*0.5
local circle = display.newCircle( xpos, ypos, 20 );
circle:setFillColor(255,0,0,255);
 
local tPrevious = system.getTimer()
local function animate(event)
        local tDelta = event.time - tPrevious
        tPrevious = event.time
        xpos = xpos + ( 0.084*xdirection*tDelta );
        ypos = ypos + ( 0.066*ydirection*tDelta );
 
        if (xpos > display.stageWidth - 20 or xpos < 20) then
                xdirection = xdirection * -1;
        end
        if (ypos > display.stageHeight - 20 or ypos < 20) then
                ydirection = ydirection * -1;
        end
 
        circle:translate( xpos - circle.x, ypos - circle.y)
end
 
Runtime:addEventListener( "enterFrame", animate );

or not spawnFlies but replacing circle with flies?

That is another way to do what we've done. That is taking into account that there could be frame drops and the deltaTime is used to catch up on lost frames.

You can try what fits for you.

However, let me also give you an advice, you can go the the market and buy the furniture that you like, but there is no guarantee that they will all look good or fit in well together, so it is best to colour match and style match them while purchasing. What I mean is that you cannot have a Red Ancient wood crafter Sofa with metallic Blue side chairs and an acryllic Green coffee table and Yellow painted walls with a purple sliken rug , etc. They might look good on their own or with the appropriate furniture items. together they might not be such a good idea.

Similarly, when you are trying to add code that you are finding, I would suggest that you try to recreate the whole routine with that code, you cannot just plug in that code into something that works on an entire different principle.

Hope you get what I am saying,

cheers,

?:)

As I was lying in bed I was thinking of how foolish of me to slab some random code on here thinking it would solve my problem because it had something that said xdirection and ydirection on it..

But thats a funny way of putting it.. I'll keep that in mind.

I will also really study what you had suggested previously and try to come up with a solution and post it when I do :)

Thanks for the help

Jake

Jake,
I am not discouraging you from looking at alternatives, even I try to search for the most optimum way to do things, after all there could be someone that has a better way to do things that what we use currently.

However, you have to remember that you cannot have mixed furniture, so if you want to go retro, then go all retro if modern, all modern.

Do what ever you want all the way, not a half hearted patch.

cheers,

?:)

Check it out JayantV!! I figured it out!..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
local k,v
 for k,v in pairs(flies)do
  local theFly = v
   theFly.x = theFly.x + theFly.speed
   if theFly.x > 1550 then
    --theFly.canMove = false
    --flies[k]=nil
    --removeFly(v)
    theFly.speed = -theFly.speed
   -- end
    elseif theFly.x < 0 then
   theFly.speed = -theFly.speed
   
   end
 end
  
end
views:1896 update:2011/10/22 9:46:13
corona forums © 2003-2011