Could someone help me with this? (video included)

Hey,

Got my first game almost created in 3 days with having no previous lua knowledge or even any knowledge of programming so I think I’m doing pretty well.

I’ve uploaded a video to YouTube here explaining my problem:

http://www.youtube.com/watch?v=Ap8TqbOlHto

If anyone can help me, it would be great!

Thanks
Ace [import]uid: 9899 topic_id: 2732 reply_id: 302732[/import]

Hi Ace,

Could you post your basic code in this thread so we can determine what’s happening during run time? The video helps me see it in action, but the code (in the video) is blurry so I can’t see what you’ve typed…

Based on your design protoype, however, I might suggest using a “Sensor” object instead of asking some action to occur when the scissors reach x=300. A sensor makes an immediate call to a Listener when a specified object enters its range… it’s basically an invisible physics body which you set as a sensor, so it doesn’t react physically with other objects, only as a shape that senses overlap. You would position that shape somewhere around the sheep to sense objects that approach it.

You can find the details for Sensor under the “Physics Bodies” section of the documentation.

Brent
[import]uid: 9747 topic_id: 2732 reply_id: 8205[/import]

http://ellerker.net/files/Doodle%20Sheep.zip

Hey Buddy,

The zip is above… Thanks a lot

Ace [import]uid: 9899 topic_id: 2732 reply_id: 8268[/import]

Ok got the solution, consider the following

  1. Use terminal to monitor the output, the code is throwing up errors

  2. Using terminal you could put a print statement inside the if statement and see whats happening when its called, if you do you will notice that its being called for ever frame after the scissors pass the marker. This resets the transition every frame and its only allowed to actually start when you move the scissors back to the right of the screen and the if statement is no longer true

  3. Set a flag like sheep.animating = true and check for that so it doesn’t fire every fame and once the scissors are reset back to the right you can set the sheep.animating = false, or do that at some other logical point [import]uid: 5354 topic_id: 2732 reply_id: 8274[/import]

Hey there,
I glanced at the code you zipped. If I understand the game design, the user clicks on the appropriate color blob matching the scissor color (as written in the Instructions). If the choice/colors match, the sheep “jumps” right before the scissors reach him. Is that correct?

If so, a sensor is a good option. You just place it below (or above) the sheep, but you set it as invisible during game play:

local jumpTrigger = display.newRect( sheep.x, sheep.y, 100, 100 )  
jumpTrigger:setFillColor( 255, 0, 0, 50 )  
--jumpTrigger.isVisible = false --un-comment this later to make this sensor invisible  
physics.addBody( jumpTrigger, { isSensor = true } )  
jumpTrigger.bodyType = "kinematic"  
jumpTrigger.collision = sheepJump --the function to call when the sensor is "activated"  
jumpTrigger:addEventListener( "collision", jumpTrigger )  

Somewhere above that in your code, you write the jump function:

local function sheepJump( self, event )  
-- do whatever here. "self" is the sensor. "event.other" specifies the scissors, or whatever collided with the sensor  
end  

This should work, but I haven’t tested it. I just hacked out this basic code and there might be some errors, but this is the basic idea. Obviously you can adjust the numbers and positioning of the sensor and whatever else.

You might also need to define the proper Collision Groups for the sensor and the scissors. All of that is detailed in the Collisions section of the Corona documentation.

Let me know if that helps,
Best of luck!

Brent

[import]uid: 9747 topic_id: 2732 reply_id: 8282[/import]

Hey Brent

Tried your idea but still had no luck (thanks a lot for the suggestion though). I saw where you were coming from, the scissors do not have physics properties though.

I’ve re-coded everything and done another video to show what my problem is now. If you could take a look I’d be grateful.

Code:
http://instantmashgames.com/files/Doodle%20Sheep.zip

Video:
http://www.youtube.com/watch?v=Dla134Mq9VA

Ace [import]uid: 9899 topic_id: 2732 reply_id: 8895[/import]

Hi Ace,
I am new to corona, so not 100% about this, but from what I see in your code is that you have the logic all enclosed into the new() function, don’t you think the logic has to be checked for on every frame, like on enterFrame?

secondly, I am still trying to get my head around the co-ordinates, and I just wanted to ask, wouldn’t 0 be the left hand side x axis? so the maximum x on a iPhone would be 480, so when you are checking for 340 the scissors have already passed 340 in the first few animation moves. The sheep is more like near 0 than 340

does that make sense?

Pressing the wrong button shows the GameOver graphic because it is triggered via an event on the Tap of the button.
cheers,

Jayant C Varma
[import]uid: 3826 topic_id: 2732 reply_id: 8909[/import]

Yeah, have it triggering from main.lua when you press start, so new() function in gameplay.lua is where it’s at

I am totally new to this, so the enterFrame thing you said made no sense haha. Any chance you could explain it a little? That’d be great!

I have it set to iPad co-cordinates and in the config file setting it so that it scales down to iPhone, that’s why 340 pixels is just to the right of the sheep.

Thanks a lot
Ace [import]uid: 9899 topic_id: 2732 reply_id: 8911[/import]

Righto,

first a quick thing on a game module (structure)

--initailize the game  
--setup the sprites  
  
--Start of Loop  
  
 --move player (if keys pressed)   
 --check for collisions  
 --check for other stuff  
  
--LOOP  

Does that make sense to you? if it does, then enterFrame is an event that is called every frame, so in a 60fps game, 60 times in a second.

now, how to achieve that is simple, in the new add a line

Runtime:addEventListener("enterFrame", checkForWin)  

before which of course you need to define a function

local function animate(event)  
 -- place all your conditions here  
 -- they will be checked 60 times a second, how good is that?  
end  

Lastly, your video was playing with an iPhone but you are making the game with co-ordinates for the iPad, rather than hardcoding your co-ordinates, why don’t you set them up to scale accordingly, so get the device you are working with and then set the co-ordinates to check for accordingly.

 local deviceName = system.getInfo("model")  

and based on that you can set the co-ordinates

 local sheepWillGetHitAt=0;  
  
 .  
 .  
 .  
 if deviceName=="iPhone" then  
 sheepWillGetHitAt=10  
 elseif deviceName == "iPad" then  
 sheepWillGetHitAt=340  
 elseif deviceName == "iPhone4" then  
 sheepWillGetHitAt=240  
 else  
 sheepWillGetHitAt=100  
 end  

cheers,

Jayant C Varma [import]uid: 3826 topic_id: 2732 reply_id: 8913[/import]

That’s really helpful! Thanks a lot.

It’s half past midnight here, so I’ll try that in the morning. One thing I have a question about is checkForWin

Is checkForWin the name of a function I’ll have to create that I want checking 60 times a second?

For example, if I wanted the location of the scissors to be checked 60 times a second, would I put the coding for the scissors within a function called checkForWin?

Sorry for my lack of knowledge, I’ve only been programming a week so it’s all new to me. I’ve spent 9 hours + a day learning and been through all the documentation and demo games, etc and still learning.

Thanks again
Ace [import]uid: 9899 topic_id: 2732 reply_id: 8915[/import]

Hi Ace,

yes, checkForWin is the name of a function that you need to implement, you can call that anything, I thought that checkForWin was a good name.

You are a veteran at Corona compared to me, I just started yesterday, and am trying to map the language and functions to what I need to get the job done, it is indeed very easy to create a game in Corona.

hope it works out for you, since I am +10:30 from you, will wait to hear if your game went well.

cheers,

Jayant C Varma [import]uid: 3826 topic_id: 2732 reply_id: 8916[/import]

Hi Ace,
I still think a Sensor is the best method for your purposes, versus some kind of Runtime listener. The sensor doesn’t need to be part of a Runtime listener; it “listens” for a collision constantly in the game cycle, so it simplifies the entire process.

You can definitely apply physics to the scissors. Just make sure the scissors do not collide with the sheep (with physics reaction), by using Collision Masks. There is an explanation of this in the “Collisions” section of the documentation. I’m also going to post a useful chart regarding collision filters in the next couple days (a chart that I use for my own reference, which will probably help other people too).

Here’s an exact working copy of a sensor I’m using in my own game (modified just with names that might apply to your game):

local function sheepJump( self, event )  
-- DO SOMETHING  
--"self" is the Sensor  
--"event.other" would be the scissors; you can get info (color, etc.) using this reference  
end  
  
local scissorSensor = display.newRect( mainGroup, [xPos], [yPos], [Xsize], [Ysize] )  
scissorSensor.x = [xPos]; scissorSensor.Y = [yPos]  
scissorSensor:setFillColor( 255, 0, 0, 20 )  
physics.addBody( scissorSensor, { filter=scissorCollisionFilter, isSensor=true } ) --FILTER IS IMPORTANT, please research this!  
scissorSensor.bodyType = "kinematic"  
  
scissorSensor.collision = sheepJump  
scissorSensor:addEventListener( "collision", scissorSensor )  

[import]uid: 9747 topic_id: 2732 reply_id: 8925[/import]

Hi Ace,
What IgnisDesign has suggested in your case might be a much better solution. I was thinking about collisions and IgnisDesgin’s post kind of re-iterated that.

that way if you place a trigger point just before your sheep, the scissor will collide with that trigger and you will know that the scissor has reached the point. so you do not have to hard code the values.

@IgnisDesign
I tried to read up to CollisionFilters but did not find much, however I also tried to read about masks and category, I am a bit confused with that example. What exactly is categoryBits and what exactly is maskBits? How are they determined or set?

cheers,

Jayant C Varma [import]uid: 3826 topic_id: 2732 reply_id: 8926[/import]

Read that sample again with patience and tried to understand it, got the answers to the categoryBits and maskBits. It is so simple and easy. [import]uid: 3826 topic_id: 2732 reply_id: 8927[/import]

This sounds similar to the pockets on the pool table in the sample code SimplePool that is included with Game Edition. [import]uid: 9562 topic_id: 2732 reply_id: 8928[/import]

Raaa, been at it all day and my brain is falling out.

Here’s the new video:

http://www.youtube.com/watch?v=fn54HJd_XHo

And here’s the new code:

http://instantmashgames.com/files/Doodle%20Sheep.zip

Any help would be great.

I’ve tried the rectangle trigger, everything, just can’t get the scissors to trigger the jump function.

Any help will be great
Ace [import]uid: 9899 topic_id: 2732 reply_id: 8959[/import]

Hi Ace,
Will have to look at it tomorrow morning, it’s 2:30 here and I need to sleep, so will catch up tomorrow (for me) and I will have a look.

cheers,

Jayant C Varma [import]uid: 3826 topic_id: 2732 reply_id: 8960[/import]

Im not sure while you are still stuck with this, I provided the solution days ago.

The scissors more x every frame

When they pass x you trigger the jump and set a flag like sheepAnimating = true

The trigger for the jump should be wrapped in an if statement such like,

if ( x \< 150 and sheepAnimating != true ) then  
-- Do jump here  
-- Then set the flag  
sheepAnimating = true  
end  

once the scissors have moved off screen and you reset / place them over to the right, you then set sheepAnimating = false [import]uid: 5354 topic_id: 2732 reply_id: 8961[/import]

Hey Matthew,

I tried setting it to that first of all but for some reason doesn’t work. I have no idea why.

If you could take another look, it’d be great!

Ace [import]uid: 9899 topic_id: 2732 reply_id: 8962[/import]

Email a version without sensors, one that worked like your original and I will have it sorted in about 1hr

matt @ mattpringle.co.uk [import]uid: 5354 topic_id: 2732 reply_id: 8964[/import]