相关文件
关注小编,私信小编领取哟!
当然别忘了一件三连哟~~
对了大家可以关注小编的公众号哟~~
Python日志
开发环境
Python版本:3.6.4
相关模块:
pygame模块;
以及一些Python自带的模块。
环境搭建
安装Python并添加到环境变量,pip安装需要的相关模块即可。
原理介绍
这是一个双人小游戏,分为红蓝两方。当然每队都有三个球员和一个守门员,每个玩家可以控制一个球员,其他三个是电脑控制。红方球员是通过”W”,”A”,”S”,”D”控制球员的移动,”T”踢球。蓝方球员是通过”↑”,”↓”,”←”,”→”控制球员的移动,”K”踢球。安空格键是开始游戏,下面是整个球场的效果图。
大概了解了游戏规则之后,我们就可以开始写这个游戏啦~首先,进行一下游戏初始化操作:
def myinit():
screen = pygame.display.set_mode((769,563))
g1 = pygame.image.load("g1.jpg").convert()
g2 = pygame.image.load("hh.png").convert()
t = 0
timer = pygame.time.Clock()
while(1):
timer.tick(30)
ticks = pygame.time.get_ticks();
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
screen.blit(g1,(0,0))
t+= 1
print(t)
if t > 66:
break;
pygame.display.update()
while(1):
timer.tick(30)
ticks = pygame.time.get_ticks();
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == MOUSEBUTTONUP:
mouse_up = event.button
mouse_up_x,mouse_up_y = event.pos
if mouse_up_x > 245 and mouse_up_x < 469 and mouse_up_y> 368 and mouse_up_y < 470:
return
screen.blit(g2,(0,0))
pygame.display.update()
然后就是一部分的代码示意:
def bias(x, y):
x = x + 16
y = y + 24
x_cent = 0
y_cent = 0
if (x >= 100 and x 700):
x_cent = -1 * x + 100
elif (x > 700):
x_cent = -600
else:
x_cent = 0
if (y >= 75 and y 525):
y_cent = -1 * y + 75
elif (y > 525):
y_cent = -450
else:
y_cent = 0
return x_cent, y_cent
def draw_background(screen):
rc = (255, 255, 255)
rp = (600, 400)
rr = 80
width = 5
screen.fill((0,100,0))
pygame.draw.circle(screen, rc, rp, rr, width)
pygame.draw.rect(screen, (255, 255, 255), (10, 10, 600, 790), 5
Original: https://blog.csdn.net/Gtieguo/article/details/118019870
Author: 彳余大胆
Title: Python制作的足球双人小游戏,你确定你不过来看看?
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/781874/
转载文章受原作者版权保护。转载请注明原作者出处!