Implementing moving blocks

Implementing moving blocks

Postby ChristianCareaga » Sun Dec 08, 2013 5:32 am

Im trying to add moving blocks to my platformer, but i having some trouble, I put the blocks in the solid block sprite list so collision is detected, but that means i have to update the solid blocks (Most of them don't move, except for the moving ones), So the player stops while on top of them but he doesn't travel with the blocks. I want him to stay on the blocks

The way i differentiate the normal blocks from the moving blocks is a class variable called block_type, so when updating i want to check for collision, and if the blocks are moving blocks then set the player rect x speed to the blocks speed

here is the code:
https://github.com/C-Dubb/Flatformer

If someone could point me in the right direction or give me a way to do it with my code I would highly appreciate it

-Chris
ChristianCareaga
 
Posts: 52
Joined: Sat Jun 22, 2013 9:54 am

Re: Implementing moving blocks

Postby Mekire » Sun Dec 08, 2013 8:31 am

I actually have yet to write an implementation of this; I'm constantly distracted by other projects.

Here are two superb resources on the subject (not related to any specific language):
http://www.emanueleferonato.com/2012/05/24/the-guide-to-implementing-2d-platformers/
http://info.sonicretro.org/Sonic_Physics_Guide

The first link above actually has a section specifically talking about implementing moving platforms.

If I have time in the next few days I'll try and write something up, but hopefully this gives you a push in the right direction.

-Mek
User avatar
Mekire
 
Posts: 987
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Implementing moving blocks

Postby ChristianCareaga » Sun Dec 08, 2013 8:38 am

Mekire wrote:I actually have yet to write an implementation of this; I'm constantly distracted by other projects.

Here are two superb resources on the subject (not related to any specific language):
http://www.emanueleferonato.com/2012/05/24/the-guide-to-implementing-2d-platformers/
http://info.sonicretro.org/Sonic_Physics_Guide

The first link above actually has a section specifically talking about implementing moving platforms.

If I have time in the next few days I'll try and write something up, but hopefully this gives you a push in the right direction.

-Mek


Thanks Mekire! I'll take a look at those and try to figure things out, I think i know what to do but not exactly how to do it with the collision detection and sprite groups
ChristianCareaga
 
Posts: 52
Joined: Sat Jun 22, 2013 9:54 am

Re: Implementing moving blocks

Postby Mekire » Wed Dec 11, 2013 10:40 am

Wrote something up. I'm sure it could still be improved.

https://github.com/Mekire/meks-pygame-samples/blob/master/platforming/moving_platforms.py

-Mek
User avatar
Mekire
 
Posts: 987
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Implementing moving blocks

Postby ChristianCareaga » Thu Dec 12, 2013 2:48 am

Oh wow thank you! i got it implemented and moving but my player calls is different so it doesn't move the player with it, what do i need to change or do i need to fix my player class
ChristianCareaga
 
Posts: 52
Joined: Sat Jun 22, 2013 9:54 am

Re: Implementing moving blocks

Postby Mekire » Thu Dec 12, 2013 4:34 am

Not sure. Won't be able to test your code till later.
My method: Everyloop the first thing I do is check if the player is on a moving platform. Then I update all platforms. If the player is either on or bumped by a moving platform his position is adjusted. Then I update the player based on his own movement. Then draw everything.

-Mek
User avatar
Mekire
 
Posts: 987
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Implementing moving blocks

Postby ChristianCareaga » Thu Dec 12, 2013 5:31 am

I messed with it a bit and its pushing the player if it touches the side but not if the player is on top,
ChristianCareaga
 
Posts: 52
Joined: Sat Jun 22, 2013 9:54 am

Re: Implementing moving blocks

Postby ChristianCareaga » Thu Dec 12, 2013 7:04 am

I got it! it was only detecting collision between the mover and the player from the mover class, I couldn't figure out why the player wasn't checking for collision then i noticed that check_moving was never called, because in yours you call it in the main-loop! Thank so much works great! :D
ChristianCareaga
 
Posts: 52
Joined: Sat Jun 22, 2013 9:54 am


Return to Game Development

Who is online

Users browsing this forum: No registered users and 3 guests

cron