pygame

nameError within Inheritance

丶灬走出姿态 提交于 2020-02-16 13:12:45
问题 When the program is run I get this error: Traceback (most recent call last): File "G:/assets/gametest1.py", line 141, in <module> cam = camera(318,0,220) File "G:/gametest1.py", line 85, in __init__ super(camera,self).__init__(playerposX,characterPosX,y) NameError: name 'characterPosX' is not defined The player class class player: def __init__(self, playerposX,characterPosX,y): self.playerposX = playerposX self.y = y self.width = 88 self.height = 135 self.standing = True self.left = False

pygame的安装(windows)

回眸只為那壹抹淺笑 提交于 2020-02-13 12:37:03
1.查看python版本 2.检查是否安装pip 3.下载pygame安装文件   下载地址: https://pypi.org/project/pygame/#files   选择合适的版本(我选择的是 python3.7 windows 64bit): 4.使用pip安装pygame   将下载好的文件移动到项目文件夹下,然后在命令行程序中运行安装命令 来源: https://www.cnblogs.com/alas/p/12302674.html

Can someone please explain this weird Pygame importing convention?

假装没事ソ 提交于 2020-02-11 15:51:25
问题 I see that people usually import Pygame like this: import pygame from pygame.locals import * I don't understand what's the second line for. If we already imported the whole of Pygame, why import pygame.locals ? Doesn't Pygame already include it once it's imported? 回答1: import pygame imports the pygame module into the "pygame" namespace. from pygame.locals import * copys all names in pygame.locals into your current namespace. This is not neccessary, but saves you typing. 回答2: Actually, from

pygame的使用

元气小坏坏 提交于 2020-02-09 12:28:07
Pygame的历史 Pygame是一个利用SDL库的写就的游戏库,SDL呢,全名Simple DirectMedia Layer,是一位叫做Sam Lantinga的大牛写的,据说他为了让Loki(致力于向Linux上移植Windows的游戏的一家大好人公司,可惜已经倒闭,唉好人不长命啊……)更有效的工作,创造了这个东东。 SDL是用C写的,不过它也可以使用C++进行开发,当然还有很多其它的语言,Pygame就是Python中使用它的一个库。Pygame已经存在很多时间了,许多优秀的程序员加入其中,把Pygame做得越来越好。 安装Pygame 可以从 www.pygame.org 下载pygame,选择合适你的操作系统和合适的版本,当然你也可以使用pip安装。安装成功后可用下面方法确认有没有安装成功: >>>import pygame pygame 1.9.6 Hello from the pygame community. https://www.pygame.org/contribute.html >>> 另外说一下,就产品而言,Pygame更致力于2D游戏的开发,也就是说,你可以用Pygame写一个植物大战僵尸,但是写一个魔兽世界则相当困难……请不要做出鄙夷的目光,底层的东西永远是相通的,而且对于新手而言,从简单的2D入手才是正途。 使用Pygame 模块名 功能

windows下python3.7环境安装pygame

半城伤御伤魂 提交于 2020-02-06 16:09:50
Pygame是一个强大的游戏扩展包,要安装pygame,在这之前要安装pip,安装setuptool。 一、首先安装setuptool: 下载:https://pypi.org/project/setuptools/#files setuptools-45.1.0.zip 解压;打开cmd,cd到解压目录,运行命令:python setup.py install 接下来安装pip: https://pypi.org/project/pip/#files 该网址下载tar文件,并解压 pip-20.0.2.tar.gz (1.4 MB) 安装失败 可能版本太高,又重新下载较低版本18.1 https://files.pythonhosted.org/packages/45/ae/8a0ad77defb7cc903f09e551d88b443304a9bd6e6f124e75c0fbbf6de8f7/pip-18.1.tar.gz 打开cmd,cd到解压目录,运行命令:python setup.py install 安装成功! 使用pip list 查看版本: D:\软件\python\pip-18.1>pip list Package Version ---------- ------- pip 18.1 setuptools 39.0.1 显示setuptools版本是39.0.1

Pygame display color and resolution distortion between versions

廉价感情. 提交于 2020-02-05 06:15:52
问题 I am making a game with pygame. One aspect of it forced me to upgrade to pygame2.00dev6, previously I was using pygame 1.9.6. Doing this resolved my initial problem, however created a few new ones. The first problem is I can no longer call the pygame.FULLSCREEN function properly anymore. In the old version, I would use: screen = pygame.display.set_mode((1600, 800), pygame.FULLSCREEN) I am aware the first parameter is redundant if I then call it into fullscreen, however when I didn't fill it

Windows操作系统下安装pygame

天大地大妈咪最大 提交于 2020-02-04 02:21:48
参考链接: https://blog.csdn.net/qq_38721302/article/details/83243632 https://www.cnblogs.com/mingkongluedong/p/9364530.html pygame的安装,我相信很多人都有点苦恼,第一:不知道去哪里寻找下载文件。第二:该下载哪个文件。第三:下载了正确文件后又该如何安装?这个随笔既是为了帮助大家快速下载pygame,也是为了以后自己忘记如何下载安装方可以有个提供回忆的便签! 我将从上面提出的三个问题来逐个解决pygame的下载安装过程! 第一:去哪里寻找pygame的下载文件? https://pypi.org/project/pygame/#files 第二:该下载哪个文件? 1.你首先应该明确自己的操作系统,如pygame的下载列表中提供了macos,linux,windows的下载文件,本文主要讲解windows,反正会在一种系统下安装了,其他系统的安装只不过是举一反三罢了!(这里我们采用windows系统) 2.你该下载哪个文件? 首先我们明确了是windows系统,于是我们找到带有win的文件,这个时候又要我们选择32位系统还是64位系统,如今的绝大多数系统都是64位,如果你不知道自己是多少位操作系统,可以去系统的设置里面寻找,实在找不到的可以下载驱动精灵http:/

Adding menu with buttons to pygame

断了今生、忘了曾经 提交于 2020-02-04 01:11:27
问题 I am trying to add a menu to my game for a very long time but it doesn't show up. There is a screen which comes up, however it is empty and only has words but no buttons, so no matter where I click, it takes me to the same page. Like a screen shows but the buttons don't appear and I am not sure why. How do I add a button for the options? background = pygame.image.load('background.png') backgroundX = 0 backgroundX2 = background.get_width() homeScreen = pygame.image.load('home_screen.png')

Can't hear the sounds I am tring to play with pygame

百般思念 提交于 2020-02-03 12:12:29
问题 I can't hear the sounds I am trying to play with pygame. This is my code. import pygame pygame.init() pygame.mixer.music.load(r"C:\Users\Isaiah\Desktop\easy_going.mp3") pygame.mixer.music.play() Any help would be great! Thanks! 回答1: MP3 support is limited with Pygame; use .wav instead. Fortunately you can easily convert .mp3 files to .wav files with an online conversions tool. You also need to add a delay loop at the end to keep your program from closing prematurely. Convert your .mp3 to a

Using pygame.time.set_timer

℡╲_俬逩灬. 提交于 2020-02-02 14:08:45
问题 I am making a game in Pygame and Python, a form of Asteroids. Every 10 seconds, the game should make another asteroid if there isn't more than 10 on the screen at a time. As I was looking over the example code on how to implement it, I saw that I have to use USEREVENT in the code. Could I replace this with a function? For example: def testfunc(): print "Test" pygame.time.set_timer(testfunc, 100) If I can't use the function this way, how would I use the USEREVENT with this code? Thanks EDIT: