Give Points to player, who moves

MarcoColMarcoCol Member, PRO Posts: 279
edited August 2012 in Working with GS (Mac)
Hi,

I want that the player collect/get points for each (for example) 20 Pixels he moves high, he should get 10 points.
And if he goes down, then the highest number of points (for example at 80 Pixels height, he has 40 points) should be still displayed.
Did you have an idea?

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    It sounds like you want the player's points to be constrained to the height of the player's actor. If that's incorrect, let me know. Otherwise, just do:

    Change attribute self.originalY (real) to self.position.Y <-- this goes at the top of the player actor's rules
    Constrain attribute game.points to ceil((self.positionY-self.originalY)/2).

    This will add a point each time the player moves up 2 pixels, so if you want the scoring to go 0...10...20 or 0...20...40, we can work on that next.

    You may need to add some conditions (Rules) if you want to avoid negative scores. You could wrap the Constrain behavior in a When self.position.Y > self.originalY rule.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • MarcoColMarcoCol Member, PRO Posts: 279
    Right.
    I create two attributes (real) "self.originalY" and "self.position.Y".
    Also I set first the attribute self.originalY for example to "160".
    I also have the "game.points" as integer.
    Then I put at the top of the player actor the rule, as you write.

    But with points, nothing happens. So for each 10 pixel I want the scoring go up for 10 points.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Can you post a screenshot of your rules?

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • MarcoColMarcoCol Member, PRO Posts: 279
    how can I post a screenshot?

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @MarcoCol, you'll need to upload the image(s) to a file hosting service such as DropBox or MediaFire and then paste the upload URL into the forum code, which looks like this:

    < img src="http://www.URL.com">

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • MarcoColMarcoCol Member, PRO Posts: 279
    Here you go:

    image
    image
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Your Constrain Attribute behavior is not using the formula I suggested, which should be self.position.Y - self.Start-PlayerY. Your screenshot shows game.Current-PlayerY - self.position.Y, which would only work if (a) you are constraining game.Current-PlayerY to self.position.Y and (b) the player is moving down the whole time. You also left out a set of parentheses which is crucial because in your formula, you are dividing self.position.Y by 2 but in my formula, I am dividing the difference by 2.

    As a side note, I'd recommend NOT using dashes in your attribute names. It will work fine, but it's confusing to see game.Current-PlayerY-self.position.Y because the dash looks like a minus (subtraction) symbol.

    Also, how do you know it's not working? Have you created an actor with a DisplayText behavior to show game.Score while you're playing the game?

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • MarcoColMarcoCol Member, PRO Posts: 279
    Ah, ok. That was a mistake. It now works. I think there is no need for making steps of the points bigger. I think that is ok. Thank you for the tips of the naming the attributes. That makes sense.
    So now it worked. I devided by 10. And when player starts at X160px, he just has 16 points, but he should have only 0.
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited August 2012
    As tatiang said to use other numbers it would be a different formula. Take some time to think about the example you were shown and try to figure out how to make it work. This is how you learn GS not just copying but understanding what the formula means.
Sign In or Register to comment.