Arrow keys to move and jump. WASD to move the camera. Space to talk to Pico. This project is a tutorial on building scrolling platformers. The code controls jumping, falling, collisions with objects, and scrolling in the x-direction and y-direction. This isn't meant to be a game exactly. I see a lot of questions in the discussion forums about scrolling, so created this project to help show how scrolling is done. Arrow keys to move and jump.
This project uses variables called xVelocity and yVelocity to move Scratch Cat. xVelocity is the speed Scratch Cat is moving in the x-direction. yVelocity is in the y-direction. In the x-direction, when right or left arrows are pressed, Scratch Cat moves 8. If it moves into a platform, it keeps backing up 1 until it is no longer touching. In the y-direction, when up is pressed, Scratch Cat will jump, and its y-velocity becomes 30. Then y-velocity keeps decreasing by 3. So Scratch Cat will move up 27, then 24, then 21 and so on. This creates an effect like gravity. First Scratch Cat is moving up more quickly, then slows down until eventually the y-velocity is 0 (the top of the jump). y-velocity will keep decreasing and become negative, so Scratch Cat moves down. First more slowly, then faster. This continues until Scratch Cat is touching a platform and stops. If Scratch Cat's y-velocity is positive (moving up) and moves into a platform, he is shifted down by 1 until no longer touching. The opposite is true if y-velocity is negative (moving down). He is shifted up by 1 until no longer touching. The scrolling is done by tracking the player's location with the "Player X" and "Player Y" variables. Scratch Cat always stays in the center of the screen; just the variables change. Each of the platform clones has an X location, "my x". Scratch Cat runs in a loop and keeps broadcasting a refresh message. Whenever the platforms receive the message they set their x location to (my x - Player X). So as Player X increases, the x location will decrease, making the platforms move left as the player "moves" right. There is similar logic for setting the platform y-location. I used the black borders to cover platforms at the edge of the screen. Scratch doesn't move the platforms completely off screen, so without the borders it looks weird because the off-screen sprites just sit at the edge. Covering it with the borders hides that strangeness. The platform costumes are created as tiles that are the same size as the scratch screen, which is 480 in the x-direction and 360 in the y-direction. The tiles are laid out in 2 rows and 4 columns (8 costumes in all), and are created as clones with different costumes and x/y locations.