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

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.

Related

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

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

How do you make a sprite be able to detect if the mouse is over it in pygame? [duplicate]

This question already has answers here:
How to detect when a rectangular object, image or sprite is clicked
(1 answer)
Why is my collision test always returning 'true' and why is the position of the rectangle of the image always wrong (0, 0)?
(1 answer)
Closed 2 years ago.
I am using Pygame and I want to have a sprite be able to detect if the mouse is over it. Here's the code I got: if axe_button.get_rect().collidepoint(pygame.mouse.get_pos()): It sort of works.
Here's what I mean. It detects it only when my mouse is at (0, 0); I think that it's because I used pygame.display.blit(axe_button, (30, 70)). So it only draws it at the right place but the actual thing is still at 0, 0.
I don't know if my theory is right, but can you please help me?

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.

In pygame, how do I rotate an image around its middle bottom? [duplicate]

This question already has answers here:
How can you rotate an image around an off center pivot in Pygame
(1 answer)
How do I rotate an image around its center using Pygame?
(6 answers)
Closed 2 years ago.
I am making 2D Tank game and I have a problem with rotating my turret. Turret should rotate around its middle bottom but it rotates around the center.
def turret_rotate(self):
turret_rot_image = pygame.transform.rotate(self.turret_image,self.turret_angle)
turret_rot_rect = turret_rot_image.get_rect(center = self.turret_rect.midbottom)
return turret_rot_image,turret_rot_rect
can anyone help me?
solved

Pygame tilemap collison using hitboxes? [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 want to make that every tile has a hitbox...
And how to check if player collides with them...
Heres the code:
http://pastebin.com/56LbcMPA
EDIT: And i need help with this!

Categories