pygame

How do I convert my pygame program which has multiple python scripts and images to a exe?

独自空忆成欢 提交于 2020-07-15 08:54:06
问题 I have 3 python scripts and many images in folders and tmx files which I want to make it as a single .exe . I wasnt able to find how to convert multiple python scripts and folders to single exe. I was only able to find cxfreeze and similar things for a single python script. Please help. Thanks in advance. 回答1: You can add external files to your pyinstaller exe by using add-data . An example I'm using for one of my pygame games: pyinstaller --onedir --clean --name "MyGame" --icon="images/icon

Sometimes the ball doesn't bounce off the paddle in pong game

我怕爱的太早我们不能终老 提交于 2020-07-13 15:55:23
问题 I have a simple pong game that mostly works well. But sometimes it occurs the the ball doesn't bounce of the paddle. The ball wobbles and slides along the paddle and the paddle seems to magnetically pull the ball as shown in the animation: Every time when the rectangle which surrounds the ball, collides the the paddle rectangle, the the direction of the ball is changed: if ball.colliderect(paddleLeft): move_x *=-1 if ball.colliderect(paddleRight): move_x *=-1 What causes the behavior? The

Sometimes the ball doesn't bounce off the paddle in pong game

£可爱£侵袭症+ 提交于 2020-07-13 15:51:09
问题 I have a simple pong game that mostly works well. But sometimes it occurs the the ball doesn't bounce of the paddle. The ball wobbles and slides along the paddle and the paddle seems to magnetically pull the ball as shown in the animation: Every time when the rectangle which surrounds the ball, collides the the paddle rectangle, the the direction of the ball is changed: if ball.colliderect(paddleLeft): move_x *=-1 if ball.colliderect(paddleRight): move_x *=-1 What causes the behavior? The

Why text display for 2 seconds in pygame

落爺英雄遲暮 提交于 2020-07-10 03:15:24
问题 Text wchich I display is displaying for only around 2 sec. I want that it will display while I click to other area elif msg[0:7] == 'YOU WIN' and Message_id == '200': print('You Win') textSurface = font.render('You Win', True, (0, 0, 0)) largeText = pygame.font.Font('freesansbold.ttf', 115) TextSurf = pygame.font.render('You Win', True, (0, 0, 0)) TextRect = textSurface.get_rect() TextRect.center = ((600 / 2), (700 // 2)) surface.blit(TextSurf, TextRect) grid.draw(surface) pygame.display.flip

Changing volume in pygame.mixer (almost) no effect

和自甴很熟 提交于 2020-07-09 06:15:11
问题 I'm trying to make an application in tkinter that has a number of buttons you can assign sound on and play it later. The click of the button itself only calls play() method, so loading of the sound is done beforehand. I tried making some kind of volume control with sliders (tk.Scale) and I noticed there is no noticeable difference between most volume values until I get very close to zero (take into consideration that slider resolution is 0.01 from 0.0 to 0.1). At around 0.02 I think I notice

Pygame: how to change background color

我的梦境 提交于 2020-07-08 12:26:15
问题 import pygame, sys pygame.init() screen = pygame.display.set_mode([800,600]) white = [255, 255, 255] red = [255, 0, 0] screen.fill(white) pygame.display.set_caption("My program") pygame.display.flip() background = input("What color would you like?: ") if background == "red": screen.fill(red) running = True while running: for i in pygame.event.get(): if i.type == pygame.QUIT: running = False pygame.quit() I'm trying to ask the user what background color he would like to have. If the user

Pygame: how to change background color

怎甘沉沦 提交于 2020-07-08 12:26:14
问题 import pygame, sys pygame.init() screen = pygame.display.set_mode([800,600]) white = [255, 255, 255] red = [255, 0, 0] screen.fill(white) pygame.display.set_caption("My program") pygame.display.flip() background = input("What color would you like?: ") if background == "red": screen.fill(red) running = True while running: for i in pygame.event.get(): if i.type == pygame.QUIT: running = False pygame.quit() I'm trying to ask the user what background color he would like to have. If the user

Pygame: how to change background color

时间秒杀一切 提交于 2020-07-08 12:25:11
问题 import pygame, sys pygame.init() screen = pygame.display.set_mode([800,600]) white = [255, 255, 255] red = [255, 0, 0] screen.fill(white) pygame.display.set_caption("My program") pygame.display.flip() background = input("What color would you like?: ") if background == "red": screen.fill(red) running = True while running: for i in pygame.event.get(): if i.type == pygame.QUIT: running = False pygame.quit() I'm trying to ask the user what background color he would like to have. If the user

How to remove an image in pygame?

冷暖自知 提交于 2020-07-08 03:19:27
问题 I'm working on a game and I have some problems working with images. I have loaded a few images . loading them and using screen.blit() was okay like below: img1 = pygame.image.load("leaf.png") img1 = pygame.transform.scale(img1, (25,25)) leaf = img1.get_rect() leaf.x = random.randint(0, 570) leaf.y = random.randint(0, 570) but I don't know how to remove them in an if statement like this for example: if count == 1: ... and I though maybe there is no way and I should draw a rectangle on the

Why isn't my Pygame colliderect() working?

南楼画角 提交于 2020-07-03 17:40:43
问题 I am creating a game where the player moves around a grid and dodges rocks, but my code for detecting collision doesn't seem to work. import pygame from pygame.locals import * import random pygame.init() xSize = 500 ySize = 500 win = pygame.display.set_mode((xSize, ySize), RESIZABLE) pygame.display.set_caption('Grid Game: Featuring Sad Blue Circle') grid = pygame.image.load('gr.png').convert() clock = pygame.time.Clock() rockWait = 1000 rock_spawn_ev = pygame.USEREVENT class player(object):