pygame

My implementation of Bridson's algorithm Poisson-Disk Sampling seems to be stuck in an infinite loop

白昼怎懂夜的黑 提交于 2021-02-05 08:29:48
问题 A video by Sebastion Lague explained the Bridson's algorithm really well. To oversimplify, Create cell grid that has sides of radius/sqrt(2). Place initial point and list as spawnpoint. Place point into cell in grid. For any spawnpoint, spawn a point between radius and 2*radius. Look at the cells 2 units away from cell of new point. If contains other points, compare distance. If any point is closer to new point than the radius, new point is invalid. If new point is valid, new point is listed

My implementation of Bridson's algorithm Poisson-Disk Sampling seems to be stuck in an infinite loop

半世苍凉 提交于 2021-02-05 08:29:29
问题 A video by Sebastion Lague explained the Bridson's algorithm really well. To oversimplify, Create cell grid that has sides of radius/sqrt(2). Place initial point and list as spawnpoint. Place point into cell in grid. For any spawnpoint, spawn a point between radius and 2*radius. Look at the cells 2 units away from cell of new point. If contains other points, compare distance. If any point is closer to new point than the radius, new point is invalid. If new point is valid, new point is listed

How to make a circular sprite appear - pygame

只谈情不闲聊 提交于 2021-02-05 08:24:17
问题 I need my sprite to appear in the pygame window. How do I do this? Important code: #This will be a list that will contain all the sprites we intend to use in our game. all_sprites_list = pygame.sprite.Group() #creating the player player = player(BLUE, 60, 80, 70) player.rect.x = 200 player.rect.y = 300 At the end of the code I have pygame.display.update() . My sprite class (correctly imported): class player(pygame.sprite.Sprite): def __init__(self, color, width, height, speed): # Call the

How to Flip Image After Hitting Wall

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-05 08:22:06
问题 I want the image to face right when travelling right and face left when travelling left. I'm not sure what to do here... This is for an assignment and flipping the image isn't necessary, but I'd still like to learn how to do it. """ Author: victor Xu Date: January 21st, 2021 Description: Animating 3 images with background music and 3 sound effects. """ import pygame def main(): '''This function defines the 'mainline logic' for our game.''' # I - INITIALIZE pygame.init() # DISPLAY screen =

How to Flip Image After Hitting Wall

喜你入骨 提交于 2021-02-05 08:22:06
问题 I want the image to face right when travelling right and face left when travelling left. I'm not sure what to do here... This is for an assignment and flipping the image isn't necessary, but I'd still like to learn how to do it. """ Author: victor Xu Date: January 21st, 2021 Description: Animating 3 images with background music and 3 sound effects. """ import pygame def main(): '''This function defines the 'mainline logic' for our game.''' # I - INITIALIZE pygame.init() # DISPLAY screen =

Check collision between a image and a line

一笑奈何 提交于 2021-02-05 08:18:15
问题 I check collision: offset = (x0 - x1, y0 - y1) result = player1.mask.overlap(player2, offset) Its working between two images. But if I want to check collision between a image and pygame.draw.line(...) (I use it for create mask from line). mask.overlap returns None : surface = self.gameDisplay.subsurface(pygame.draw.line(self.gameDisplay, colors.GREEN, [100, 100], [200, 200], 5)) line_mask = pygame.mask.from_surface(surface) pygame.draw.line(self.gameDisplay, colors.GREEN, [100, 100], [200,

How to make an object fades color in pygame [duplicate]

不想你离开。 提交于 2021-02-05 08:15:33
问题 This question already has answers here : Pygame unresponsive display [duplicate] (1 answer) Pygame window not responding after a few seconds (3 answers) Closed 4 months ago . I want a rectangle to fade from green to red for a life-bar, but couldn't find easy way to do it on internet. I tried like this (just for going from red to yellow): colorR = 0 colorG = 255 colorB = 0 change = True while change: pygame.draw.rect(win, (colorR, colorG, colorB), (10, 10, 200, 50), 0) colorR += 1 if colorR ==

My pygame rects are giving a rect argument is invalid error

淺唱寂寞╮ 提交于 2021-02-05 08:14:49
问题 I've been looking for a solution for this error for about 15 minutes now and no posts or other websites covered the specific error i've been having. Here's the code snippet in question: import pygame win = pygame.display.set_mode((100,100)) width = 10 height = 40 pipex = 10 pipe1y = 10 pipe1 = pygame.draw.rect(win,(0, 255, 100), (width, height1)) pygame.win.blit(pipe1, pipex, pipe1y) pygame.display.update() And here's the full code: import pygame import time import random from bird import brd

My pygame rects are giving a rect argument is invalid error

安稳与你 提交于 2021-02-05 08:14:09
问题 I've been looking for a solution for this error for about 15 minutes now and no posts or other websites covered the specific error i've been having. Here's the code snippet in question: import pygame win = pygame.display.set_mode((100,100)) width = 10 height = 40 pipex = 10 pipe1y = 10 pipe1 = pygame.draw.rect(win,(0, 255, 100), (width, height1)) pygame.win.blit(pipe1, pipex, pipe1y) pygame.display.update() And here's the full code: import pygame import time import random from bird import brd

AttributeError: 'pygame.Surface' object has no attribute 'event'

社会主义新天地 提交于 2021-02-05 08:01:25
问题 I am creating my first game in python and was doing it part by part. Than I got this error message: AttributeError: 'pygame.Surface' object has no attribute 'event' My code: import pygame pygame.init() screen_width = 800 screen_height = 600 pygame = pygame.display.set_mode([screen_width,screen_width]) gameover = False while not gameover: for event in pygame.event.get(): print(event) 回答1: Because the module pygame is shadowed by the variable pygame that refers to the display Surface object.