arcade 物理系统_如何使用Python和Arcade库创建2D游戏

arcade 物理系统

对于那些学习编程的人来说, Python是一种出色的语言,它对于想要“完成工作”并且不花很多时间在样板代码上的人来说是完美的语言。 Arcade是一个用于创建2D视频游戏的Python库,该库易于开始使用,并且在您获得经验时非常有能力。 在本文中,我将解释如何开始使用Python和Arcade对视频游戏进行编程。

在使用PyGame库教了学生之后,我开始在Arcade上进行开发。 我使用PyGame进行了近十年的现场教学,并开发了ProgramArcadeGames.com进行在线教学。 PyGame很棒,但是最终我觉得我在浪费时间去掩盖那些从未修复过的错误

我担心教诸如事件循环之类的事情 ,而这不再是我们编写代码的方式。 我在整个章节中解释了为什么将y坐标反转。 因为PyGame很少更新,并且它基于旧的SDL 1库,而不是像OpenGL这样的更现代的库,所以我对未来并不抱太大希望。

安装

像许多其他软件包一样,可以通过PyPi使用Arcade,这意味着您可以使用pip命令(或pipenv命令)安装Arcade。 如果您已经安装了Python,则可能只需在Windows上打开命令提示符并键入:



   
   
   
pip install arcade

或在MacOS和Linux上输入:



   
   
   
pip3 install arcade

有关更详细的安装说明,您可以参考Arcade安装文档

简单绘图

您可以打开一个窗口并仅需几行代码即可创建简单的图形。 让我们创建一个绘制笑脸的示例,如下图所示:

微笑的脸图像

下面的脚本显示了如何使用Arcade的绘图命令来执行此操作。 注意,您不需要知道如何使用 ,甚至不需要定义函数 。 带有快速视觉反馈的编程非常适合想要开始学习编程的任何人。



   
   
   
import arcade

# Set constants for the screen size
SCREEN_WIDTH = 600
SCREEN_HEIGHT = 600

# Open the window. Set the window title and dimensions (width and height)
arcade. open_window ( SCREEN_WIDTH , SCREEN_HEIGHT , "Drawing Example" )

# Set the background color to white.
# For a list of named colors see:
# http://arcade.academy/arcade.color.html
# Colors can also be specified in (red, green, blue) format and
# (red, green, blue, alpha) format.
arcade. set_background_color ( arcade. color . WHITE )

# Start the render process. This must be done before any drawing commands.
arcade. start_render ( )

# Draw the face
x = 300
y = 300
radius = 200
arcade. draw_circle_filled ( x , y , radius , arcade. color . YELLOW )

# Draw the right eye
x = 370
y = 350
radius = 20
arcade. draw_circle_filled ( x , y , radius , arcade. color . BLACK )

# Draw the left eye
x = 230
y = 350
radius = 20
arcade. draw_circle_filled ( x , y , radius , arcade. color . BLACK )

# Draw the smile
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Learn and use Python and PyGame to design and build cool arcade games. In Program Arcade Games: With Python and PyGame, Second Edition, Dr. Paul Vincent Craven teaches you how to create fun and simple quiz games; integrate and start using graphics; animate graphics; integrate and use game controllers; add sound and bit-mapped graphics; and build grid-based games. After reading and using this book, you'll be able to learn to program and build simple arcade game applications using one of today's most popular programming languages, Python. You can even deploy onto Steam and other Linux-based game systems as well as Android, one of today's most popular mobile and tablet platforms. You'll learn: How to create quiz games How to integrate and start using graphics How to animate graphics How to integrate and use game controllers How to add sound and bit-mapped graphics How to build grid-based games Audience This book assumes no prior programming knowledge. Table of Contents Chapter 1: Before Getting Started… Chapter 2: Create a Custom Calculator Chapter 3: What Is a Computer Language? Chapter 4: Quiz Games and If Statements Chapter 5: Guessing Games with Random Numbers and Loops Chapter 6: Introduction to Graphics Chapter 7: Back to Looping Chapter 8: Introduction to Lists Chapter 9: Introduction to Animation Chapter 10: Functions Chapter 11: Controllers and Graphics Chapter 12: Bitmapped Graphics and Sound Chapter 13: Introduction to Classes Chapter 14: Introduction to Sprites Chapter 15: Libraries and Modules Chapter 16: Searching Chapter 17: Array-Backed Grids Chapter 18: Sorting Chapter 19: Exceptions Chapter 20: Recursion Chapter 21: Formatting Chapter 22: Exercises
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值