hoping on lily pads

DookiDooki Member Posts: 247
edited November -1 in Working with GS (Mac)
Hey-ho,

First off, I had started a thread about moving in fixed increments. Got some great help but had some clarity during the process. Thus the new topic.

OK, My actor (cricket/frog) needs to hop from one lily pad (or leaf) to another. The leaves move around the pond. I'd like to tap on a pad and have the frog jump to that pad, BUT only if the pad is within a certain distance (thus my thread on fixed increment movements).
So in a way, I need my actor to be able to hop to a pad within a certain amount of space. If he jumps and the pad is too far he dies. I am not sure if there is some kind of proximity attribute or not. Or should I be looking at some kind of snap to object attribute?

Thanks folks!

-Dooki

Comments

  • fuzzeemicfuzzeemic Member Posts: 47
    I would think you need to use Pythagoras' Theorem. You can work out the frog's x,y location easily enough and get the x,y for the touch point. See if the distance is outside your max. Just my way I would approach it.

    BTW - what method have you used for the jumping/hopping part. Are you jumping with easing in-out? Interpolate? Move to?
  • firemaplegamesfiremaplegames Member Posts: 3,211
    The "proximity attribute" you're talking about is the magnitude function.
    It measures the distance between two points.

    It is used like this:

    magnitude(abs(myX-frogX),abs(myY-frogY))

    That will give you the distance in pixels between a lily pad and the frog.

    Also, distance needs to be positive. That is what the abs() function is for.

    So in your lily pad actor:

    Rule
    When Touch is Pressed
    -----Change Attribute: self.theDistanceBetweenMeAndTheFrog = magnitude(abs(self.Position.X-game.frogX),abs(self.Position.Y-game.frogY))
    -----Rule
    -----When self.theDistanceBetweenMeAndTheFrog < [some distance in pixels]
    ----------[successful jump! do something.]
    -----Otherwise
    ----------[too far! dead frog.]
  • DookiDooki Member Posts: 247
    Hi-

    this game is a top view layout. So I am not really "hoping" as more snapping or poppng around. If you can imagine the actor will be in one location. You will then tap(or click) in another area and the actor should snap to it and not drift there like with a regular move.

    There is a template that shows you how to snap to a grid. I'd like to able to snap to objects that are moving around. Know what I mean?

    Thanks!
    - Dooki
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    Do what Joe said. In the part about a successful jump use a move to. To do this you will have to create game integer attributes and constrain the x and y of each Lilly pad so your frog will "know" where to move to. I would also add two interpolated for image size (or two change size behaviors) so for the first half of the movement the frog gets bigger and the second half it gets smaller. From the top down view this will look like jumping.
  • DookiDooki Member Posts: 247
    Thanks guys!

    @Joe: So I make a new attribute called "theDistanceBetweenMeAndTheFrog." Will this be a real or integer setting?

    @scitunes: [you will have to create game integer attributes and constrain the x and y of each Lilly pad so your frog will "know" where to move to.] Sorry, I am not clear on this.

    As to the jump images. I have two top view images. Frog sitting and frog stretched out. I was going to use animate. Is this a bad idea?

    -Dooki
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    Actors cannot communicate directly with each other very well so use game attributes as a middle man. So create a game integer attribute called lillypad1x and another called lillypad1y. In lillypad1 constrain lillypad1x to self.positionX and constrain Lillypad1y to self.PositionY. Then have a Boolean game attribute called jumptopad1.

    In lillypad1

    Rule
    When touch is pressed change jumptopad1 to true

    In frog

    When jumptopad1 is true
    Move to (now use the game attributes as the x and y move to coordinates)
  • DookiDooki Member Posts: 247
    - So integer attributes for Lilypad1x and Lilypad1y.
    - Boolean attribute for jumptopad1
    OK, now when you say in lilypad1 constrain to position are you talking about within the actor? Hope so because I do not see how you can apply constraints to game attributes.
    Also, within the actor lilypad1 I have made a rule, but when I apply jumptopad1 I do not see an option to make this "true" in the second field. Do I type this in?

    Lastly, when creating attributes does it matter if the first letter is a capitol? Is this case sensitive?

    Thanks,

    -Dooki
  • DookiDooki Member Posts: 247
    Hey Joe,

    I've been reading your reply and your reply in my other thread. I've noticed something. When creating a rule what is the difference between "change attribute" and "when?" For example:

    -Change Attribute: self.theDistanceBetweenMeAndTheFrog
    -When self.theDistanceBetweenMeAndTheFrog.

    Of course I can find change attribute but I cannot find "when." Is this an attribute? Thanks!

    Dooki
  • firemaplegamesfiremaplegames Member Posts: 3,211
    "When..." is a condition in a Rule. "When All/Any conditions are valid:"...

    The first drop-down menu in a Rule says "Actor receives event" by default. You can change that first drop-down to listen for an attribute instead.

    Events are things like Mouse clicks, Touches, Key presses, Auto-Rotations, etc...

    So you could could have something like:

    Rule
    When All conditions are valid:
    Actor receives event: Mouse is Down
    Destroy Actor

    OR:

    Rule
    When All conditions are valid:
    game.score = 1000
    Destroy Actor

    The first Rule listens for an Event, the second one listens for a specific attribute.

    And you can combine them, like this:

    Rule
    When All conditions are valid:
    Actor receives event: Mouse is Down
    When game.score = 1000
    Destroy Actor

    That would only destroy the Actor when BOTH conditions are true.

    ---

    Change Attribute is a behavior that you drag over from the behaviors list.
  • DookiDooki Member Posts: 247
    WOW Thanks Joe! This helps a lot!
    Funny, I was thinking about my next game and how to complete levels once a certain amount of points are met. You example sheds light on this as well. :-)

    -Dooki
Sign In or Register to comment.