Python Forum
[PyGame] Game restart problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Game restart problem
#1
Hi guys, me and my friends are making a 2d platformer and are in desperate need of help. This is the link to our github repository, the updated code is in the MainMenu branch:
https://github.com/koay-whyes/TT5L-06-Project.git
So, our main issue is the level resetting. When we click the restart button in level 1, the level data does not load properly. And whenever we go to the next level, the platforms shifts and do not look the way they are intended to look. Plus, the player cannot interact with the environment and the enemies don't shoot. Also, the background doesn't scroll.

We suspect that it is because we didn't put the main game loop into another function. We tried to separate it into another class but it didn't work. Or maybe the problem is with the screen scroll but we're not really sure. Any help or advice is greatly appreciated.
Reply
#2
For the level resetting issue, it does sound like it might be related to how the game state is being managed. Separating the main game loop into its function or class can help keep things organized. Still, you'll want to make sure that the state (like level data and player position) is properly reset when you restart or move to the next level. Double-check how you're loading and initializing level data for the platforms shifting and other elements not behaving correctly. Ensure that all necessary variables are reset and that your level loading logic is correctly placing objects based on that data. As for the player interaction and enemies not shooting, this could be related to event handling or the update logic for those entities. Make sure that the main game loop (or the relevant functions) is correctly calling the update methods for all game objects. Lastly, for the background not scrolling, verify that your background scrolling logic is being called every frame and that it's dependent on the player's position or another relevant factor. Adding detailed logging can help pinpoint where things go wrong if you haven't already.
senka_25 likes this post
Reply
#3
From what you’ve described, the problem could be related to how the game state is being reset or how the game loop is handling the transitions between levels. One suggestion is to double-check how you’re reinitializing your game objects when you restart a level or move to the next one. Make sure all game objects, such as platforms, enemies, and the player, are being properly reset to their initial states. Also, since you mentioned the main game loop, it might help encapsulate the initialization and reset logic into functions that can be called whenever you need to restart a level or load a new one. This can help ensure that everything is properly reloaded. If you haven’t already, try logging the state of your game objects before and after the level reset to see what might be going wrong. Sometimes, just seeing the differences can give you a clue. Lastly, make sure that the screen scroll and other game elements are also being reset. If these are dependent on the player’s position or other game states, they might not be updating correctly after a reset.
senka_25 likes this post
Reply
#4
(Jun-19-2024, 08:55 PM)AdamHensley Wrote: From what you’ve described, the problem could be related to how the game state is being reset or how the game loop is handling the transitions between levels. One suggestion is to double-check how you’re reinitializing your game objects when you restart a level or move to the next one. Make sure all game objects, such as platforms, enemies, and the player, are being properly reset to their initial states. Also, since you mentioned the main game loop, it might help encapsulate the initialization and reset logic into functions that can be called whenever you need to restart a level or load a new one. This can help ensure that everything is properly reloaded. If you haven’t already, try logging the state of your game objects before and after the level reset to see what might be going wrong. Sometimes, just seeing the differences can give you a clue. Lastly, make sure that the screen scroll and other game elements are also being reset. If these are dependent on the player’s position or other game states, they might not be updating correctly after a reset.

thank you for your detailed explanation. we'll be sure to try it out!
Reply
#5
It sounds like you and your friends are facing some tricky issues. I checked out your GitHub repo, and it looks like a fun project! For the level resetting issue, separating the main game loop into another function or class could help keep things organized. Also, make sure you're reinitializing all game objects and variables when resetting the level. For the platforms shifting and player interactions, double-check your object positioning and collision detection logic. It might also be worth looking into how the screen scroll is handled and if it's properly reset.
Reply
#6
I've checked out your GitHub repository. Your issue with the level resetting might be related to how the game state is being managed. When you restart or move to the next level, make sure you're reinitializing all game objects and variables properly.
Reply
#7
It sounds like you're tackling some challenging issues with your 2D platformer project. The issues you're experiencing with level resetting, platform alignment, player interaction, and background scrolling can indeed be complex and multifaceted. Your suspicions about the main game loop and screen scroll could be on the right track.

Here are a few suggestions that might help:

Check Game Loop Structure: Ensure your game loop is properly structured and handles level transitions and object interactions correctly.
Debugging and Testing: Break down each issue systematically. Use print statements or debugging tools to track data flow and identify where the code might be going wrong.
Review Code Dependencies: Verify that all classes, functions, and methods are correctly linked and called where needed.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Problem With Entering Game Loop ElevenDecember 3 2,884 Jan-19-2020, 08:25 AM
Last Post: michael1789
  [PyGame] Problem when moving game window michael1789 15 9,375 Jan-17-2020, 01:40 PM
Last Post: metulburr
  Snake Game - obstacle problem Samira 3 5,937 Oct-31-2019, 02:58 PM
Last Post: Samira
  [PyGame] Game Logic problem with a "The Game of Life" Replication Coda 2 3,268 Dec-24-2018, 09:26 AM
Last Post: Coda
  [PyGame] Pong game key.event problem erickDarko 2 4,338 Dec-12-2018, 03:17 PM
Last Post: erickDarko

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020