pygame

I am wondering why it says the distance has to be less than 27? Why less than 27? Where is 27 coming from?

♀尐吖头ヾ 提交于 2021-02-05 10:50:09
问题 My teacher gave us this code to analyze and I am not sure why he put 27 there for collision.. I asked him he said if the distance between the player and the enemy is less than 27 then I will call it a collision, but I still don't understand, can someone please kindly explain it to me in simpler terms. I don't understand where the number 27 comes from.. when my dimensions are so big? import math import random import pygame # Intialize the pygame pygame.init() # create the screen screen =

How to make enemies fall at random on pygame?

允我心安 提交于 2021-02-05 10:48:11
问题 I want enemies to randomly fall from the sky on my game and I do not know how to do this. I was using this youtube video: Falling Objects in Pygame. import pygame, random pygame.init() screen_width = 800 screen_height = 600 window = pygame.display.set_mode((screen_width, screen_height)) pygame.display.set_caption('Test') time = pygame.time.Clock() bg_color1 = (135, 142, 142) # MAIN BG COLOR bg_color2 = (255, 0, 0) # red bg_color3 = (255, 255, 0) # yellow UFO = pygame.image.load('ufo.png') bg

pygame.display.update() error: video system not initialized

我与影子孤独终老i 提交于 2021-02-05 10:46:11
问题 import pygame from pygame.locals import* def main(): global FPSCLOCK, DISPLAYSURF, BASICFONT, PLAY_SURF, PLAY_RECT, NEW_SURF, NEW_RECT, SOLVE_SURF, SOLVE_RECT black = ( 0, 0, 0) Aqua = ( 0, 255, 255) Blue = ( 0, 0, 255) Fuchsia = (255, 0, 255) Gray = (128, 128, 128) Green =( 0, 128, 0) Lime =( 0, 255, 0) Maroon= (128, 0, 0) NavyBlue = ( 0, 0, 128) Olive =(128, 128, 0) Purple =(128, 0, 128) Red= (255, 0, 0) Silver =(192, 192, 192) Teal =( 0, 128, 128) White =(255, 255, 255) Yellow =(255, 255,

PyGame Invalid Position For Blit

不羁岁月 提交于 2021-02-05 09:39:18
问题 I am creating a small level designer in Python (using PyGame). The program is supposed to just let you place down an image, change between images, export to a PNG file, and export image path and coordinates to where it was place in a text document. I have gotten all of these components to work, but I am stuck with one last component, and that is reading the text document back into PyGame, and re-placing all of the images in the correct places with the correct sprites. The way that I have it

python/pygame, pass input from a class to another class

只愿长相守 提交于 2021-02-05 09:33:08
问题 there is a way to pass a value or a variable from a class to another class without having to pass through the main function I'm using python 回答1: well, of course you can access other objects attributes in methods of a specific object. e.g: class A(object): def method(self, other): other.somevar = 5 class B(object): pass def main(): a = A() b = B() b.somevar = "Hello World" a.method(b) print(b.somevar) # now prints '5' 来源: https://stackoverflow.com/questions/7610531/python-pygame-pass-input

python/pygame, pass input from a class to another class

你。 提交于 2021-02-05 09:31:02
问题 there is a way to pass a value or a variable from a class to another class without having to pass through the main function I'm using python 回答1: well, of course you can access other objects attributes in methods of a specific object. e.g: class A(object): def method(self, other): other.somevar = 5 class B(object): pass def main(): a = A() b = B() b.somevar = "Hello World" a.method(b) print(b.somevar) # now prints '5' 来源: https://stackoverflow.com/questions/7610531/python-pygame-pass-input

How do you make Pygame stop for a few seconds?

做~自己de王妃 提交于 2021-02-05 09:27:53
问题 I know this is a simple problem and I could just use the time function or something, but it's somehow still a problem to me. So I have this: letter = pygame.image.load('w00.png') screen.blit(letter, (letter_x, 625)) letter_x += 30 letter = pygame.image.load('e-2.png') screen.blit(letter, (letter_x, 625)) letter_x += 30 letter = pygame.image.load('l-2.png') screen.blit(letter, (letter_x, 625)) letter_x += 30 letter = pygame.image.load('c-2.png') screen.blit(letter, (letter_x, 625)) letter_x +=

how to make circular surface in pygame

戏子无情 提交于 2021-02-05 09:23:06
问题 I need to create a surface that has a bounding circle. Anything drawn on that surface should not be visible outside that bounding circle. I've tried using masks, subsurfaces, srcalpha, etc., but nothing seems to work. My attempt: w = ss.get_width () h = ss.get_height () TRANSPARENT = (255, 255, 255, 0) OPAQUE = ( 0, 0, 0, 225) crop = pygame.Surface ((w, h), pygame.SRCALPHA, ss) crop.fill (TRANSPARENT) c = round (w / 2), round (h / 2) r = 1 pygame.gfxdraw. aacircle (crop, *c, r, OPAQUE) pygame

Need help an error “TypeError: __init__() takes 5 positional arguments but 6 were given”

情到浓时终转凉″ 提交于 2021-02-05 09:13:47
问题 I am just started getting into classes and understand the basic concept however I don't understand why it gives me this error. My code: import pygame pygame.init() screen = pygame.display.set_mode((400, 300)) done = False while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True class shape(): def __init__(self, place, colour, x, y): self.place = place self.colour = colour self.x = x self.y = y class rectangle(shape): def __init__(self, place, colour, x, y,

Need help an error “TypeError: __init__() takes 5 positional arguments but 6 were given”

随声附和 提交于 2021-02-05 09:13:25
问题 I am just started getting into classes and understand the basic concept however I don't understand why it gives me this error. My code: import pygame pygame.init() screen = pygame.display.set_mode((400, 300)) done = False while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True class shape(): def __init__(self, place, colour, x, y): self.place = place self.colour = colour self.x = x self.y = y class rectangle(shape): def __init__(self, place, colour, x, y,