hoping on lily pads
Dooki
Member Posts: 247
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
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
BTW - what method have you used for the jumping/hopping part. Are you jumping with easing in-out? Interpolate? Move to?
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.]
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
@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
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)
- 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
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
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.
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