pygame

Mp3 player - the “file not found” messagebox.showerror shows up every time I play a file

时间秒杀一切 提交于 2020-05-17 06:04:11
问题 The code below is a media player (mp3). It worked perfectly until I added the show_details() function which is supposed to show the length and timing of the song, the error message "file not found" appears when playing a file (The file does play! but the error message pops everytime). Once I take off the 3 lines consisting of 'a', 'total_length' and 'print' statements, the error stops to show up and the song of course plays normally. What is the problem with my code? filelabel = Label(root,

My Collision With My Platform Images Problem How To Fix?

冷暖自知 提交于 2020-05-15 21:31:48
问题 the problem is that when I collide with my platform it seems to put me way higher then the platform it does this for all my platforms and idk why my collision for platform for enemy in enemies: if playerman.rect.colliderect(enemy.rect): collide = True playerman.y = enemy.rect.top - playerman.height + 1 if playerman.rect.right > enemy.rect.left and playerman.rect.left < enemy.rect.left - playerman.width: playerman.x = enemy.rect.left - player.width if playerman.rect.left < enemy.rect.right and

Make bullets fire off in the direction the player is facing

房东的猫 提交于 2020-05-15 05:59:05
问题 I was just getting some help to figure out how to get my player fire bullets when I realized that they only go (kinda expected this but however as only had y value for movement). I don't know how I'll make the bullets fire off in the direction the player is facing. I have some idea of what to but I just don't know how to do it... I thought I could somehow use the cursor and player tracking that's in this game for the visuals but I don't know how to make that a one-time thing instead of a

What is the surface.blit() function in pygame? What does it do? How does it work?

被刻印的时光 ゝ 提交于 2020-05-14 18:23:04
问题 I am a beginner in Python and I am not clear about the function surface.blit() . What does it do? How does it works? I have come across the following points as to how to create it. Create a canvas of desired size Create a surface of smaller size containing the object to be displayed. Define the Rect value of the surface. Blit (overlap) the surface on the canvas at the rect position Syntax: canvas.blit(surface, surfacerect) Why is only rect used? Can it be any other shape? 回答1: Putting this in

Pygame not showing anything in the window

和自甴很熟 提交于 2020-05-14 17:48:11
问题 Just started programming in python and pygames. Whenever I try running a py file with pygames, the pygames window will appear, but there will be absolutely nothing in it. No errors in the log, but nothing shows, it's just a gray screen. I tried running it on IDLE, and through the command line (I'm on a mac so I use the terminal) And it's not just my programs that aren't showing anything, I've tried to run one of pygames examples, and it will still not display anything. For example, if I run

How can I use different images for my snake's body parts in my snake game? (Python, Pygame, Snake)

谁都会走 提交于 2020-05-13 10:55:13
问题 Explanation I am currently working on a snake game with Pygame but I have a problem because my snake currently consists only of squares but I would find it better if the snake contained a drawn 25x25 picture for the snake head, the body, the tail and for a bent body part so that when the snake changes its height and direction, this part still looks connected to the snake. I have also added a sample image so that you can better understand what I mean by the diffrent body parts. This is the

How can I use different images for my snake's body parts in my snake game? (Python, Pygame, Snake)

拥有回忆 提交于 2020-05-13 10:54:00
问题 Explanation I am currently working on a snake game with Pygame but I have a problem because my snake currently consists only of squares but I would find it better if the snake contained a drawn 25x25 picture for the snake head, the body, the tail and for a bent body part so that when the snake changes its height and direction, this part still looks connected to the snake. I have also added a sample image so that you can better understand what I mean by the diffrent body parts. This is the

How does bullet reflect of the wall

家住魔仙堡 提交于 2020-05-09 10:47:57
问题 I've been working on this project about tanks (based on game Tank Trouble) and I've made walls appear on the screen. How can I make that when projectiles/bullets collide with the wall they ricochet from it? In the future, I am planning on the bullet colliding with a player/enemy. Any help will be appreciated! Here is game code: class Game: def __init__(self): self.run = True self.screen_width = 1060 self.screen_height = 798 self.image = pygame.image.load("bin/sprites/background/background1

Pygame not returning events while embedded in PyQt

旧城冷巷雨未停 提交于 2020-05-09 07:29:29
问题 I'm testing out an application and the UI uses PyQt4 with Pygame embedded into it. It uses a timer to "update" itself so to speak and in the timerEvent function Pygame attempts to retrieve all detected events. Issue is, Pygame isn't detecting any events. Here's a minimalist version of my code #!/etc/python2.7 from PyQt4 import QtGui from PyQt4 import QtCore import pygame import sys class ImageWidget(QtGui.QWidget): def __init__(self,surface,parent=None): super(ImageWidget,self).__init__

Pygame mask collision

旧街凉风 提交于 2020-05-09 06:34:13
问题 I'm trying to get proper collision detection with rotating surfaces in pygame. I decided to try using masks. It somewhat works, but it is not as precise as I'd liked/thought. I tried updating the mask at the end of the cycle to get a "fresh" hitbox for the next frame, but it didn't work as expected. What is my mistake? import pygame import random WHITE = [255, 255, 255] RED = [255, 0, 0] pygame.init() FPS = pygame.time.Clock() fps = 6 winW = 1000 winH = 500 BGCOLOR = WHITE win = pygame