pygame

How do I pass a rect into pygame.display.update() to update a specific area of the window?

半世苍凉 提交于 2021-02-05 07:02:26
问题 On the documentation page for pygame.display.update() , it says you can pass a rect into the method to update part of the screen. However, all of the examples I see just pass an existing rect from an image or shape in the program. How can I tell it to update an area on the screen directly? For example, when drawing a rectangle, I could use a rect argument of (100,200,30,40) . This would draw a rectangle with a top at 200, a left at 100, a width of 30, and a height of 40. How can I pass a

Pygame drawings rotated 90 degrees

亡梦爱人 提交于 2021-02-05 06:50:51
问题 So if you've by any chance seen my earlier questions, you would know I was working on a recreation of Conway's game of life with a friend. I'm having another issue where the drawings are being rotated for some odd reason. I assume its an issue with the x and y position but I can't seem to find how to fix it. Any help is appreciated. Here's the code: #Import goodies import time import pygame #Start pygame pygame.init() pygame.display.init() #Create dimension variables width = 64 height = 36

Pygame knowing when shift+other key is pressed

这一生的挚爱 提交于 2021-02-05 06:49:46
问题 I am trying to create a program similar to Microsoft word, only heavily simplified. I need to be able to know when shift+(any key) is pressed, and display the proper value for what was pressed (changed from just the normal key by the shift). Currently, my best method is simply to find if a shift key is pressed, then whenever another key is pressed altering the number output from the pressed key to a new value that I can call chr() to change it into the shifted value for that key. import

Pygame drawings rotated 90 degrees

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-05 06:49:26
问题 So if you've by any chance seen my earlier questions, you would know I was working on a recreation of Conway's game of life with a friend. I'm having another issue where the drawings are being rotated for some odd reason. I assume its an issue with the x and y position but I can't seem to find how to fix it. Any help is appreciated. Here's the code: #Import goodies import time import pygame #Start pygame pygame.init() pygame.display.init() #Create dimension variables width = 64 height = 36

How to keep run a game in window while we are inputting in terminal python [duplicate]

早过忘川 提交于 2021-02-05 06:45:34
问题 This question already has answers here : Is there a way that while running pygame, I can also run the console too? (2 answers) Closed last year . I am new to python programming i was writing a code of snake game in which snake moves randomly on x axis. And user have to put input in terminal for the location of food and poison on x axis. And snake must be inside the food and poison. "The main thing i want to that is while the user input any location of food and Poison the snake must move whole

Is it possible to implement gradual movement of an object to given coordinates in Pygame?

南楼画角 提交于 2021-02-05 06:45:25
问题 here is the sample code that i have tried: x[0] = 10 y[0]=10 x[1] = 40 y[1]=40 width=10 height=10 pygame.draw.rect(win,(0,0,255),(x[1],y[1],width,height)) pygame.draw.rect(win,(0,0,255),(x[0],y[0],width,height)) 回答1: You have to slight change the position in the application loop. Define a start position ( start ), end position ( end ) and velocity ( speed ): start = 10, 10 end = 40, 40 speed = 1 Init the current position. Compute the vector form the current position to the end position ( dx ,

How to keep run a game in window while we are inputting in terminal python [duplicate]

可紊 提交于 2021-02-05 06:44:45
问题 This question already has answers here : Is there a way that while running pygame, I can also run the console too? (2 answers) Closed last year . I am new to python programming i was writing a code of snake game in which snake moves randomly on x axis. And user have to put input in terminal for the location of food and poison on x axis. And snake must be inside the food and poison. "The main thing i want to that is while the user input any location of food and Poison the snake must move whole

Pygame- rotate sprite and follow path simultaneously [duplicate]

别说谁变了你拦得住时间么 提交于 2021-02-05 06:42:25
问题 This question already has answers here : How do I rotate an image around its center using Pygame? (6 answers) Closed 4 months ago . I'm trying to animate a ball getting thrown, and I want it to rotate an follow a smooth, parabolic path at the same time. However, I just can't seem to get pygame.transform.rotate() to cooperate. Here's what I've tried so far: import pygame screen = pygame.display.set_mode((500, 500)) timer = pygame.time.Clock() ball = pygame.sprite.Sprite() ball.image = pygame

How to save object using pygame.Surfaces to file using pickle

别来无恙 提交于 2021-02-05 06:42:11
问题 If I have created my own class which has some attributes that are pygame.Surfaces and I would like to save this object to a file, how can I do this as an error occurs when I try. The class which I have created is an object which is essentially the following (Item class is included because the player has items which have attributes that are pygame.Surfaces): class Item: def __init__(self,name,icon): self.name = name self.icon = pygame.image.load(icon) class Player(pygame.Sprite): def __init__

pygame.sprite.groupcollide() does not work when trying to implement collision in pygame

爷,独闯天下 提交于 2021-02-05 06:15:47
问题 I'm working on a Snake Game project, and I can't make the snake and the foods collide. After reading some Pygame documentation, I decided to use pygame.sprite.groupcollide for collisions. I have two types of sprites in my game: Snake Food(s) pygame.sprite.groupcollide has worked in my previous game (Alien Invasion game from a Python book); however, for some reason it doesn't work in my current game. What do you think might be the reason? Here is the higlight of the collisions part (snake_game