pygame

How to resize button after resizing pygame window?

旧时模样 提交于 2020-12-15 04:36:28
问题 I have a menu (main_menu), that has a Button and I want this button to stay in the middle after I resize the window. The program does draw a new button in the middle of the window but the old button is still visible and I cant figure out why. I tried to fill the screen with the background color again and then draw a new button, but the old one was still visible... Any Ideas ? WINDOW_W , WINDOW_H = 1200, 800 SCREEN = pg.display.set_mode((WINDOW_W,WINDOW_H),pg.RESIZABLE) main_menu = Main_Menu

SpriteCollide Only Running Once Per Collision

时光怂恿深爱的人放手 提交于 2020-12-14 06:40:13
问题 I'm checking missileGroup to see if any instances of missile collided with any instances enemy in enemyGroup . When run, it prints "Hit" for the first loop, but it ignores the second for loop. Why is that? #### Imagine this is in a game loop #### for missile in missileGroup: if pygame.sprite.spritecollide(missile, enemyGroup, False) : print("Hit") for enemy in enemyGroup: if pygame.sprite.spritecollide(enemy, missileGroup, False) == True: print("HI") 回答1: pygame.sprite.spritecollide() doesn't

SpriteCollide Only Running Once Per Collision

隐身守侯 提交于 2020-12-14 06:39:42
问题 I'm checking missileGroup to see if any instances of missile collided with any instances enemy in enemyGroup . When run, it prints "Hit" for the first loop, but it ignores the second for loop. Why is that? #### Imagine this is in a game loop #### for missile in missileGroup: if pygame.sprite.spritecollide(missile, enemyGroup, False) : print("Hit") for enemy in enemyGroup: if pygame.sprite.spritecollide(enemy, missileGroup, False) == True: print("HI") 回答1: pygame.sprite.spritecollide() doesn't

How to drag multiple images in PyGame? [duplicate]

自闭症网瘾萝莉.ら 提交于 2020-12-14 06:26:48
问题 This question already has an answer here : How can I drag more than 2 images in PyGame? (1 answer) Closed last month . import pygame from pygame.locals import * pygame.display.init() screen = pygame.display.set_mode((1143,677 )) img = pygame.image.load(r"C:\Users\ga-sa\Downloads\As.png") imgPos = pygame.Rect((0, 0), (0, 0)) LeftButton = 0 while 1: for e in pygame.event.get(): if e.type == QUIT: exit(0) if e.type == MOUSEMOTION: if e.buttons[LeftButton]: rel = e.rel imgPos.x += rel[0] imgPos.y

How to drag multiple images in PyGame? [duplicate]

人走茶凉 提交于 2020-12-14 06:26:43
问题 This question already has an answer here : How can I drag more than 2 images in PyGame? (1 answer) Closed last month . import pygame from pygame.locals import * pygame.display.init() screen = pygame.display.set_mode((1143,677 )) img = pygame.image.load(r"C:\Users\ga-sa\Downloads\As.png") imgPos = pygame.Rect((0, 0), (0, 0)) LeftButton = 0 while 1: for e in pygame.event.get(): if e.type == QUIT: exit(0) if e.type == MOUSEMOTION: if e.buttons[LeftButton]: rel = e.rel imgPos.x += rel[0] imgPos.y

Python/Pygame make text in Pygame wrap when in leaves the window [duplicate]

守給你的承諾、 提交于 2020-12-13 19:07:10
问题 This question already has answers here : Rendering text with multiple lines in pygame (9 answers) Closed last month . I have a text function that render text.The function is the following def textFunc(font,msg,color,x,y,center): text_render = font.render(msg,True,color) text_rect = text_render.get_rect() #If center is true, then the X,Y will be used as the center if center == True: text_rect.center = (x,y) else: text_rect = (x,y) game_display.blit(text_render,text_rect) However is my msg

【pygame】Python 制作五子棋人机对战

只愿长相守 提交于 2020-12-13 10:57:00
本文代码基于 python3.6 和 pygame1.9.4。 五子棋比起我之前写的几款游戏来说,难度提高了不少。如果是人与人对战,那么,电脑只需要判断是否赢了就可以。如果是人机对战,那你还得让电脑知道怎么下。 我们先从简单的问题来看。 开端 画棋盘 首先肯定是要画出棋盘来,用 pygame 画出一个 19 × 19 或 15 × 15 的棋盘并不是什么难事,这在之前的文章中已经多次用到,就不赘述了。 画棋子 需要说一下的是画棋子,因为没找到什么合适的棋子图片,所以只要自己来画棋子。 我们用 pygame.draw.circle 画出来的圆形是这样的: 锯齿状十分明显, pygame.draw 中有画抗锯齿直线的函数 aaline ,但是并没有 aacircle 这样的函数来画一个抗锯齿的圆。 这里就需要用到 pygame.gfxdraw 啦。 pygame.gfxdraw 目前还仅是实验版本,这意味着这个 API 可能会在以后的 pygame 版本中发生变化或消失。 要绘制抗锯齿和填充形状,请首先使用函数的aa *版本,然后使用填充版本。例如: col = (255, 0, 0) surf.fill((255, 255, 255)) pygame.gfxdraw.aacircle(surf, x, y, 30, col) pygame.gfxdraw.filled_circle

drawing an image for a set number of frames pygame

冷暖自知 提交于 2020-12-13 10:06:41
问题 How would I make an image stay on the screen for a set number of frames in pygame? I am trying to make Simon. I need a square to light up for a certain number of time and then return to its original color. import pygame pygame.init() clock = pygame.time.Clock() screen = pygame.display.set_mode((500,500)) Colors = ['Blue', 'Yellow'] while True: clock.tick(60) for i in range(len(Colors)): if Colors[i] == 'Yellow': pygame.draw.rect(screen,(153,153,0),(#bottom left coords)) # after 20 frames pass

drawing an image for a set number of frames pygame

依然范特西╮ 提交于 2020-12-13 10:02:58
问题 How would I make an image stay on the screen for a set number of frames in pygame? I am trying to make Simon. I need a square to light up for a certain number of time and then return to its original color. import pygame pygame.init() clock = pygame.time.Clock() screen = pygame.display.set_mode((500,500)) Colors = ['Blue', 'Yellow'] while True: clock.tick(60) for i in range(len(Colors)): if Colors[i] == 'Yellow': pygame.draw.rect(screen,(153,153,0),(#bottom left coords)) # after 20 frames pass

drawing an image for a set number of frames pygame

家住魔仙堡 提交于 2020-12-13 10:02:28
问题 How would I make an image stay on the screen for a set number of frames in pygame? I am trying to make Simon. I need a square to light up for a certain number of time and then return to its original color. import pygame pygame.init() clock = pygame.time.Clock() screen = pygame.display.set_mode((500,500)) Colors = ['Blue', 'Yellow'] while True: clock.tick(60) for i in range(len(Colors)): if Colors[i] == 'Yellow': pygame.draw.rect(screen,(153,153,0),(#bottom left coords)) # after 20 frames pass