pygame

Pygame MemoryError

感情迁移 提交于 2020-01-10 04:12:07
问题 HI i wrote a simple block collecting program that was working just fine and dandy until i added sound. Then all the sudden i get a MemoryError which is something ive never seen before. my code is attached along with the sound(wav) file that seem to be the problem. Any help would be great, and yes the code and the sound are in the same folder along with tons of other programs and pictures and stuff. import pygame import random import pygame.mixer winsound=pygame.mixer.Sound('winning.wav')

通过创建一个简单的骰子游戏来探究 Python

谁说我不能喝 提交于 2020-01-09 20:30:33
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 在我的这系列的第一篇文章 中, 我已经讲解如何使用 Python 创建一个简单的、基于文本的骰子游戏。这次,我将展示如何使用 Python 模块 Pygame 来创建一个图形化游戏。它将需要几篇文章才能来得到一个确实做成一些东西的游戏,但是到这系列的结尾,你将更好地理解如何查找和学习新的 Python 模块和如何从其基础上构建一个应用程序。 在开始前,你必须安装 Pygame。 安装新的 Python 模块 有几种方法来安装 Python 模块,但是最通用的两个是: 从你的发行版的软件存储库 使用 Python 的软件包管理器pip 两个方法都工作的很好,并且每一个都有它自己的一套优势。如果你是在 Linux 或 BSD 上开发,可以利用你的发行版的软件存储库来自动和及时地更新。 然而,使用 Python 的内置软件包管理器可以给予你控制更新模块时间的能力。而且,它不是特定于操作系统的,这意味着,即使当你不是在你常用的开发机器上时,你也可以使用它。pip 的其它的优势是允许本地安装模块,如果你没有正在使用的计算机的管理权限,这是有用的。 使用 pip 如果 Python 和 Python3 都安装在你的系统上,你想使用的 命令 很可能是 pip3,它用来区分 Python 2.x 的 pip 的 命令

揭秘2019年Python这一款“小兔子和Bun”游戏,附赠游戏源码文件

大兔子大兔子 提交于 2020-01-09 20:13:23
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 导语 这又将是一个不定期更新的系列~~~ 本系列主要将使用到python的pygame模块来教大家制作一些小游戏,每期制作一个。最后都会打包成.exe文件分享给大家~~~ So,对于只想玩小游戏的小伙伴来说,只需要下载相关文件就好啦~~~ 至于pygame的开发文档,暂时没有归入整理计划,来日方长,英文不好的同学只能先看网上中文的资料将就下了~~~ 准备工作:安装Python python版本:3.5.4 pygame版本:1.9.3(pip安装即可) 愉快地开始 Step1:你好,兔子 效果: Step2:添加背景 首先载入所需的图片;其次依次通过x和y进行循环,并且根据循环里x和y的值来画上草的效果;接下来的几行就是在屏幕上画出城堡。 效果: Step3:让兔子能够移动 接下来你需要加上一些真正的游戏的元素了,比如让兔子能够随着按键移动。 效果(可以移动兔子): Step4:让兔子转向 好的,现在你的兔子在你按键的时候可以移动了,但是如果你能用鼠标让兔子朝向你选择的方向不是更酷吗?这样它就不会总是朝向一个方向了。 效果: Step5:射击吧!兔子 让兔子用箭头射向它们的敌人,这一步会有一点复杂,因为你需要跟踪所有的箭头,更新它们,旋转它们,在它们跑出屏幕的时候删除它们。 效果: Step6:獾,拿上武器!

Draw a transparent rectangle in pygame

核能气质少年 提交于 2020-01-09 04:17:10
问题 How can I draw a rectangle that has a color with an alpha? I have: windowSurface = pygame.display.set_mode((1000, 750), pygame.DOUBLEBUF) pygame.draw.rect(windowSurface, pygame.Color(255, 255, 255, 128), pygame.Rect(0, 0, 1000, 750)) But I want the white rectangle to be 50% transparent, but the alpha value doesn't appear to be working. 回答1: pygame.draw functions will not draw with alpha. The documentation says: Most of the arguments accept a color argument that is an RGB triplet. These can

pygame on OSX Yosemite: unrecognized music format

99封情书 提交于 2020-01-07 09:25:14
问题 I'm playing around with Pygame on my Mac, running OSX Yosemite. I can't get it to play an MP3 file using the following code: pygame.mixer.music.load('bg_music.mp3') pygame.error: Unrecognized music format I'm using Python 2.7.1 and have the following libraries installed: sdl (brew): 1.2.15 sdl_mixer (brew): 1.2.12 libvorbis (brew): 1.3.4 pygame: 1.9.2a0 I've searched around and tried all the suggestions on this thread without success. Does anyone have any ideas how I can get this thing to

Use keyboard without calling pygame.display.set_mode

强颜欢笑 提交于 2020-01-07 09:04:14
问题 Does pygame.display.set_mode have to be used to utilize the keyboard keys? Once I added it to my code everything worked - but I do not want to open a pygame window. Does anyone know how to utilize the keyboard without having to call pygame.display.set_mode ? 回答1: You have to use pygame.display.set_mode to create a window, since it's this very window that recieves the keyboard events from your OS' window manager. You can run pygame without a window (by setting the environment variable SDL

python default argument syntax error

不问归期 提交于 2020-01-07 09:03:23
问题 I just wrote a small text class in python for a game written using pygame and for some reason my default arguments aren't working. I tried looking at the python documentation to see if that might give me an idea what I did wrong, but I didn't fully get the language in the documentation. No one else seems to be having this issue. Here's the code for the text class: class Text: def __init__(self,screen,x_location='center',y_location='center',writeable,color,size=12): self.font = pygame.font

Animation in with a list of images in Pygame

我的未来我决定 提交于 2020-01-07 03:51:23
问题 I've been suck on my Flappy Bird clone. If you don't know the game, there is an animation that happens when the bird fly up. Here is a general idea of how I tried to do an animation: self.x and self.y refer to the position of the photo Here is my code: def move_up_animation(self): #list of bird photos to animate animation_list = ['1.tiff','2.tiff','3.tiff','4.tiff','5.tiff'] for i in range(len(animation_list)): if self.y - 1 > 0: # checks if the bird is within the frame self.y = self.y - 1

Animation in with a list of images in Pygame

点点圈 提交于 2020-01-07 03:51:08
问题 I've been suck on my Flappy Bird clone. If you don't know the game, there is an animation that happens when the bird fly up. Here is a general idea of how I tried to do an animation: self.x and self.y refer to the position of the photo Here is my code: def move_up_animation(self): #list of bird photos to animate animation_list = ['1.tiff','2.tiff','3.tiff','4.tiff','5.tiff'] for i in range(len(animation_list)): if self.y - 1 > 0: # checks if the bird is within the frame self.y = self.y - 1

Pygame “No module called pygame.base”

陌路散爱 提交于 2020-01-07 03:10:42
问题 When I download pygame-1.9.2b8-cp36-cp36m-win32.whl from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame I turn it into zip, take the headers in the pygame-1.9.2b8.data folder into pygame34/include/pygame and I put the other pygame file from the zip in the site-packages folder together with pygame-1.9.2b8.data as any tutorial shows, I always get this error: Traceback (most recent call last): File "C:/Users/andsa/PycharmProjects/THIS WORKS ANDREAS/Games.py", line 1, in <module> import pygame