Questions tagged [pygame]

Pygame offers Python modules specifically crafted for developing video games. Please apply this tag exclusively when utilizing the Pygame library, rather than seeking help with programming a game in Python overall.

I require assistance with figuring out how to trigger a scroll up event

I've been struggling to find a solution in Python using Pygame that allows me to detect scrolling up. My goal is to recreate the experience from the popular video "Interstellar Mouse" https://www.youtube.com/watch?v=aANF2OOVX40 I want to trigger the ...

Why does pygame.mixer.Sound only produce a popping sound before abruptly stopping?

My attempt to play sound using Python through pygame is resulting in a strange issue. When I run the program, all I hear is a popping noise and then it abruptly quits. The audio track I am trying to play is at least 20 seconds long, but for some reason the ...

Is it possible to determine if two objects are in the same position using rect.colliderect(rect2) after a certain amount of time has elapsed during the game

Currently, I am working on a game where a dog chases a ball and the ball chases the mouse cursor. The goal is for the game to stop and display "Game over" once the dog reaches the same position as the ball. However, my code currently checks if the two obje ...

The Pygame function is not returning True when using the colliderect method

I am currently working on a Pygame project to develop a jumping system, but I'm encountering challenges with collision detection. My level is stored in a list structured like this: level = [ "WWWWWWWWWWWWWWWWWWWW", "W W", "W ...

What could be causing the error with these pygame imports?

Apologies for my lack of experience with Python, but I have a question that involves two files - File1 and File2 In File1, I have defined the variable X. This file modifies the value of X throughout my game and also imports specific objects from File2 Wi ...

Python encountered an error: TypeError - invalid rect argument

As a beginner in Python, I am currently working on creating a snake game. However, I keep encountering an error stating that the 'rect' argument is invalid. File "c:UsersIdontwanttomentionDesktopCodingPygameSnake.py", line 47, in <modul ...

Tips for effectively storing and displaying orbital paths in pygame

After following a tutorial on YouTube by TechWithTim, I successfully completed a solar system project in pygame. With plans to expand it further, adding more planets caused the program to crash due to memory issues related to orbit rendering. How can I eff ...

Utilizing text file data to play an mp3 file in pygame

myfile = open('kill.txt', encoding='utf-8').readlines() NoiseMP3 = myfile[3] bop = pygame.mixer.music.load(NoiseMP3) pygame.mixer.music.play(-1) Essentially, the file name is specified on line 3. When I change NoiseMP3 to the actual file name, the file i ...

impact of dynamic sprite interaction in pygame

I am currently working on a project with two moving sprites. One sprite is named wall and it moves up and down, while the other sprite is called Player and it bounces around the screen, changing direction whenever it hits an obstacle. I have managed to ge ...

Eliminate duplicate points along a line

Currently, I am developing an algorithm that examines the outline of a continent based on a simple black and white map. The goal is to return the perimeter of the shape. For instance, consider the following example: [(1,0), (2,0), (2,1), (2,2), (3,2)...] ...

Intersecting Rectangles in Pygame

Currently, I'm working on creating a basic game using pygame, but I've encountered an issue that I need assistance with. Let's say we have two sprites, named sprite1 and sprite2, each with their own rect and image. These sprites are interac ...

Which graphical user interface framework pairs best with Pygame?

I'm currently developing a game that requires the ability to display GUI elements within a pygame surface. I have researched various options but have not found exactly what I need. Some libraries like Ocemp, PGU, and GooeyPy seem to be in this problem ...

Discover your screen orientation using Python

I recently developed a Python game using Pygame which operates flawlessly in both Portrait and Landscape orientations. However, I encountered an issue when the user rotates their device while the game is running, causing everything to appear jumbled up on ...

Error message: Unable to locate Sdl2-config when trying to install pygame_sdl2

Having some trouble while attempting to set up pygame_sdl2 on my system. Each time I run the command: python setup.py install I encounter this error message: sh:1:sdl2-config not found Apart from that, I am also getting an error like this: subprocess.Cal ...

What is the best way to create a grid made up of rectangles, allowing each rectangle to be easily referenced by its position, represented by a tuple of row and column, for future use

Here is a sample code snippet: from tkinter import * import numpy as np rows = 10 columns = 10 width, height = rows*18, columns*18 window = Tk() window.geometry(str(width)+"x"+str(height)) window.resizable(width=False, height=False) window.confi ...

Python 3: Tricks for personalizing a map with interactive features

Currently facing an issue with setting up different block packs for drawing maps on the platformer game. Theoretically, pressing specific numbers should do the trick. All files are organized in a folder with the correct hierarchy. What would be the optima ...

What is the reason that pygame.mixer.Sound().play() doesn't return a value?

As per the pygame documentation, calling pygame.mixer.Sound().play() is expected to return a Channel object, and indeed it does. However, on certain occasions, it appears to return None causing an error to occur immediately after: NoneType has no attribut ...

Tips for displaying 2 image slides on the screen for a specific duration using Pygame

Looking to add a logo slideshow before launching your game? I have an idea. You can display logo 1 for 2 seconds, then logo 2 for another 2 seconds before the game starts. How can you achieve this? I attempted to implement this feature within the main loo ...

Error encountered in pygame.examples.aliens: syntax issue preventing proper functionality

After attempting to execute the sample code "python3 -m pygame.examples.aliens," I encountered a syntax error (as shown below). Initially, I suspected that there might have been an issue with my pygame installation. However, upon further investigation, I n ...

What could be causing the error of a missing required positional argument even though it appears to be provided as required?

Currently, I am in the process of creating a boid program using Python. This project involves two separate programs - "boid.py" which defines the boid class and "flocking practice.py" which is intended to utilize this class and display the boids on the scr ...

The foe continues to push onward to the right

After several attempts, I am still struggling to keep my enemy stationary while moving the camera with my player. Unfortunately, when the screen shifts, my enemy slowly drifts away from its original position. Additionally, if my player collides with a plat ...

Is there a way to determine the quantity of boxes based on their specific placement?

Currently working on a python memory game, I am struggling with determining the number of boxes that the user clicks based on the cursor's position. This is what I have so far: number = ev.pos[y]//boxsize*numboxsx+ev.pos[x]//boxsize (this calculation pr ...

Fixing the clock in a chess game using Python

For my chess project, I am developing a Chess clock that follows specific time formats commonly used in the game. In one format, players are granted 5 minutes each initially, and whenever a move is made, 5 seconds are added to the clock. Another example is ...

The pygame window fails to stay in fullscreen mode

Currently, I am working on developing a game using the pygame module. However, I have encountered an issue with the fullscreen mode functionality not working as expected. Although the program itself runs smoothly, when attempting to switch to fullscreen mo ...

Creating a separate screen in Pygame similar to Playground Swift (pygame) functionality

https://i.stack.imgur.com/GhtFy.jpg Looking to divide the screen into two separate areas like shown in the image using pygame - one for gameplay and the other for player input. Any tips on how I can achieve this? ...

Is it possible to translate grid arrays into (x, y) coordinates within Pygame?

Instead of using numpy. If I have information about the size of my elements and grid, can I determine the coordinates of the top left corner of my grid? Rect size: 62x50 WxH (g_height, g_width) Grid dimensions: 12x12 """self.row/column changes with mou ...

What could be the root cause of this AttributeError?

After extensive searching for a solution, I have not been able to find one. Here is the code I am working with: class snakeGame: def _init_(self): pygame.init() self._isRunning = False self._surface = None self.drawList ...

Issues with Pygame on MacOS X

Setting up Pygame on my MAC has been a challenge for me. My specifications include OS X El Capitan 10.11.4. Whenever I try to run a file with import pygame, I encounter the following error in terminal: ImportError: No module named 'pygame' Following the ...

What could be causing my pygame screen to become unresponsive when awaiting user input?

I have recently started learning Python programming and am working on developing a game for my class project. However, whenever I run the program, the screen becomes unresponsive before allowing the user to input anything. Can anyone help me figure out wha ...

Integrate PySide with PyGame for a more dynamic and interactive

Are you interested in creating a user interface that includes forms for app configuration and a rendering component, such as displaying sprites? Is there a way to integrate PySide with PyGame within a single application? For instance, how would one go abo ...

I'm encountering a persistent issue every time I attempt to utilize a spritesheet in Python

Running my code for the first time with spritesheets, I encountered 2 errors. The first error seems to be related to passing 4 arguments instead of the expected 3 when calling for the spritesheet. Even though I only see 3 arguments being passed. The seco ...

The hitboxes are constantly in motion, never remaining stationary

Currently, I am working on a game project involving gathering trees and battling zombies. One issue I am encountering is that the hitboxes of trees are not staying in place while walking on the map; instead, they move along with the screen. I have b ...

Creating sprites in proximity to a specific location: A step-by-step guide

Creating a game with enemy ships that shoot lasers at the player sprite presents some challenges. These enemies need to rotate in order to face the player and then fire a projectile aimed at colliding with the player ship. The current issue is that the la ...

When I attempt to draw pixel by pixel in Pygame, nothing appears on the screen

I am currently working on a Python program to generate and display the Mandelbrot set. However, I am facing an issue where the rendering is only showing a black image pixel by pixel. My setup includes Python 3.7 and pygame version 1.9.4. The problem seems ...

An instance of the class is not a function

I am in the process of recreating an old 2d space shooter game, and have successfully completed most of it. However, I have encountered a roadblock when trying to implement the shooting mechanism. I am also wondering if I should utilize Pythagoras' t ...

I encountered a ValueError while trying to specify a color in my pygame code

Working on my final project, I created a code for a bouncing ball effect. Initially, I intended to have two balls in action so I designed a class and incorporated multiple functions. However, after implementation, it seems that my code is not functioning ...

Why won't the pygame button navigate me to the next function as expected?

I'm new to my first python project and just learned how to set true/false variables for buttons on different pages. However, I'm struggling with getting a specific button to go to a function. In my game, the player makes choices that lead to different di ...

Tips for resolving incorrect image loading in pygame

My friends and I are collaborating on a fun game project using Python and Pygame. Today, while working on the weapon part of the code, I encountered an issue where the incorrect weapon images were loading (it was actually loading character images from a d ...

Obtaining collision side of Pygame sprites - rect detection

I'm a beginner in pygame and I'm looking to gain some basic knowledge. My goal is to create obstacles and determine which side of the player rectangle (representing the collision box of the sprite) is colliding with the obstacle rectangle. This w ...

Every time I attempt to load an image on Pygame, I encounter the frustrating message "File not found"

I've been diving into the world of pygame and encountering some frustrating errors. Every time I try to add a background image to my window, I keep receiving an error message saying No file found, even though the image name is correct. For reference ...

pygame zero - graphics in motion going downwards

One of the challenges in my game is implementing falling objects that appear at random positions on the screen. However, I keep encountering an error message that says: "empty range for randrange() (0,-799, -799)". It seems like the object must have a ne ...

Pong Pygame Not Refreshing Scores

I'm having an issue with my score not updating correctly. Whenever a player scores, the debugger shows 0's. Here are the variables for tracking the scores. player_score = 0 opponent_score = 0 basic_font = pygame.font.Font('freesansbold.ttf', 32) And here ...

What is the best way to rotate an image around its center in Pygame?

I've been attempting to rotate an image around its center using pygame.transform.rotate() but for some reason it's not working as expected. The specific line of code causing issues is rot_image = rot_image.subsurface(rot_rect).copy(). This results in the f ...