This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#26 2008-02-12 19:21:26

Icarlyrocks
Scratcher
Registered: 2007-11-10
Posts: 19

Re: Advanced Programming

Scratch is a tough website to make games like that. I'm beginning to think maybe this isn't possible.

Offline

 

#27 2008-02-13 00:24:04

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Advanced Programming

Take a look around for scratch games that have a ball that does what you want.  The "gravity" tag may help.

I made a rather fancy ball for the pinball game my son and I wrote, which has gravity in addition to being able to bounce off various objects:
http://scratch.mit.edu/projects/kevin_and_abe/54377

Offline

 

#28 2008-02-13 01:19:41

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: Advanced Programming

Icarlyrocks wrote:

Scratch is a tough website to make games like that. I'm beginning to think maybe this isn't possible.

Yes, it is perfectly possible to make a game like that in Scratch, and some ideas how to do the "bouncing off a hand drawn line" part have been discussed in this thread. It is a fine challange for creative thinking (and I'm pretty sure we'll see some intelligent implementations soon enough), so thank you for bringing this subject up for discussion! Maybe you could give it shot yourself.

I tend to agree with Paddle2See (sounds like a limerick...) that "some sort of approximation" will probably be the key for a smooth and successful solution.


Jens Mönig

Offline

 

#29 2008-02-13 02:04:57

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Advanced Programming

It's would be easy to do with circular objects, so perhaps a simplified version of the game coul dbe made where you can only draw dots (which are made of sprites) rather than lines.


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#30 2008-02-13 06:57:19

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: Advanced Programming

I've uploaded the slow (and glitchy) "slope detector" version I experimented with:

http://scratch.mit.edu/projects/Jens/98418

It's just about slope detection, no gravity and no user drawn obstacles (yet).

Unfortunately I also ran into some inconsistent online-behaviour: http://scratch.mit.edu/forums/viewtopic.php?pid=20719#p20719


Jens Mönig

Offline

 

#31 2008-02-13 09:10:36

Icarlyrocks
Scratcher
Registered: 2007-11-10
Posts: 19

Re: Advanced Programming

Using Kevin_Karplus's project, I got it started. Now I need the ball to touch the ground and bounce off. I don't know How to do that.(I'm not very good at scratch.

Offline

 

#32 2008-02-13 11:51:49

EdnaC
Scratcher
Registered: 2007-08-28
Posts: 100+

Re: Advanced Programming

Jens wrote:

... It is a fine challange for creative thinking (and I'm pretty sure we'll see some intelligent implementations soon enough), so thank you for bringing this subject up for discussion! Maybe you could give it shot yourself.

I tend to agree with Paddle2See (sounds like a limerick...) that "some sort of approximation" will probably be the key for a smooth and successful solution.

I think it's actually pretty doable, depending on how accurate you need to be.  These little challenges make it tough to get anything done on my "real" project, so I'm hoping Chalkmarrow or Mayhem will post a solution soon...

Icarlyrocks wrote:

I got it started. Now I need the ball to touch the ground and bounce off.

Kevin's project should be a good guide for you, as it does bouncing from surfaces at angles.  There are lots of (simple) examples in the Gravity to Games gallery:  http://scratch.mit.edu/galleries/view/9206 if you are interested in seeing some different ways to handle gravity, bouncing, jumping, etc.


-MrEd

Last edited by EdnaC (2008-02-13 11:52:57)

Offline

 

#33 2008-02-13 13:10:22

Icarlyrocks
Scratcher
Registered: 2007-11-10
Posts: 19

Re: Advanced Programming

I've got the Main Menu ready, But not the gameplay bacause the ball goes through the ground. I saved my project.

Last edited by Icarlyrocks (2008-02-13 13:13:14)

Offline

 

#34 2008-02-13 13:29:14

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Advanced Programming

EdnaC wrote:

...I'm hoping Chalkmarrow or Mayhem will post a solution soon...
-MrEd

Heh, not till I get the last bugs out of my Ninja sidescroller  wink


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#35 2008-02-16 08:04:31

Icarlyrocks
Scratcher
Registered: 2007-11-10
Posts: 19

Re: Advanced Programming

Acually, I'm getting better at scratch, but I still need someone's help with the gravity ball and surface. I do have a new best game on scratch, but It doesn't have gravity. this is it: http://scratch.mit.edu/projects/Icarlyrocks/100615

Last edited by Icarlyrocks (2008-02-16 08:05:17)

Offline

 

#36 2008-02-19 09:59:35

EdnaC
Scratcher
Registered: 2007-08-28
Posts: 100+

Re: Advanced Programming

I never did look at the the link you posted for what a "gravity ball" is, but put some work into bouncing off a "random" surface.  Many thanks to Jens for his slope detector, I used his technique to find the "normal" to the surface. 

This is preliminary and the code is messy and uncommented, but it works OK if downloaded:

http://scratch.mit.edu/projects/EdnaC/102490

It "hangs" online, but I think I may be able to fix that.  The code can be streamlined to speed it up (I think).  I'm hoping to use the tangent vector to apply spin to the ball, and have the spin effect the bounce.

-MrEd

Offline

 

#37 2008-02-20 00:35:05

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Advanced Programming

EdnaC, you might want to look up the ball in "school Pinball"
http://scratch.mit.edu/projects/kevin_and_abe/54377
or  "mouse round-paddle pong"
http://scratch.mit.edu/projects/kevin_karplus/102125

The ball there bounces off of surfaces pretty well, and there is already code for bouncing off of lines and circles.

Offline

 

#38 2008-02-20 11:44:56

EdnaC
Scratcher
Registered: 2007-08-28
Posts: 100+

Re: Advanced Programming

The challenge Jens and I addressed is bouncing/reflection off of a "random" surface (like something drawn on the background).  The key here is detecting the slope of the unknown surface, once that is determined, the bouncing part isn't an issue.  Chalkmarrow has a very nice demo of the "reflection vector" and an explaination of the vector algebra behind the method.
 
I got ambitious and started fiddling with having the ball also use the tangent direction of the surface (and the associated x and y unit vectors) to apply a spin when it hits, and to alter the direction based on the spin it had before the impact.  This is a "fudge", as this effect would involve inertia and friction but it looks pretty neat (I've just been fiddling with fudge factors to get it looking OK).

I'm not sure what is locking up the on-line version; I added code to hide the ball and un-ghost the sprite if spacebar is pressed, but the Java version on the site hasn't been updated as of yet, so I don't know if that is part of the issue.

-MrEd

Last edited by EdnaC (2008-02-20 12:10:59)

Offline

 

#39 2008-02-20 13:56:58

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Advanced Programming

Sorry, I had misunderstood the goal.

Determining the slope of a drawn surface is an interesting challenge.

I had considered adding a spin variable to the pinball ball, but I had not worked out yet what I wanted it to do
  1) on bounces
  2) on movement when not bouncing.
(Since a pinball is rolling on a surface, spin should affect its movement somewhat.)

For bounces, I was thinking adding a velocity component parallel to the surface proportional to spin, but I haven't figured out how I would want spin to change on a bounce.

For movement on a surface, there should probably be a small acceleration at right angles to the direction of movement, proportional to spin.  I've not tried playing with this yet, but it would be important for a bowling simulation.

Offline

 

#40 2008-02-20 18:59:34

Icarlyrocks
Scratcher
Registered: 2007-11-10
Posts: 19

Re: Advanced Programming

EdnaC's project is a great example! But it lags online. I should test that one out.

Offline

 

#41 2008-02-20 23:21:26

EdnaC
Scratcher
Registered: 2007-08-28
Posts: 100+

Re: Advanced Programming

kevin_karplus wrote:

For bounces, I was thinking adding a velocity component parallel to the surface proportional to spin, but I haven't figured out how I would want spin to change on a bounce.

For "BouncingBall", I found the angle of the normal using an adaptation of the (rotating sprite) method that Jens used.  After rotating (and color sensing) to "find" the surface, the sensor sprite turns 90 degrees and records the Tangent direction, then another 90 to record the Normal direction.

The bounce part of "Bouncing Ball" is "real", in that it uses vector algebra to find the reflection vector.  I also (fudged) spin by:

Recording the "OldSpin"

Setting the new spin (after the bounce) by multiplying "VdotNormal" (how hard the ball hit the surface) by the X component of Velocity * X component of the Tangent vector + Vy * Tangent_Y.

Using the OldSpin to alter Vx and Vy of the reflected Ball Velocity Vector.  (Same as setting the new spin, but with a lesser fudge factor).

Both the "Spin" and the effect of the "OldSpin" needed fudge factors.  Also, Vx, Vy and Spin get some damping applied after each bounce.  Without fudging and damping, the "Flubber Effect" was making the ball velocity/spin go ballistic.

For some reason, the latest changes made the project start to work OK on-line, whereas it "locked up" previously.  I still see some "odd" bounces in the Java version that don't show up in Scratch.  I wonder if trig functions aren't mapping correctly from Scratch to Java?

-MrEd

Last edited by EdnaC (2008-02-20 23:23:08)

Offline

 

#42 2008-02-24 13:46:37

supergogeta
Scratcher
Registered: 2008-02-24
Posts: 1

Re: Advanced Programming

how to make a game like super mario where u can jump and when u arrive to the border of the stage u go  to an other stage.....

Offline

 

#43 2008-03-02 06:56:35

Dibbo222
Scratcher
Registered: 2007-11-03
Posts: 100+

Re: Advanced Programming

this is how to move right

<when green flag clicked>
<forever if><key[ right ]pressed?>
<change x by( 3 )

i thought i should put some scripting here so i did something simple


The biggest tower defense game on Scratch?
http://scratch.mit.edu/projects/Dibbo222/929092

Offline

 

#44 2008-03-02 10:13:26

Heybrian
Scratcher
Registered: 2007-12-05
Posts: 100+

Re: Advanced Programming

yes spnce is right dont do this


      <when[right]key pressed>
      <change x by(3


      Its not smooth if you do "when blah pressed" you have to do "forever if"


Black Mesa. go here to get a game 10 times better than SN or FW.  http://scratch.mit.edu/galleries/view/10650
Smiley! copy and paste these into your post or signature!  smile   sad    yikes                 big_smile     wink    tongue    hmm    neutral   cool   lol   mad   roll

Offline

 

#45 2008-03-02 20:48:37

the_hack
Scratcher
Registered: 2007-08-25
Posts: 5

Re: Advanced Programming

Question:

I am embedding a scratch project into a rails web app.  I want my website to reward the user when they finish playing the game.

My first thought was getting scratch to use hyperlinks, but I totally understand and agree that wouldn't be kid-safe.

Is there any other way I can get my website (with javascript or something) to monitor and what is going on in the scratch game and respond?

Or, Jens, would it be possible for you to include hyperlinking in chirp?

Last edited by the_hack (2008-03-03 12:41:30)

Offline

 

#46 2010-02-28 11:32:44

seagoon
Scratcher
Registered: 2009-07-20
Posts: 2

Re: Advanced Programming

archmage wrote:

Ok people I will tell you how to implement gravity!

The way I implement gravity is very simple and logical and you probally won't think gravity is such a big deal anymore.

// First create a local variable on your sprite called yVelocity

Then put this script into your sprite.

<when green flag clicked>
<set{  yVelocity}to(0
<forever>
<change{ yVelocity }by(-1
<change y by( yVelocity

//Now that wasn't so hard was it?


Now to jump we invert gravity.

<when[ up ]key pressed>
<set{  yVelocity}to( 10

Controlling x and y velocity is an important of game design and it's good to learn about it  smile

i try that but my sprite just flies upwards and doesn't come down... if i press up he just go's faster...

Offline

 

#47 2010-02-28 12:59:20

billyedward
Scratcher
Registered: 2008-01-03
Posts: 500+

Re: Advanced Programming

funkymonkey wrote:

archmage wrote:

Ok people I will tell you how to implement gravity!

The way I implement gravity is very simple and logical and you probally won't think gravity is such a big deal anymore.

// First create a local variable on your sprite called yVelocity

Then put this script into your sprite.

<when green flag clicked>
<set{  yVelocity}to(0
<forever>
<change{ yVelocity }by(-1
<change y by( yVelocity

//Now that wasn't so hard was it?


Now to jump we invert gravity.

<when[ up ]key pressed>
<set{  yVelocity}to( 10

Controlling x and y velocity is an important of game design and it's good to learn about it  smile

but how do you make it bounce?

Negate velocity y.
So if it equals -10, change it to 10.
If you want it to bounce less high, then change it to ((-1)-(yVel)), so that from -10 it turns to 9.


"I'd love to change the world, but they haven't released the source code yet."
Check out the latest version of Streak --> http://billy.scienceontheweb.net/Streak

Offline

 

#48 2010-02-28 13:25:36

seagoon
Scratcher
Registered: 2009-07-20
Posts: 2

Re: Advanced Programming

archmage wrote:

Ok people I will tell you how to implement gravity!

The way I implement gravity is very simple and logical and you probally won't think gravity is such a big deal anymore.

// First create a local variable on your sprite called yVelocity

Then put this script into your sprite.

<when green flag clicked>
<set{  yVelocity}to(0
<forever>
<change{ yVelocity }by(-1
<change y by( yVelocity

//Now that wasn't so hard was it?


Now to jump we invert gravity.

<when[ up ]key pressed>
<set{  yVelocity}to( 10

Controlling x and y velocity is an important of game design and it's good to learn about it  smile

ok, i got it but my sprite just falls down to the bottom of the screen. i want a floor. also i set my walking script like this

<when[ right arrow ]key pressed>
<point in direction( 90 )
<switch to costume[ right leg ]
<move( 10 )steps>
<wait( 0.2 )secsc>
<switch to costume[ left leg ]
<move( 10 )steps>
<wait( 0.2 )secsc>
<switch to costume[ standing ]

so when i jump, if i try to go right or left then the sprite moves his legs in mid-air. can you help me? (:     smile

Offline

 

Board footer