pygame

How do you assign a “rect” attribute to a pygame.sprite.rect rectangle in Pygame?

你说的曾经没有我的故事 提交于 2021-02-04 07:41:49
问题 This question has been asked before, but the code they answer doesn't apply to me. I want to check when two rectangles collide in my game, and for the circle, I put a rectangle behind the circle(it's colored black). However, when I run, I get an error saying the rectangle needs to have a rect attribute. Here is my code: clock = pygame.time.Clock() pygame.init() change = False screen = pygame.display.set_mode((400, 300)) done = False x = 100 y = 30 bound = False while not done: for event in

How do you assign a “rect” attribute to a pygame.sprite.rect rectangle in Pygame?

痴心易碎 提交于 2021-02-04 07:41:29
问题 This question has been asked before, but the code they answer doesn't apply to me. I want to check when two rectangles collide in my game, and for the circle, I put a rectangle behind the circle(it's colored black). However, when I run, I get an error saying the rectangle needs to have a rect attribute. Here is my code: clock = pygame.time.Clock() pygame.init() change = False screen = pygame.display.set_mode((400, 300)) done = False x = 100 y = 30 bound = False while not done: for event in

How to display dynamically in Pygame? [duplicate]

狂风中的少年 提交于 2021-02-04 07:41:27
问题 This question already has answers here : Countdown timer in Pygame (7 answers) Closed 1 year ago . I am able to display a number "1" on my display. Now, my goal is to display the numbers 1...4. That means "1" is displayed first, then after 1 "2" is displayed, etc. How to solve that problem? Here is my code: import pygame import time pygame.init() screen = pygame.display.set_mode((640, 480)) clock = pygame.time.Clock() done = False font = pygame.font.SysFont("comicsansms", 72) text = font

Pygame Wont Let Me Draw A Circle Error argument 3 must be sequence of length 2, not 4

你离开我真会死。 提交于 2021-02-04 07:29:05
问题 I am trying to draw a circle with pygame but I keep getting this error error argument 3 must be sequence of length 2, not 4 class circle: def __init__(self,x,y,height,width,color): self.x =x self.y = y self.height = height self.width = width self.color = color self.rect = pygame.Rect(x,y,height,width) def draw(self): self.rect.topleft = (self.x,self.y) pygame.draw.circle(window,self.color,self.rect,20) circle1 = circle(300,200,20,20,white) 回答1: The 3rd argument of pygame.draw.circle is the

Pygame Wont Let Me Draw A Circle Error argument 3 must be sequence of length 2, not 4

三世轮回 提交于 2021-02-04 07:29:05
问题 I am trying to draw a circle with pygame but I keep getting this error error argument 3 must be sequence of length 2, not 4 class circle: def __init__(self,x,y,height,width,color): self.x =x self.y = y self.height = height self.width = width self.color = color self.rect = pygame.Rect(x,y,height,width) def draw(self): self.rect.topleft = (self.x,self.y) pygame.draw.circle(window,self.color,self.rect,20) circle1 = circle(300,200,20,20,white) 回答1: The 3rd argument of pygame.draw.circle is the

PYGAME - Move Character with Vector

为君一笑 提交于 2021-02-04 07:27:32
问题 I am teaching myself pygame and am looking at making my character able to rotate and then move in the direction they are facing. I can do the rotation but cannot get the character to move in the direction the image is then facing. The code is on Trinket HERE class Bob(pygame.sprite.Sprite): def __init__(self, color , height , width): super().__init__() self.image = pygame.Surface([width , height]) self.image.fill(BLACK) self.image.set_colorkey(BLACK) #Loading the image for the character self

converting the difference in vectors to between 0 and 1

左心房为你撑大大i 提交于 2021-02-04 07:27:05
问题 I'm working with two unit vectors but not sure how to calculate this. I need it so that if they point in the same direction the answer is 1, opposite directions the answer is 0, perpendicular (either up or down) the answer is 0.5, etc. Examples: For two vectors (1,0) and (-1,0) (so, opposite vectors), the answer I get is 0. For two vectors (1,0) and (1/sqrt(2),1/sqrt(2)) (so, the unit vector pointing at a 45 degree angle) I get 0.25. For two vectors (0,1) and (-1,0) (so, perpendicular vectors

Pygame: how to write event-loop polymorphically

醉酒当歌 提交于 2021-02-04 06:16:51
问题 I'm some-what new to pygame, and while trying to get back into it, I found the advice "replace your conditionals with polymorphism." Most pygame tutorials recommend using the "for event in pygame.event.get()" loop and then using a conditional to determine if any particular event has occured. 1: How do I write that code using a polymorphic function 2: Is it worth it to re-factor the code, or just leave the conditional as-is Below is what most tutorials recommend def gameloop(): """ Stuff that

Pygame Tic Tak Toe Logic? How Would I Do It

瘦欲@ 提交于 2021-02-04 05:35:05
问题 I am trying to make a tic tak toe game with pygame and I was wondering how would I do the logic here is what I have so far. VIDEO < I only have it when I click on the middle button it will display the player 2 x on the screen and then the image that is hovering over my mouse will turn into O for player 1 turn to go BUT my question is how would I do the logic like if player 1 gets 3 in a row or player 2 gets 3 across in a row I am really confused on this and I need someone to walk me throw it

Pygame Tic Tak Toe Logic? How Would I Do It

风格不统一 提交于 2021-02-04 05:34:30
问题 I am trying to make a tic tak toe game with pygame and I was wondering how would I do the logic here is what I have so far. VIDEO < I only have it when I click on the middle button it will display the player 2 x on the screen and then the image that is hovering over my mouse will turn into O for player 1 turn to go BUT my question is how would I do the logic like if player 1 gets 3 in a row or player 2 gets 3 across in a row I am really confused on this and I need someone to walk me throw it