python arcade库是干什么的-Python街机模块arcade的鼠标移动与单击示例

"""

鼠标移动与单击示例

"""

import arcade

SCREEN_WIDTH = 640

SCREEN_HEIGHT = 480

SCREEN_TITLE = "Python街机模块arcade的鼠标移动与单击示例,译:李兴球"

class Ball:

def __init__(self, position_x, position_y, radius, color):

# 球的中央坐标点和半径与颜色

self.position_x = position_x

self.position_y = position_y

self.radius = radius

self.color = color

def draw(self):

"""画球. """

arcade.draw_circle_filled(self.position_x, self.position_y, self.radius, self.color)

class MyGame(arcade.Window):

def __init__(self, width, height, title):

# 调用基类的初始化方法

super().__init__(width, height, title)

# 隐藏鼠标指针

self.set_mouse_visible(False)

arcade.set_background_color(arcade.color.ASH_GREY)

# 实例化一个球

self.ball = Ball(50, 50, 15, arcade.color.AUBURN)

def on_draw(self):

""" 开始渲染及画球 """

arcade.start_render()

self.ball.draw()

def on_mouse_motion(self, x, y, dx, dy):

"""每秒60次更新球的坐标"""

self.ball.position_x = x

self.ball.position_y = y

def on_mouse_press(self, x, y, button, modifiers):

"""

单击鼠标键时调用此函数

"""

print(f"你单击的鼠标为: {button}")

if button == arcade.MOUSE_BUTTON_LEFT:

self.ball.color = arcade.color.BLACK

def on_mouse_release(self, x, y, button, modifiers):

"""

松开鼠标键时调用此方法

"""

if button == arcade.MOUSE_BUTTON_LEFT:

self.ball.color = arcade.color.AUBURN

def main():

window = MyGame(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)

arcade.run()

if __name__ == "__main__":

main()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 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、付费专栏及课程。

余额充值