Author Topic: Thoughts of a newcomer  (Read 5273 times)

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Thoughts of a newcomer
« Reply #15 on: 2008-03-09, 09:12:05 AM »
Indeed. The Player Sprite's third rule (Second in the collapsed list) is wrong.  Tanja is exactly correct.
Edward Dassmesser

Joe

  • Visitor
  • *
  • Posts: 10
    • View Profile
    • Email
Re: Thoughts of a newcomer
« Reply #16 on: 2008-03-09, 05:06:06 PM »
THANKYOU EVERYONE

Now just so everyone knows, these are the rules you need to make a left/right sprite that jumps, like Mario, etc.

Firstly you need two states, a left and a right state. If you rename Norm0 in the template you made to Right, then choose another state where it points left, rename that Left.

To make the sprite stick to the ground instead of being able to fly, add gravity. This is a rule named Gravity. Select "Do" and "AlterYVelocity" and add ".4" into the delta box. You'll also need three rules called "if moving left", "if moving right" and "if pressing up". I'll go through these one at a time, as they all have subrules which you'll need to add.

Make a rule called "if moving left" and select "if" and "IsInputPressed". Then from the Input box, select "SpriteBase.InputBits.Left" and set Initial Only to "false". If it was true, you would only be able to move one "step" at a time, setting it to false means if you hold down the key, the player will move along until you let go of the button.

This rule is a part of "if moving left" so make sure it is nested. Make this rule "and facing right" then select "and" and "IsInState". In First State, select "(int)Sprites.Player.State.Right" and the same for Last State.

This third rule is also part of "if moving left" and is the last one to be included there. Make a new rule called "then face left" select "do" and "SwitchToState". In the State box, select "(int)Sprites.Player.State.Left" and in Alignment select "RelativePosition.CenterMiddle" and tick the box "end if/while". What we've just done is told the player to move left when we press left. The second rule checks if it is facing right and the third turns the sprite to face left before walking.

In order to move right, we do the same things except replace Left and Right and vice verca in all the rules. Here is what to do anyway, incase you need it.

Make a new rule called "if moving right" and select "if" and "IsInputPressed". From Input select "SpriteBase.InputBits.Right" and InitialOnly is "false".

Create a new  rule (a sub-rule of "if moving right") and name it "and facing left" then select "and" and "IsInState". From both FirstState and LastState, select "(int)Sprites.Player.State.Left".

Create a new rule (a sub-rule of "if moving right") and name it "then face right" and select "Do" and "SwitchToState". From State select "(int)Sprites.Player.State.Right" and from Alignment, "RelaticePosition.CenterMiddle".

In your inertia rule you'll need "do" and "reactToInertia" selected. From RetainPercentVertical, type 100. From RetainPercentHorizontal, type 80.

If this isn't going right, I have two extra rules which I'm not sure what they do (can someone help?). One is called "Rule 1" and has "Do" and "AlterYVelocity" selected. In delta, it has "0.1"

The other rule is named "Rule 3" which has "do" and "AccellerateByInputs" selected. In Accelleration, have "10". Then in Max have "5" and in HorizontalOnly, select "true".

This should result in having a left-right jumping sprite.

If anyone out there wants to follow the first tutorial, then inserting these rules, please do so we can clean up the explanations and sticky this somewhere. I'm certain other people will want to know.

Cheers.

[edit] There is an error in there somewhere which allows you to jump infinitely high if you press up over and over again in quick succession. After figuring all that out, I'm a little fatigued so I'm taking a break. If anyone else can spot the error (or can think of a quick solution) please go ahead and do so.
« Last Edit: 2008-03-09, 05:46:02 PM by Joe »

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Thoughts of a newcomer
« Reply #17 on: 2008-03-09, 06:35:47 PM »
Isn't it easier to just import the player sprite and delete what you don't need?

Joe

  • Visitor
  • *
  • Posts: 10
    • View Profile
    • Email
Re: Thoughts of a newcomer
« Reply #18 on: 2008-03-09, 06:56:37 PM »
Instead of making a game, wouldn't it be easier to open SHFL and just look at it?

Importing the player sprite might be easier, but its not a way to do it yourself. When I first imported it, I got so many errors I wanted to cry. So with tweaking and attempts and such, the above is what I came up with for a barebones typical player sprite. Note that most/all of the rules are based on the blob in SHFL... but this tells someone what they do need to get some basic play going on.

You can say delete what you don't need, but for someone who doesn't know what they don't need, thats a scary task... "What if I mess up" "what if i delete the wrong thing?" "how do i know what this one does anyway" were typical things that I thought of while attempting to go at it. Usually this was followed by "Why isn't it easier?" "Why doesn't someone just tell me how to do it?" The only thing that kept me going was the idea that someone else would be in my position and would want to know. ie, guy doesn't know SGDK and wants to make a jumping sprite but doesn't know how.

The above says how, hopefully in a fairly followable manner.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Thoughts of a newcomer
« Reply #19 on: 2008-03-09, 08:26:34 PM »
Good point.  Thanks for providing the info from a newcomer's perspective.  If I had tried to write it, it would have been pages and pages long because I wouldn't know which details were important to explain, so I would have tried to include everything, and then it would have been too long for anyone to follow.  I hope you find the effort of learning this worthwhile and that things are getting easier as you go along.

To attempt to address your unanswered questions:

1) Rule 1: I don't know why there would be another AlterYVelocity in addition to the .4 one you already have for gravity.  Maybe you kept one from the tutorial and one from teh sample project?  You only need one.
2) Rule 3: AccelerateByInputs allows the sprite to move in response to the inputs being applied to the sprite.  For example, if the player is pressing Left, and the player's input is mapped to this sprite, then AccelerateByInputs will cause the sprite to accelerate 1 pixel per frame per frame if you pass 10 tenths-of-a-pixel as the first parameter.  (You know how to find out all the details about what all these functions do right?)
3) Jumping: Did you take a close look at the player sprite in creating the rules for jumping?  The important parts are a) If Blocked(Down) or IsRidingOnPlatform (to make sure they can't jump in the middle of the air) then set the y velocity (dy) to a negative number like -10 (using the "=" function).
« Last Edit: 2008-03-09, 08:39:39 PM by bluemonkmn »

Joe

  • Visitor
  • *
  • Posts: 10
    • View Profile
    • Email
Re: Thoughts of a newcomer
« Reply #20 on: 2008-03-09, 08:38:01 PM »
As I become more versed in the ways of making a simple game, I'll post back about how to do simple stuff, which hopefully will be along the same lines as what another person in the same situation would be attempting things.

Still not sure about what those two "extra" rules up there do, and how to get the jump to only work from the ground (pressing up three times allows you to jump in the sky three times as high as I'd like) but apart from that, following the tutorial then those steps will get you somewhere.

[edit] "Rule 3" up there is apparently very important. It allows the player to move left and right. I think it tells you how fast you can go sideways. Without it, you won't be going anywhere.
« Last Edit: 2008-03-09, 08:41:38 PM by Joe »

Jam0864

  • Contributor
  • Fanatic
  • **
  • Posts: 744
    • MSN Messenger - marmalade0864@hotmail.com
    • View Profile
    • Jam0864's Content Dump
    • Email
Re: Thoughts of a newcomer
« Reply #21 on: 2008-03-09, 10:16:15 PM »
to stop the played jumping again in mid air, make a rule

if - is blocked - direction, down

then do all the jumping stuff here

Joe

  • Visitor
  • *
  • Posts: 10
    • View Profile
    • Email
Re: Thoughts of a newcomer
« Reply #22 on: 2008-03-09, 11:04:24 PM »
I can't change that back there  :(

Here is updated code:
THANKYOU EVERYONE

Now just so everyone knows, these are the rules you need to make a left/right sprite that jumps, like Mario, etc.

Firstly you need two states, a left and a right state. If you rename Norm0 in the template you made to Right, then choose another state where it points left, rename that Left.

To make the sprite stick to the ground instead of being able to fly, add gravity. This is a rule named Gravity. Select "Do" and "AlterYVelocity" and add ".4" into the delta box. You'll also need three rules called "if moving left", "if moving right" and "if pressing up". I'll go through these one at a time, as they all have subrules which you'll need to add.

Make a rule called "if moving left" and select "if" and "IsInputPressed". Then from the Input box, select "SpriteBase.InputBits.Left" and set Initial Only to "false". If it was true, you would only be able to move one "step" at a time, setting it to false means if you hold down the key, the player will move along until you let go of the button.

This rule is a part of "if moving left" so make sure it is nested. Name this rule "and facing right" then select "and" and "IsInState". In First State, select "(int)Sprites.Player.State.Right" and the same for Last State.

This third rule is also part of "if moving left" and is the last one to be included there. Make a new rule called "then face left" select "do" and "SwitchToState". In the State box, select "(int)Sprites.Player.State.Left" and in Alignment select "RelativePosition.CenterMiddle" and tick the box "end if/while". What we've just done is told the player to move left when we press left. The second rule checks if it is facing right and the third turns the sprite to face left before walking.

In order to move right, we do the same things except replace Left and Right and vice verca in all the rules. Here is what to do anyway, incase you need it.

Make a new rule called "if moving right" and select "if" and "IsInputPressed". From Input select "SpriteBase.InputBits.Right" and InitialOnly is "false".

Create a new  rule (a sub-rule of "if moving right") and name it "and facing left" then select "and" and "IsInState". From both FirstState and LastState, select "(int)Sprites.Player.State.Left".

Create a new rule (a sub-rule of "if moving right") and name it "then face right" and select "Do" and "SwitchToState". From State select "(int)Sprites.Player.State.Right" and from Alignment, "RelaticePosition.CenterMiddle". Tick the End If/While box.

Create a new rule called "if pressing up" you can also call this "jump" or something more descriptive. Select "if" and "IsInputPressed" then in Input select "SpriteBase.InputBits.Up" and in InitialOnly, select "true".

Add another rule (this is a subsection of the "pressing up" rule) call this "on ground" or something. select "And" and "Blocked". In the direction, select "SpriteBase.Direction.Down". This checks if you can't move down (because you're on the ground) and allows you to jump. If you're in the air, you can move down, and thus won't be allowed to jump.

Add another rule (this is also a subsection of the "pressing up" rule) call this "accellerate" or whatever you like. Select "Do" and "=" (that's the equal sign, just one, not two of them with no other text) and in Value, select "-10" (thats minus ten) and in Output To: select "dy" and tick the end if/while box

In your inertia rule you'll need "do" and "reactToInertia" selected. From RetainPercentVertical, type 100. From RetainPercentHorizontal, type 80.

There is  another rule, it can be named "Walk" which has "do" and "AccellerateByInputs" selected. In Accelleration, have "10". Then in Max have "5" and in HorizontalOnly, select "true". This tells the sprite how fast to move when you press any of the buttons.

This should result in a left/right jumping sprite.

If it doesn't work, I have an extra rule which I'm not sure what it doed (can someone help?). One is called "Rule 1" and has "Do" and "AlterYVelocity" selected. In delta, it has "0.1"

This should definately result in having a left-right jumping sprite.

If anyone out there wants to follow the first tutorial, then inserting these rules, please do so we can clean up the explanations and sticky this somewhere. I'm certain other people will want to know.

Cheers.

[edit] There is an error in there somewhere which allows you to jump infinitely high if you press up over and over again in quick succession. After figuring all that out, I'm a little fatigued so I'm taking a break. If anyone else can spot the error (or can think of a quick solution) please go ahead and do so.
[edit] In the first run, I forgot to add the jump information here. Thanks to Jam0864 for suggesting a fix anyway and allowing progess to be made. You can now jump only when on the ground.
Note: In the second rule of "if pressing up", if you select select "And" and "TouchTiles". Then in the category, select "TileCategoryName.Solid", you should be able to climb walls by walking up to them and pressing up, repeatedly.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Thoughts of a newcomer
« Reply #23 on: 2008-03-10, 05:39:11 AM »
Let me explain AccelerateByInputs a bit more clearly.  This is the main rule that tells the sprite to accelerate in response to the inputs being pressed.  You wouldn't have to make the sprite move; you could make it turn instead (like a rotating sprite does).  AccelerateByInputs affects the dx and dy (horizontal and vertical velocity) of the sprite based on the inputs that are being pressed.  Yes, it also determines how much the inputs affect the acceleration (how fast it goes), but it is also the primary reason the sprite responds to inputs.  Another thing that is responsible for sprite movement that I don't see mentioned is MoveByVelocity.  Here are the main functions involved in movement:

1) MapPlayerToInputs - associates (copies) a player's inputs to those of a sprite.
2) AccelerateByInputs - associates the inputs of a sprite with it's velocity directly (left = accelerate left, right = accelerate right)
3) MoveByVelocity - causes the sprite to actually move in response to its current velocity setting.  This is separate from acceleration so you have an opportunity to ReactToSolid after accelerating, but before moving.

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: Thoughts of a newcomer
« Reply #24 on: 2008-03-10, 05:53:35 AM »
it is very good that joe is showing us how difficult the beginning is for a newbie. it is even more cooler that he took the time to write this tut. i hope it will go into the help files soon.