<key[ ]pressed?><< <not> >>
LoneFox wrote:
what do you mean "not right arrow key pressed"?
For the category numbers, there's a thing called "not[blank]". That's where you put in the key[blank] pressed. Now it says "not key[blank] pressed?"
Offline
I made a platforming demo, which you can veiw here. Sprite movement demo
Offline
I'm tring to get gravity to work, help me!
[blocks]
<when green flag clicked>
<forever>
<if><key[ left arrow ]pressed?>
<change x by( -2
<end>
<if><key[ right arrow ]pressed?>
<change x by( 2
<end>
<if><key[ space ]pressed?>
<if><touching color[ black
<if><( <{ Jumping }> <=> 0 )>
<set{ Jumping }to( 1
<repeat( 20
<change y by( 2
<end>
<set{ Jumping }to( 0
<else>
<repeat until><touching color[ black
<change y by( -2
<end>
<end>
<end>
<end>
<when green flag clicked>
<forever>
<if><< <not> <touching color[ black >>
<if><( <{ Jumping }> <=> 0 )>
<repeat until><touching color[ black
<change y by( 2
<end>
<end>
<end>
<end>
Last edited by ThePCKid (2009-10-19 21:42:28)
Offline
Boopaloo wrote:
Nearly everthing is working, sort of..... but I want the character to chance costumes when he's walking. I've tryed this code:
When right arrow pressed
Forever if <Right arrow pressed>
change x by 3
point in direction 90
Repeat until <NOT right arrow key pressed>
switch to costume 1walk
wait 0.25 secs
switch to costume 2walk
But for some reason it just goes all juddery and doesn't move when I press the arow keys??? Aaaaarrrggg!!! Please help me someone!!!
Instead, you have to do this:
When flag clicked
Forever if key right arrow pressed
point in direction 90
change X by 3
When flag clicked
Forever if key right arrow pressed
next costume
wait 0.25 seconds
What I did differently was that they are 2 seperate scripts. If it is one script, the "wait 0.25 seconds" will cause the entire script to pause, not just the costume change. I also changed some things to prevent bugs/glitches.
Offline
S65 wrote:
Assuming you just want your character to move along flat one-color surfaces with no walls, slopes, or mid-air platforms (walls, slopes and mid-air platforms are where the programming can get complicated), a basic engine allowing for left movement, right movement, and jumping/gravity would work like this:
when green flag clicked
forever
if key left arrow pressed
change x by -2
if key right arrow pressed
change x by 2
if key space pressed
if touching color []
if jumping = 0
set jumping to 1
repeat 20
change y by 2
set jumping to 0
when green flag clicked
forever
if not touching color []
if jumping = 0
repeat until touching color []
change y by -2
(replace color [] with color of platform)
The jumping variable is just a flag to indicate that you're jumping so the gravity script which pulls you down doesn't take place. When space is pressed, it sets the jumping flag to 1, and changes your y position by 2 20 times so that you go up. Then it sets jumping to 0, so the gravity effect takes place, which pulls you down until you're touching the []-color platform.
I'm sorry if I explained this badly, I suck at explaining things.![]()
You have to put
if right arrow pressed
change x by 2
if left arrow pressed
change x by -2
blocks in the jumping repeat block so you can move in the air and don't just jump straght up and down
Offline
Post your project and Ill take a look, check out my platformer "Air" if you need any mroe help!!!!http://scratch.mit.edu/projects/domben/825141
Offline
domben wrote:
Post your project and Ill take a look, check out my platformer "Air" if you need any mroe help!!!!http://scratch.mit.edu/projects/domben/825141
This topic started back in 2007. I think the author has probably figured it out or moved on by now
Offline
S65 wrote:
Assuming you just want your character to move along flat one-color surfaces with no walls, slopes, or mid-air platforms (walls, slopes and mid-air platforms are where the programming can get complicated), a basic engine allowing for left movement, right movement, and jumping/gravity would work like this:
when green flag clicked
forever
if key left arrow pressed
change x by -2
if key right arrow pressed
change x by 2
if key space pressed
if touching color []
if jumping = 0
set jumping to 1
repeat 20
change y by 2
set jumping to 0
when green flag clicked
forever
if not touching color []
if jumping = 0
repeat until touching color []
change y by -2
(replace color [] with color of platform)
You want to see these scripts in action? Go to my project
How to make a platform game. I did change some of the scripts so it would do what I wanted it to do
Offline
http://scratch.mit.edu/projects/NeilWest/892054 this should help
Offline
I believe this topic is rather old and resolved. Perhaps it is time to have it closed.
Offline