Basically, you have one sprite that has one loop inside of it. During each repetition of the loop, the sprite changes costume and goes to different locations on the screen and stamps. If those different locations are represented by variables, and the variables change as well during the loop, it looks like a moving object.
Here's an example 1s1s pong game I just made up (I haven't tried it, so don't count on it working).
Let's say the ball is 30 x 30 pixels, and the paddle is 80 pixels wide.
when gf clicked set [Paddle.X v] to (0) set [Paddle.Y v] to (-150) set [Ball.X v] to (0) set [Ball.Y v] to (0) set [Ball.Speed v] to (10) set [Ball.InitialDirection v] to (pick random (-180) to (180)) set [Ball.Velocity.X v] to (([cos v] of (Ball.InitialDirection)) * (Ball.Speed)) set [Ball.Velocity.Y v] to (([sin v] of (Ball.InitialDirection)) * (Ball.Speed)) forever change [Ball.X v] by (Ball.Velocity.X) change [Ball.Y v] by (Ball.Velocity.Y) if <key [right arrow v] pressed?> change [Paddle.X v] by (5) end if <key [left arrow v] pressed?> change [Paddle.X v] by (-5) end if <(Paddle.X) > (200)> set [Paddle.X v] to (200) end if <(Paddle.X) < (-200)> set [Paddle.X v] to (-200) end if <(Ball.Y) < (Paddle.Y)> if <((Ball.X) - (Paddle.X)) < (40)> set [Ball.Y v] to (Paddle.Y) set [Ball.Velocity.Y v] to ((-1) * (Ball.Velocity.Y)) else stop all end end if <(Ball.Y) > (165)> set [Ball.Y v] to (165) set [Ball.Velocity.Y v] to ((-1) * (Ball.Velocity.Y)) end if <(Ball.X) > (225)> set [Ball.X v] to (225) set [Ball.Velocity.X v] to ((-1) * (Ball.Velocity.X)) end if <(Ball.X) < (-225)> set [Ball.X v] to (-225) set [Ball.Velocity.X v] to ((-1) * (Ball.Velocity.X)) end clear go to x: (Paddle.X) y: (Paddle.Y) switch to costume [Paddle v] stamp go to x: (Ball.X) y: (Ball.Y) switch to costume [Ball v] stamp end
Offline
Set up the positions as variables then do what you would regularly do except stamp when you need to.
Offline
Here is a 1s1s launcher game that I made:
http://scratch.mit.edu/projects/darthvader111/1124532
~Any ideas you got from this? Scripts?
Last edited by darthvader111 (2012-04-29 00:50:53)
Offline
amcerbu wrote:
Basically, you have one sprite that has one loop inside of it. During each repetition of the loop, the sprite changes costume and goes to different locations on the screen and stamps. If those different locations are represented by variables, and the variables change as well during the loop, it looks like a moving object.
Here's an example 1s1s pong game I just made up (I haven't tried it, so don't count on it working).
Let's say the ball is 30 x 30 pixels, and the paddle is 80 pixels wide.when gf clicked set [Paddle.X v] to (0) set [Paddle.Y v] to (-150) set [Ball.X v] to (0) set [Ball.Y v] to (0) set [Ball.Speed v] to (10) set [Ball.InitialDirection v] to (pick random (-180) to (180)) set [Ball.Velocity.X v] to (([cos v] of (Ball.InitialDirection)) * (Ball.Speed)) set [Ball.Velocity.Y v] to (([sin v] of (Ball.InitialDirection)) * (Ball.Speed)) forever change [Ball.X v] by (Ball.Velocity.X) change [Ball.Y v] by (Ball.Velocity.Y) if <key [right arrow v] pressed?> change [Paddle.X v] by (5) end if <key [left arrow v] pressed?> change [Paddle.X v] by (-5) end if <(Paddle.X) > (200)> set [Paddle.X v] to (200) end if <(Paddle.X) < (-200)> set [Paddle.X v] to (-200) end if <(Ball.Y) < (Paddle.Y)> if <((Ball.X) - (Paddle.X)) < (40)> set [Ball.Y v] to (Paddle.Y) set [Ball.Velocity.Y v] to ((-1) * (Ball.Velocity.Y)) else stop all end end if <(Ball.Y) > (165)> set [Ball.Y v] to (165) set [Ball.Velocity.Y v] to ((-1) * (Ball.Velocity.Y)) end if <(Ball.X) > (225)> set [Ball.X v] to (225) set [Ball.Velocity.X v] to ((-1) * (Ball.Velocity.X)) end if <(Ball.X) < (-225)> set [Ball.X v] to (-225) set [Ball.Velocity.X v] to ((-1) * (Ball.Velocity.X)) end clear go to x: (Paddle.X) y: (Paddle.Y) switch to costume [Paddle v] stamp go to x: (Ball.X) y: (Ball.Y) switch to costume [Ball v] stamp end
Whew! That scratchblocking must've taken a while!
when i receive [1s1s scratchblocks] switch to costume [script] wait [a really really long time] seconds stamp say [that took a while!]
Offline
Just so you know (as you probably do) 1s1s Doesn't need to be a looooooong script and stuff it can just be
[scratchblock]
when space clicked
change colour!!
[/scratchblocks]
Offline