pygame

Python

北城以北 提交于 2020-04-19 10:47:53
【windows 安装Python】 因为在安装时,会提醒同步配置环境变量。因此按照步骤安装即可。 什么是Python? Python是一种跨平台的计算机程序设计语言,是一个高层次的结合了解、编译、互动和面向对象的脚本语言。 最初是用于编写shell脚本,现在功能是越来越强大了。 Python是怎么执行的? Python在执行时,首先会将.py文件中的源代码编译成Python的bytecode字节码,然后再由Python虚拟机来执行这些编译好的byte code。好像与Java呀,.NET类似哈。 Python虚拟机与他们不同的是,Python虚拟机是一种更高级的虚拟机,它是一种抽象层次更高的虚拟机。 Python可以以交互模式运行,比如主流操作系统Unix/Linux、Mac、Windows都可以通过交互模式运行。。 Python基本应用 1、图形处理:有PIL、Tkinter等图形库支持,能方便进行图形处理。 2、数学处理:NumPy扩展提供大量与许多标准数学库的接口。 3、文本处理:python提供的re模块能支持正则表达式,还提供SGML,XML分析模块,许多程序员利用python进行XML程序的开发。 4、数据库编程:程序员可通过遵循Python DB-API(数据库应用程序编程接口)规范的模块与Microsoft SQL Server,Oracle,Sybase,DB2

Path-finding in 2D space

时间秒杀一切 提交于 2020-04-18 05:37:09
问题 I am creating a game where I want an enemy to path track onto the player - who can move in any direction on the 2D plane. At first, I tried... self.bat_x += (player_rect.centerx - self.rect.centerx) / 60 self.bat_y += (player_rect.centery - self.rect.centery) / 60 Here the path-tracking works fine. I divide each value by 60 so that the enemy doesn't just appear and stick on to my player / to slow the movement of the enemy down. However, the further away the enemy is, the faster it is. The

Updating multiple items in a class, not just one

拥有回忆 提交于 2020-04-16 08:34:43
问题 In the update section of this code, only the first bat that gets made is affected by update() in class Bat()... Outside of main loop: START_BAT_COUNT = 30 BAT_IMAGE_PATH = os.path.join( 'Sprites', 'Bat_enemy', 'Bat-1.png' ) bat_image = pygame.image.load(BAT_IMAGE_PATH).convert_alpha() bat_image = pygame.transform.scale(bat_image, (80, 70)) class Bat(pygame.sprite.Sprite): def __init__(self, bat_x, bat_y, bat_image, bat_health): pygame.sprite.Sprite.__init__(self) self.bat_health = bat_health

Updating multiple items in a class, not just one

北城余情 提交于 2020-04-16 08:34:09
问题 In the update section of this code, only the first bat that gets made is affected by update() in class Bat()... Outside of main loop: START_BAT_COUNT = 30 BAT_IMAGE_PATH = os.path.join( 'Sprites', 'Bat_enemy', 'Bat-1.png' ) bat_image = pygame.image.load(BAT_IMAGE_PATH).convert_alpha() bat_image = pygame.transform.scale(bat_image, (80, 70)) class Bat(pygame.sprite.Sprite): def __init__(self, bat_x, bat_y, bat_image, bat_health): pygame.sprite.Sprite.__init__(self) self.bat_health = bat_health

Pygame window not responding, but program continues to run

对着背影说爱祢 提交于 2020-04-16 07:42:01
问题 I am an enthusiast fairly new to working with python. It has been a week since I installed Pygame, and after numerous attempts, I still can’t get the Pygame window to launch or open when I run any of my programs. I have watched as many tutorials as I can, as well as reading all the articles on similar issues I could find. I have copied all of the solutions I found on other websites and the problem still persists. Stranger nonetheless, is the fact that the IDE I am using (Pycharm) rarely

Shooting tank bullet in python/pygame

假装没事ソ 提交于 2020-04-14 09:01:47
问题 I'm working on python project right now using pygame library and I need help with this project I make. I want my tank to shoot bullets and so those bullets ricochet from the walls. What is the best way possible to do this? I'm sorry that my code looks so messy, I've been watching different youtube tutorials and they all do differently. Here is my code import pygame pygame.init() # ======================= Variables ======================= # ------------------------ Screen ---------------------

How to correctly add a light to make object get a better view with pygame and pyopengl

不打扰是莪最后的温柔 提交于 2020-04-14 07:38:12
问题 I am following the tutorial available in https://pythonprogramming.net/opengl-pyopengl-python-pygame-tutorial/ where he teachs how to render a cube with pyOpenGL an pygame. When rendering the cube, the tutorial set color to all the vertices of the cubes and then dispays it. However, im my project, i load object from a .obj file using the code provided in https://www.pygame.org/wiki/OBJFileLoader and most of my objects is fully white. Conclusion: when i render it on screen, i only see full

How to correctly add a light to make object get a better view with pygame and pyopengl

与世无争的帅哥 提交于 2020-04-14 07:38:11
问题 I am following the tutorial available in https://pythonprogramming.net/opengl-pyopengl-python-pygame-tutorial/ where he teachs how to render a cube with pyOpenGL an pygame. When rendering the cube, the tutorial set color to all the vertices of the cubes and then dispays it. However, im my project, i load object from a .obj file using the code provided in https://www.pygame.org/wiki/OBJFileLoader and most of my objects is fully white. Conclusion: when i render it on screen, i only see full

Pickling unpicklable objects

≡放荡痞女 提交于 2020-04-13 05:32:48
问题 I am making a drawing program with pygame in which I want to give the user an option of saving the exact state of the program and then reloading it at a later time. At this point I save a copy of my globals dict and then iterate through, pickling every object. There are some objects in pygame that cannot be pickled, but can be converted into strings and pickled that way. My code is set up to do this, but some of these unpicklable objects are being reached by reference. In other words, they

Python开源游戏,《植物大战僵尸》

时间秒杀一切 提交于 2020-04-12 20:09:49
python开发植物大战僵尸游戏 https://github.com/371854496/pygame https://segmentfault.com/a/1190000019418065 https://github.com/marblexu/PythonPlantsVsZombies https://www.pygame.org/ 点赞 收藏 分享 文章举报 libaineu2004 发布了509 篇原创文章 · 获赞 620 · 访问量 347万+ 他的留言板 关注 来源: oschina 链接: https://my.oschina.net/u/4409653/blog/3231229