pygame 相关问题

pygame是一组用于编写视频游戏的Python模块。只有在使用pygame库时才使用此标记,如果您对python中的游戏编程有疑问,请不要使用此标记。


写入midi文件

我想编写一个MIDI文件,其中包括我从数字钢琴中收到的输入。我正在使用pygame.midi打开输入端口和Midiutil来编写MIDI文件。我无法包裹我的...

回答 1 投票 0

阅读PyGame Display的当前标志(全屏等)

可以读取显示显示器的当前标志吗?因此,当一个人打电话给pygame.display.set_mode(分辨率,标志)时,我很想在之后阅读它们。 例如,我想哈...

回答 2 投票 0


带pygame set_alpha()设置图像透明度

aohoj, 在Pygame中,我试图设置图像的透明度。 我用这个: ship = pygame.image.load(os.path.join(dir,“ spacehip.png”)) ship.set_alpha(128) 问题: 该代码在MX

回答 2 投票 0


我将在pygame中使用OOP降低或等于0,无法找到一种重置玩家位置的方法 我正在创建一个2播放器相同屏幕游戏,该游戏使用键盘上的两个玩家都在同一台计算机上玩。我正在努力寻找一种在OOP中编写编码的方法,以便一旦戏剧之一...

class Player: def __init__(self, x, y, width, height, speed, images_right, images_left, idle_image): self.x = x self.y = y self.width = width self.height = height self.speed = speed self.left = False self.right = False self.jump_status = False self.jump_time = 10 self.anim_num = 0 self.images_right = images_right self.images_left = images_left self.idle_image = idle_image self.hitbox = (self.x + 17, self.y + 11, 29, 52) self.health = 10 self.visible = True self.maxhealth = 10 self.score = 0 self.start = (x,y) def hit(self): if self.health > 0: self.health -= 1 else: self.visible = False print('hit') class ResettableSprite: def __init__(self, idle_image, x, y): self.idle_image = idle_image self.rect = self.image.get_rect() self.start_x = x self.start_y = y self.reset() def reset(self): self.rect.x = self.start_x self.rect.y = self.start_y self.health = Player.maxhealth player1 = Player(200, 317, 64, 64, 10, walkRight, walkLeft, char) player2 = Player(500, 285, 92, 85, 10, walkRight2, walkLeft2, dragon)

回答 1 投票 0


文字仅在pygame

感谢您提前的帮助

回答 1 投票 0

Pygame等距网格?

是否有用于捕获等距网格的算法? 这是我想到的: DEF ISO(参数0,参数1): a = round(pygame.mouse.get_pos()[1]/gright1 -pygame.mouse.get_pos()[0]/

回答 1 投票 0


如何在python/pygame中制作按钮? 我在pygame上制作游戏,在第一个屏幕上,我希望有一个按钮,您可以按(i)启动游戏,(ii)加载带有指令的新屏幕,(iii)退出程序。 我...

#load_image is used in most pygame programs for loading images def load_image(name, colorkey=None): fullname = os.path.join('data', name) try: image = pygame.image.load(fullname) except pygame.error, message: print 'Cannot load image:', fullname raise SystemExit, message image = image.convert() if colorkey is not None: if colorkey is -1: colorkey = image.get_at((0,0)) image.set_colorkey(colorkey, RLEACCEL) return image, image.get_rect() class Button(pygame.sprite.Sprite): """Class used to create a button, use setCords to set position of topleft corner. Method pressed() returns a boolean and should be called inside the input loop.""" def __init__(self): pygame.sprite.Sprite.__init__(self) self.image, self.rect = load_image('button.png', -1) def setCords(self,x,y): self.rect.topleft = x,y def pressed(self,mouse): if mouse[0] > self.rect.topleft[0]: if mouse[1] > self.rect.topleft[1]: if mouse[0] < self.rect.bottomright[0]: if mouse[1] < self.rect.bottomright[1]: return True else: return False else: return False else: return False else: return False def main(): button = Button() #Button class is created button.setCords(200,200) #Button is displayed at 200,200 while 1: for event in pygame.event.get(): if event.type == MOUSEBUTTONDOWN: mouse = pygame.mouse.get_pos() if button.pressed(mouse): #Button's pressed method is called print ('button hit') if __name__ == '__main__': main()

回答 6 投票 0



试图在pygame上做一个自上而下的射手,并在玩家移动时试图弄清楚如何滚动地图时遇到了麻烦 我目前正在尝试制作一个自上而下的射击游戏,但是当角色移动时(向上,向下,左和右)时,我遇到了一些麻烦,试图弄清楚如何移动地图。我想要地图...

我目前正在尝试制作一个自上而下的射击游戏,但是当角色移动时(向上,向下,左和右)时,我遇到了一些麻烦,试图弄清楚如何移动地图。我希望地图始终填充屏幕,但是当角色移动时,地图将随着图像移动。我已经在网上寻找寻找一些解决方案,但是很难将其实施到我自己的程序中。

回答 1 投票 0






最新问题
© www.soinside.com 2019 - 2025. All rights reserved.