pygame

How to make a Pygame Zero window full screen?

我怕爱的太早我们不能终老 提交于 2021-02-16 08:46:40
问题 I am using the easy-to-use Python library pgzero (which uses pygame internally) for programming games. How can I make the game window full screen? import pgzrun TITLE = "Hello World" WIDTH = 800 HEIGHT = 600 pgzrun.go() Note: I am using the runtime helper lib pgzrun to make the game executable without an OS shell command... It implicitly imports the pgzero lib... Edit: pgzero uses pygame internally, perhaps there is a change the window mode using the pygame API... 回答1: You can access the

Pygame rectangle drawing issue

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-15 07:39:18
问题 So me and my friend have been working on recreating Conway's game of life in python. It's been going well until we started drawing the cells with pygame. we just finished the grid easily but for some unknown reason our cells won't draw. Please let us know whats wrong with the draw command. Here's the code: #Import goodies import time import pygame pygame.init() pygame.display.init() #Create dimension variables width = 32 height = 18 rectwidth = 1280 / width rectheight = 720 / height #Colors!

How to make my rectangle rotate with a rotating sprite [duplicate]

限于喜欢 提交于 2021-02-15 07:37:11
问题 This question already has answers here : Shooting a bullet in pygame in the direction of mouse (1 answer) calculating direction of the player to shoot pygame (1 answer) Closed last month . So I been having this problem with my rectangle/projectile rotation, I want it so that my rectangle/projectile will rotate with my rotating sprite but the code I'm trying for it is not working for me, The code that I'm trying is giving me this error. 'pygame.Surface' object has no attribute 'x' I have tried

pygame.display.set_icon(pygame.image obj) doesn't work in python 3.9.1

半世苍凉 提交于 2021-02-15 07:18:28
问题 I was using python 3.8 and everything was ok, but when I updated my python to 3.9 I figured out that pygame.display.set_icon doesn't work :/ (No errors, No warnings) Here's the code: import pygame pygame.init() scr = pygame.display.set_mode((0, 0)) fps = pygame.time.Clock() pygame.display.set_caption("Caption Here!") pygame.display.set_icon(pygame.image.load("pics\\img.png")) fps.tick(60) pygame.display.update() the problem is solved. it required a smaller image as it's icon =) 回答1: See

Pygame Pacman - Enemy Random Movement

巧了我就是萌 提交于 2021-02-15 07:14:32
问题 Ive made a pacman game using python and pygame and I have one of the ghosts that just makes random movements around the maze. Does anyone know if there is a way for me to make the random enemy more AI controlled? I still want it to be random but at the moment the random movement code I have makes it so that the ghost can sometimes get stuck in the box that the ghosts start in or it will just go back and forth from one place to another. This is the Random movement method that I Have: def get

How to make a circle move diagonally from corner to corner in pygame

穿精又带淫゛_ 提交于 2021-02-15 07:14:18
问题 I've created a program to animate shapes, and I've only moved either the x axis or y axis, never both at the same time. So moving diagonally is completely new to me. Below is my code: """ Author: Victor Xu Date: January 20th, 2021 Description: Animating Shapes with pygame """ """ 1. Modify the animation of the red_box so that when it hits the left or right side of the window it changes direction. (COMPLETED) 2. Add a green_rect (40x20) Surface that moves in up and down. It should change its y

How to make a circle move diagonally from corner to corner in pygame

你说的曾经没有我的故事 提交于 2021-02-15 07:14:12
问题 I've created a program to animate shapes, and I've only moved either the x axis or y axis, never both at the same time. So moving diagonally is completely new to me. Below is my code: """ Author: Victor Xu Date: January 20th, 2021 Description: Animating Shapes with pygame """ """ 1. Modify the animation of the red_box so that when it hits the left or right side of the window it changes direction. (COMPLETED) 2. Add a green_rect (40x20) Surface that moves in up and down. It should change its y

Stopwatch between mouse up/down

浪子不回头ぞ 提交于 2021-02-15 06:51:28
问题 I am trying to test the time between mouse down and mouse up events by using a simple stopwatch in a while loop. The mouse down event works fine, but when i release the mouse for mouse up, the seconds continue to go up and do not stop. from pygame import * import time screen = display.set_mode((160, 90)) sec = 0 while True: new_event = event.poll() if new_event.type == MOUSEBUTTONDOWN: while True: # Basic stopwatch started time.sleep(1) sec += 1 print(sec) # In loop, when mouse button

Stopwatch between mouse up/down

可紊 提交于 2021-02-15 06:51:11
问题 I am trying to test the time between mouse down and mouse up events by using a simple stopwatch in a while loop. The mouse down event works fine, but when i release the mouse for mouse up, the seconds continue to go up and do not stop. from pygame import * import time screen = display.set_mode((160, 90)) sec = 0 while True: new_event = event.poll() if new_event.type == MOUSEBUTTONDOWN: while True: # Basic stopwatch started time.sleep(1) sec += 1 print(sec) # In loop, when mouse button

I need to add text to my rectangles, how would I do this?

让人想犯罪 __ 提交于 2021-02-15 06:48:25
问题 I need to draw text into the buttons, which can be seen as the four smaller rectangles in my program, alongside this I need to draw text onto the title as well. I am unsure on how to do this, as the structure of my program, is different to others that I have seen. Followed other questions, and the answer they've received in an attempt to influence mine. import pygame import sys def main(): pygame.init() clock = pygame.time.Clock() fps = 60 size = [700, 600] bg = [255, 255, 255] font = pygame