how to remove a body and a shape from a Space [duplicate] - python

This question already has answers here:
how to make image/images disappear in pygame?
(1 answer)
How do I delete rect object from screen once player collides with it?
(1 answer)
Closed 1 year ago.
I am making a game in python using pygame for the visual interface and pymunk to simulate the physical collisions between the ennemies and everything works just fine but now i want to remove the enemy bodies when they die (get to 0 health), so i used pymunk.Space.remove(space, enemy.shape) and pymunk.Space.remove(space, enemy.body) and so far everything works , when the enemy dies he disappears but the problem is once the image disapeared the pymunk "bodies" that process collision still persist which then blocks the other enemies. Also i dont wan't to just once they die move their bodies out of the map as i'm worried about it causing lags > see the photos

Related

How do I make solid walls in my pygame program? [duplicate]

This question already has answers here:
How to implement barriers to stop the player moving through walls
(1 answer)
Adding collision to maze walls
(1 answer)
Closed 4 months ago.
In my program, there is a small cube which you can move around. There are also walls, but the cube is able to move through the walls. Is there any way to make the walls solid such that the cube can't move through them?
I haven't tried anything yet.

How to make pygame only load the graphics being shown on the screen [duplicate]

This question already has answers here:
Pygame lags after drawing full window grid
(1 answer)
How Can I Improve My Terrain Generator Performance I Get 40 FPS
(1 answer)
Closed 1 year ago.
I'm creating a game with my team in Python and Pygame.
It is a 2d battle royale game based in zombsroyale.io.
As the map is really big, the game starts to lag because it is loading the entire map, even the parts that aren't being shown on screen.
We would like pygame to only load the graphics that are currently being shown on screen, and when you move, stop loading the graphics that now aren't being shown and load the new graphics.
How could we achieve this in Python 3?
Thanks for reading.
EDIT: we've also checked that the game is less laggy when we set the screen window size to a smaller one (e.g. 680x680). How can we make the game's performance be good with a big window size (e.g. 1280x720)?

Not able to move second paddle in pong clone written with pygame [duplicate]

This question already has answers here:
How to get keyboard input in pygame?
(11 answers)
How can I make a sprite move when key is held down
(6 answers)
Closed 2 years ago.
So I have a small problem.
I am a beginner and I am just making my first game, chose to do a pong clone.
However, I can not move the second paddle with the keys a and z and for the life of me I canĀ“t find out why.
I would be extremely grateful if someone could help me.
Just for heads up, laud mean paddle, pall means ball and aken means screen. I am not a native speaker.

how to get pygame framerate higher? [duplicate]

This question already has answers here:
Why does my game made with Pygame suddenly lag for a few seconds? [duplicate]
(1 answer)
Pygame is running slow
(1 answer)
Closed 2 years ago.
I'm designing a game in pygame that you can download here: https://github.com/hailfire006/games unfortunately, when you fly the ship near the space station, the framerate drops from a nice 30-40 to 16-20. I believe this is due to my blitting sprites onto the screen every frame, and I have been told that there is a way to only redraw parts of the screen that need redrawing, but no one ever explains how to do this.
Someone please help, I'm beginning to worry that I should abandon hope of ever making a good game in python, and that I'll have to learn an entirely new language just to deal with framerate...
p.s. any other way you know how to raise the fps would be welcome also

pygame - solid object collision detection [duplicate]

This question already has answers here:
How do I detect collision in pygame?
(5 answers)
How to detect collisions between two rectangular objects or images in pygame
(1 answer)
Closed 2 years ago.
I'm using Pygame with my group to develop a game for this semester in school. I'm responsible for building the physics engine.
My question: How do I get a player object to stop on collision with a rect object? I've scoured the internet, and this website for answers, but everything seems to complicated to grasp.
Here's the code particular block of code I'm trying to get to work:
if player.rect.left == rect.right:
player.undo_right()
This block is preceded by the game loop. All I want to do is make it so the player is consistently 20 pixels away from the box. I'll be able to apply better bounds once I get this test to work. Right now, it repels the player sporadically, and never consistently. Sometimes, I'll run it, and it'll bounce away once, and then the player will go through the rectangle freely.
I realize there are numerous links on the internet for this type of thing, but I wanted to try to get collision to work using simple code like this. If I'm not able to, then why? Can someone exaplin a simple and efficient way to do this?
Thanks.

Categories