当前位置:网站首页>Make a chase game with pyGame
Make a chase game with pyGame
2022-07-26 07:00:00 【Nostalgia_ Sun】
Hello, everyone , Today, let's play a chase game
1、 Use the mouse to operate
2、 Left click to change color ( Random )
3、 The wheel adjusts the size of the sphere ( Go up , Lower )
4、 Right click to clear the screen
import sys
import pygame as p
from random import *
p.init() #pygame initialization
The screen = p.display.set_mode( (800,800) ) # Set up the screen
p.display.set_caption(" Chase the game ")
Frame rate = p.time.Clock()
red , green , blue =255,100,100
radius =50
gx,gy=50,50
while True:
for event in p.event.get():
#print(event)
#p.MOUSEBUTTONDOWN Mouse button down
#p.MOUSEBUTTONUP Release the mouse button
#p.MOUSEMOTION Mouse movement
if event.type == p.QUIT: # If the type of event is exit
p.quit() # Then quit (pygame)
sys.exit() # Then quit ()
if event.type == p.MOUSEBUTTONDOWN:
if event.button == 3:
The screen .fill( (0,0,0) )
elif event.button == 4:
radius +=2
elif event.button == 5:
radius -=2
if radius <2:
radius = 2
elif event.button == 1:
red = randint(0,255)
green = randint(0,250)
blue = randint(0,250)
elif event.type == p.MOUSEMOTION:
print(event.pos)
x = event.pos
# else:
# The screen .fill( (0,0,0) )
if gx<x[0]:
gx+=1
else:
gx-=1
if gy<x[1]:
gy+=1
else:
gy-=1
p.draw.circle( The screen ,( red , green , blue ),( x[0], x[1]), radius ,0)
p.draw.circle( The screen ,(255,255,255),(gx,gy),10,0)
if x[0]- radius <= gx <= x[0]+ radius and x[1]- radius <= gy <= x[1]+ radius :
The screen .fill( (255,255,255) )
Frame rate .tick(120)
p.display.update() # The refresh screen
边栏推荐
- Leetcode question brushing 1: topic classification
- Development stage of source code encryption technology
- On stock price prediction model (3): are you falling into the trap of machine learning
- Use and analysis of show profile optimized by MySQL
- 火焰图分析Flink反压
- [QT] detailed explanation of *.pro, *.pri, *.prf, *.prl files
- QT监听socket事件,使用QSocketNotifier类
- Drools(2):Drools快速入门
- Experimental flags: --disable_ admission_ control=false --enable_ rm=false --llama_ callback_ port=28000
- IV Actual combat - global unified return result class
猜你喜欢
随机推荐
Agile and tidy way
优炫数据库JDBC打开日志方式有哪些
buuReserve(4)
Do you know what "parts" MySQL contains?
Rust语言- Slice(切片)类型(&[u8])
The creation of "harmonyos" project and the use of virtual machines
Is there any online account opening process of Huatai Securities? Is online account opening safe
【硬十宝典】——7.1【动态RAM】DDR硬件设计要点
MySQL isolation level transactions
Basic operations and common functions of MySQL table creation
在第一次使用德国小鸡要注意的地方
MySQL table read lock
Celery takes up large memory - memory leak
哈夫曼编码原理
20220725 自动控制原理中的卷积Convolution
【数据库】CTE(Common Table Expression(公共表表达式))
Function of hot air pad
Contents mismatch at: 08000000H (Flash=FFH Required=00H) ! Too many errors to display !
7. Reverse integer integer
[hardware ten treasures] - 7.1 [dynamic RAM] key points of DDR hardware design






![Rust语言- Slice(切片)类型(&[u8])](/img/d1/68c73c8b34b848212083c08df3137f.png)


