Scrolling Platformer - Vertical Scrolling

Hello,

I’m working with a couple of students to try and create a scrolling platformer in game lab that has both vertical and horizontal scrolling. Thus far we have horizontal scrolling figured out, but the vertical scrolling is vexing us.

We’ve tried many solutions and this is the best we can come up with at this point. It uses the built-in collide function. The problem is that when the player collides with the platform (grass), all of the other platforms in the group move up by a short distance (is this because the collide function makes use of the isTouching code?).

We’ve also tried to code this with static sprites and a scrolling player and camera, but ran into some problems there as well. I’d be interested to hear from anyone who went that route.

Thanks in advance for any ideas you might have. Here is the link to the project:
Scrolling Platformer

Documentation
Code.org

Link: Game Lab - Code.org

@134852e ,

I’m not quite sure what you’re asking.

I’m seeing what you are mentioning regarding the other platforms moving up, but is that what you’re trying to prevent by using .getVelocity 0?

Also, I’m not sure what lines 62 & 63 are trying to do.

I would suggest a few things. Have your students comment the code with what they think the code should be doing. That will make it easier for us to see what they are trying to do and to be able to debug.

They may want to make use of watchers in strategic parts of the code to see if the conditionals are behaving as intended.

The grass must be moving due to the upDate Scroll function, but as to how that is happening, I’m not 100% sure. It would take me some time to break down the program and figure out exactly what their goals are.

Let me know if I’m missing something and/or if the code can be commented, it would greatly help.

Mike

While I agree with @varrience, his way might confuse a beginner programmer.

All you have to do is to use the built-in code.org syntaxes.

if (camera.isActive()) {
    camera.x = player.x;
    camera.y = player.y;
    camera.zoom = 1; //camera attribute
}

As you can see it’s pretty easy to understand for a beginner.

How this works is that it executes those lines of code which focus on the camera on the player’s x and y position and you can change how much camera zoom you want.

Sorry if it sounded wordy as I am tired right now.


I hope this has helped you!

2 Likes

The code is now commented.

By using grass.get(k).velocityY = 0; (line 82) we are trying to prevent the rest of the non-colliding platform from continuing to fall upward. Removing that line, they continue upward after a collision.

Lines 62 and 63 make the player fall. Or rather, after the up key is pressed, it makes the platforms slow to a stop, reverse, and fall upward.

@134852e ,

I’ll try to look at it if I get a minute, but I do like @pluto’s suggestion above of using the camera to help with scrolling. It seems a much simpler solution.

Mike

1 Like

Thanks for your reply, this helps.