pygame

ImportError: No module named 'pygame'

江枫思渺然 提交于 2019-12-28 02:04:53
问题 I have installed python 3.3.2 and pygame 1.9.2a0. Whenever I try to import pygame by typing: import pygame I get following error message : Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import pygame Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> import pygame ImportError: No module named 'pygame' >>> I went through some of the questions related to

使用pygame制作一个贪吃蛇的小游戏

◇◆丶佛笑我妖孽 提交于 2019-12-27 20:39:56
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 之前我们已经学习了如果使用pygame创建一个窗口,现在我们来学习使用pygame来制作一个经典的小游戏--贪吃蛇。 首先我们需要导入待使用的模块: import pygame, sys, random from pygame.locals import * pygame.locals 模块 包含pygame使用的各种常量,它的内容会被自动放入到 Pygame 模块的名字空间中。 模块导入之后我们可以先定义好会用到的颜色,根据大家的喜好定义: # 定义颜色 pinkColor = pygame.Color(255, 182, 193) blackColor = pygame.Color(0, 0, 0) whiteColor = pygame.Color(255, 255, 255) pygame.Color() 是用于描述颜色的对象, Color(name) -> Color Color(r, g, b , a) -> Color Color(rgbvalue) –>Color # Color对象的方法&属性 pygame.Color.r :获取或者设置Color对象的红色值 pygame.Color.g :获取或者设置Color对象的绿色值 pygame.Color.b :获取或者设置Color对象的蓝色值

一步步教你怎么用python写贪吃蛇游戏

老子叫甜甜 提交于 2019-12-27 20:03:26
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 目录 0 引言 1 环境 2 需求分析 3 代码实现 4 后记 0 引言 前几天,星球有人提到贪吃蛇,一下子就勾起了我的兴趣,毕竟在那个Nokia称霸的年代,这款游戏可是经典中的经典啊!而用Python(蛇)玩Snake(贪吃蛇),那再合适不过了🤣🤣🤣 先通过下面这个效果图来感受下吧! 1 环境 操作系统:Windows Python版本:3.7.3 2 需求分析 我们先来回顾下贪吃蛇中的游戏元素及游戏规则。 首先呢,需要有贪吃蛇、有食物;需要能控制贪吃蛇来上下移动获取食物;贪吃蛇在吃取食物后,自身长度增加,同时食物消失并随机生成新的食物;如果贪吃蛇触碰到四周墙壁或是触碰到自己身体时,则游戏结束。 游戏规则就是这么简单,接下来我们借助一个第三方库pygame来实现它。 Pygame是一个利用SDL库的游戏库, 是一组用来开发游戏软件的 Python 程序模块。 SDL(Simple DirectMedia Layer)是一个跨平台库,支持访问计算机多媒体硬件(声音、视频、输入等),SDL非常强大,但美中不足的是它是基于 C 语言的。 PyGame是 SDL 库的 Python 包装器(wrapper),Pygame 在SDL库的基础上提供了各种接口

pygame制作flappy bird小游戏

≯℡__Kan透↙ 提交于 2019-12-26 19:35:21
Python弱智,请各位大神勿喷 思路:flappy bird的游戏过程非常简单: 1. 小鸟会自动往前飞行,在往前飞行的过程中,自身会往下以一定速度下坠(实际游戏可能是有加速度,我暂时以固定速度) 2. 飞行过程中的管道随机从图片上下方生成,同时生成的管道必须给小鸟留有一定的空间飞过去。 3. 每次点击或键盘敲击都会使小鸟往上飞行一段距离,持续按键盘不会使小鸟一直往上飞 4. 小鸟碰到管道或者碰到屏幕边缘游戏会结束。 步骤: 实现过程和创建飞机大战过程十分类似,而且比飞机大战还要简单。 1. 与飞机大战类似,我先创建了两个文件一个游戏运行的主文件flappy_bird_main.py和一个用来创建类的工具类文件flappy_bird_sprite.py 2. Flappy_bird_main.py文件需要完成的内容: a) 完成游戏主页面的绘制,创建游戏时钟来保证每秒运行60帧 b) 创建游戏对象: i. 创建游戏中所有的精灵对象:游戏背景(需要两张来保证小鸟运动过程背景的连续性) ii. 创建管道,我比较笨,为了在背景图像上生成上下部分两个管道,所以就创建了上管道对象,和下管道对象。同时他们生成的时间要保持一致,要有时间间隔 iii. 创建小鸟。 c) 开始游戏的函数: i. 设置游戏刷新率 ii. 监听事件:(键盘事件,鼠标事件,内置事件) iii. 碰撞检测

Pygame not using specified font

纵然是瞬间 提交于 2019-12-25 19:48:07
问题 So I am having a problem in pygame where I specify the font and size to use, but when my program is run, the font and size are the default. Here is where I define the text def font(self): '''*****FATAL - THIS LINE CAUSES ERROR (When compiled to .exe using cx_freeze)*****''' #font = pygame.font.SysFont("Coure", 20) font_color = (0, 0, 0) font = pygame.font.Font("coure.fon", 20) self.text = font.render("Level "+str(self.level) + " " + self.name + " Health " + str(self.health), True, font_color)

Create multiple instances of a class

元气小坏坏 提交于 2019-12-25 18:17:05
问题 I'm working on a space invaders type of game in Pygame. So far I just have the basics of the game down: import pygame, sys, os, math, random, time from pygame.locals import * pygame.init() window = pygame.display.set_mode((1000,500)) screen = pygame.display.get_surface() spaceBackground = pygame.image.load("C:/Users/LN/Desktop/space-background.png") spaceShip = pygame.image.load("C:/Users/LN/Desktop/space-ship.png") bullet = pygame.image.load("C:/Users/LN/Desktop/bullet.png") enemyShip =

Playing music in Pygame causes an assertion failure message

我只是一个虾纸丫 提交于 2019-12-25 17:47:30
问题 I'm having trouble playing music in Pygame. I type: pygame.mixer.music.load("Maid with the Flaxen Hair.mp3") pygame.mixer.music.play(-1, 0.0) but I get this message: Assertion failed! Program: C\Python33\pythonw.exe File:..\..\audio\mpegtoraw.cpp Line: 505 Expression: audio->rawdatawriteoffset > len Then it tells me to see C++ documentation. It's not the loading of the music, it's the playing that causes the message. I tried different music files too. 回答1: Just to update, I had the same error

cx_freeze app opens then closes quickly

▼魔方 西西 提交于 2019-12-25 17:02:15
问题 i am trying to turn my python game into an exe file using cx_Freeze. The build finishes but i cannot open the app. I ran it in cmd and it says: __import__(name+"__init__") ImportError:No module named 'pygame.py__init__' not sure what this means here is my setup code: import cx_Freeze import os executables = [cx_Freeze.Executable("pygame.py.py")] os.environ['TCL_LIBRARY'] = "C:\\New folder\\tcl\\tcl8.6" os.environ['TK_LIBRARY'] = "C:\\New folder\\tcl\\tk8.6" cx_Freeze.setup( name="Speed",

pygame initialize framebuffer or x server

女生的网名这么多〃 提交于 2019-12-25 11:55:33
问题 I have a class that checks for suitable framebuffer, and it works fine. One a couple of computers (mostly embedded older boards) there is no framebuffer, so I remove the init (self): function and manually set it to run under X. Both ways work on their respective systems, I'm just tired of porting it every time I make a change. Here is the working framebuffer code: class wxdisplay : screen = None; def __init__(self): "Ininitializes a new pygame screen using the framebuffer" # Based on "Python

Can't create games with pygame

陌路散爱 提交于 2019-12-25 11:25:15
问题 I make a game with python 2.5 and pygame. but,I can't complete make. because this errors occured. C:\Python26\TypeType\src\dist\Main.exe:8: RuntimeWarning: use font: MemoryLoadLibrary failed loading pygame\font.pyd Traceback (most recent call last): File "Main.py", line 8, in <module> File "pygame\__init__.pyo", line 70, in __getattr__ NotImplementedError: font module not available Traceback (most recent call last): File "Main.py", line 8, in <module> File "pygame\sysfont.pyo", line 253, in