Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////////////////////////////////////////////////
- // Moving platform code
- ///////////////////////////////////////////////////////////////////////////////
- /*
- Note:
- This code assumes that the platform is only travelling
- horizontally or vertically, not both. (Diagonally)
- Diagonal movement would also work in a very similar way
- however a few lines of code would have to be tweaked in
- order to handle each axis individually such as the
- platform against other platform collision code.
- There's also a slight but where the player can sometimes
- jump up through the platform in very specific situations
- but is fixable with another check. Shouldn't matter in
- most games.
- */
- ///////////////////////////////////////////////////////////////////////////////
- // Create event:
- ///////////////////////////////////////////////////////////////////////////////
- // Give the platform a speed to move at.
- hSpeed = 0;
- vSpeed = -1;
- ///////////////////////////////////////////////////////////////////////////////
- // Step event:
- ///////////////////////////////////////////////////////////////////////////////
- // Before moving check if the player is on this platform.
- var playerOnPlatform = place_meeting(x, y - 1, objPlayer);
- // Move the platform by its horizontal and vertical speed.
- x += hSpeed;
- y += vSpeed;
- // Check if the platform has hit another platform of any type.
- if(place_meeting(x, y, objPlatform))
- {
- // If so then move back away from the platform that has
- // been hit.
- x -= hSpeed;
- y -= vSpeed;
- // And reverse the direction that the platform is
- // travelling in.
- hSpeed *= -1;
- vSpeed *= -1;
- }
- // If the platform has successfully moved without a collision
- // and the player is on top then move the player with it.
- else if(playerOnPlatform || place_meeting(x, y, objPlayer))
- {
- // Tell the player to execute the code inside the curly
- // brace brackets.
- with(objPlayer)
- {
- // Move at the same speed that the platform is moving
- // at.
- x += other.hSpeed;
- y += other.vSpeed;
- // Check for collisions with other platforms and if any
- // occur move back to original position.
- if(place_meeting(x, y, objPlatform))
- x -= other.hSpeed;
- if(place_meeting(x, y, objPlatform))
- y -= other.vSpeed;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement