猫史档案馆


【Python作品分享】原野跑酷(PYTHON版)

用户:_昵称副本__昵称副本_查看:1 回复:2 评论:1 创建时间:2024-03-10T15:48:54


【作品展示】

center_image

【作品源代码】

def Read_cloud_data(name):#读取云变量
    return(requests.post('http://tinywebdb.appinventor.space/api',data = {'user':'c2345','secret':'a3ea43b6','action':'get','tag':name}).text[8:len(requests.post('http://tinywebdb.appinventor.space/api',data = {'user':'c2345','secret':'a3ea43b6','action':'get','tag':name}).text) - 2])
def Write_to_cloud_data(name,data):#修改云变量
    update = requests.post('http://tinywebdb.appinventor.space/api',data = {'user':'c2345','secret':'a3ea43b6','action':'update','tag':name,'value':data})
def Clear_cloud ():#清空云变量
    Write_to_cloud_data("p1","0")
    Write_to_cloud_data("p2","0")
    Write_to_cloud_data("p3","0")
    Write_to_cloud_data("p4","0")
    Write_to_cloud_data("p5","0")
    Write_to_cloud_data("p6","0")
    Write_to_cloud_data("p7","0")
    Write_to_cloud_data("p8","0")
    Write_to_cloud_data("UC","0")
def fall(x,decrease):
    global yy
    yy += int(x)
    if collide(rect1, mask1, rect2, mask2, rect3, mask3, 3) and (x != 0):
            yy -= (0 - x) / abs(x)  
    else:
        if x > -1 and collide(rect1, mask1, rect2, mask2, rect3, mask3, 3)!=1: 
            fall(int(x) - int(decrease),(int(decrease)+5))
def collide(rect1, mask1, rect2, mask2, rect3, mask3, num):
    if keyboard.is_pressed('s'):
        collide_rect = rect1
        collide_mask = mask1
    else:
        collide_rect = rect2
        collide_mask = mask2
    if num == 3:
        other_rect = rect3
        other_mask = mask3
    offset_x = collide_rect.centerx - other_rect.centerx
    offset_y = collide_rect.centery - other_rect.centery
    collision = collide_mask.overlap(other_mask, (offset_x, offset_y))
    if collision:
        return 1
    else:
        return 0

def choose_player_num():
    if Read_cloud_data(P1)==0:
        return 1
    elif Read_cloud_data(P2)==0:
        return 2
    elif Read_cloud_data(P3)==0:
        return 3
    elif Read_cloud_data(P4)==0:
        return 4
    elif Read_cloud_data(P5)==0:
        return 5
    elif Read_cloud_data(P6)==0:
        return 6
    elif Read_cloud_data(P7)==0:
        return 7
    elif Read_cloud_data(P8)==0:
        return 8
    else:
        return 0
import pygame #导入pygame
import math #数学
import time#时间
import pyautogui as pag#鼠标
import requests#云变量
import keyboard#键盘


        

pygame.init()#pygame初始化
background = pygame.image.load(r"E:\我的\python\原野跑酷\image\backgroud.png")#背景图片设置
font=pygame.font.Font(r"E:\我的\python\原野跑酷\font\站酷快乐体.woff",size=100)#字体设置
bgm=pygame.mixer.Sound(r"E:\我的\python\原野跑酷\media\bgm.mpeg")#游戏BGM
title=pygame.image.load(r"E:\我的\python\原野跑酷\image\title.png")#游戏标题
start=pygame.image.load(r"E:\我的\python\原野跑酷\image\start.png")#开始按钮轮廓
board_and_user=pygame.image.load(r"E:\我的\python\原野跑酷\image\board&user.png")
online=pygame.image.load(r"E:\我的\python\原野跑酷\image\Join online.png")#联机按钮轮廓
player_stand=pygame.image.load(r"E:\我的\python\原野跑酷\image\player stand.png")#玩家站立形态
player_get_down=pygame.image.load(r"E:\我的\python\原野跑酷\image\player Get down.png")#玩家下蹲形态
board=pygame.image.load(r"E:\我的\python\原野跑酷\image\board.png")
grass=pygame.image.load(r"E:\我的\python\原野跑酷\image\grass.png")
mask1 = pygame.mask.from_surface(player_stand)
mask2 = pygame.mask.from_surface(player_get_down)
mask3 = pygame.mask.from_surface(board)
screen=pygame.display.set_mode([1280,720],)#设置窗口大小
pygame.display.set_caption("原野跑酷")#窗口名称设置
bgm.play(-1)#"-1"代表无限循环音乐“BGM”
# 设置开始按钮
x, y = 540, 465
width, height = 144, 喵
button_rect = pygame.Rect(x, y, width, height)
button_color = (170, 229, 113)
text_color = (70,213,120)
button_font = pygame.font.Font(r"E:\我的\python\原野跑酷\font\站酷快乐体.woff",size=60)
button_text = button_font.render("开始", True, text_color)
# 设置联机按钮
x, y = 470, 340
width, height = 280, 70
button2_rect = pygame.Rect(x, y, width, height)
button2_color = (70, 213, 120)
text2_color = (255,0,0)
button2_font = pygame.font.Font(r"E:\我的\python\原野跑酷\font\站酷快乐体.woff",size=60)
button2_text = button_font.render("加喵机", True, text2_color)
#窗口图标更改
icon = pygame.image.load(r"E:\我的\python\原野跑酷\logo\logo.png")
pygame.display.set_icon(icon)



num=0
screen_num=1
increase=0
big_screen=0
xx=0
yy=0
x1=608
x2=610
x3=407
y1=302
y2=330
y3=538
running = True


while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    num += 3
    increase += math.cos(math.radians(num))
    mouse_x,mouse_y = pag.position()
    if keyboard.is_pressed('Enter'):
            big_screen = 1 - big_screen

        
    if screen_num ==1 or screen_num ==2:
        screen.fi喵))#浅蓝天空背景绘制
        screen.blit(background,(5,-150 + ( float(increase)*0.4 )))#原野背景绘制
        screen.blit(title,(650,50 + ( float(increase)*1 )))#标题绘制

    if screen_num ==1:
        screen.blit(start,(500,450))#开始按钮轮廓绘制
        #开始按钮绘制
        pygame.draw.rect(screen, button_color, button_rect)
        screen.blit(button_text, (button_rect.centerx - button_text.get_width() / 2, button_rect.centery - button_text.get_height() / 2))
        #侦测按钮是否被鼠标点击
        if event.type == pygame.MOUSEBUTTONDOWN:
            if button_rect.collidepoint(event.pos):
                screen_num = 2

    if screen_num ==2:
        screen.blit(board_and_user,(0,25))
        screen.blit(online,(450,250))#联机按钮轮廓绘制
        #联机按钮绘制
        pygame.draw.rect(screen, button2_color, button2_rect)
        screen.blit(button2_text, (button2_rect.centerx - button2_text.get_width() / 2, button2_rect.centery - button2_text.get_height() / 2))
        #侦测按钮是否被鼠标点击
        if event.type == pygame.MOUSEBUTTONDOWN:
            if button2_rect.collidepoint(event.pos):
                screen_num = 3

    if screen_num ==3:
        screen.fill((117,199,235))#游戏背景绘制
        if keyboard.is_pressed('s'):
            x2 = 610 + int(xx)
            y2 = 330 - int(yy)
            x3 = 407-int(x2)+610
            y3 = 538-int(y2)+330
            screen.blit(player_get_down, (610, 330))  # 玩家绘制(下蹲)
        else:
            x1 = 608 + int(xx)
            y1 = 302 - int(yy)
            x3 = 407-int(x1)+608
            y3 = 538-int(y1)+302
            screen.blit(player_stand, (608, 302))  # 玩家绘制(站立)
        
        board_rect = pygame.Rect(x3, y3, 476, 88)
        screen.blit(board,(x3,y3))
        screen.blit(grass,(x3,y3-50))
        mask3 = pygame.mask.from_surface(board)
        rect1 = player_stand.get_rect(center=(x1, y1)) 
        rect2 = player_get_down.get_rect(center=(x2, y2))
        rect3 = board.get_rect(center=(x3+400, y3+40))
        decrease=1
        if keyboard.is_pressed('w') and collide(rect1, mask1, rect2, mask2, rect3, mask3, 3):
            count = 0
            for __count in range(120):
                count += 0.05
                yy += int(count)
                screen.fill((117,199,235))#游戏背景绘制
                if keyboard.is_pressed('s'):
                    x2 = 610 + int(xx)
                    y2 = 330 - int(yy)
                    x3 = 407-int(x2)+610
                    y3 = 538-int(y2)+330
                    screen.blit(player_get_down, (610, 330))  # 玩家绘制(下蹲)
                else:
                    x1 = 608 + int(xx)
                    y1 = 302 - int(yy)
                    x3 = 407-int(x1)+608
                    y3 = 538-int(y1)+302
                    screen.blit(player_stand, (608, 302))  # 玩家绘制(站立)
        
                board_rect = pygame.Rect(x3, y3, 476, 88)
                screen.blit(board,(x3,y3))
                screen.blit(grass,(x3,y3-50))
                mask3 = pygame.mask.from_surface(board)
                rect1 = player_stand.get_rect(center=(x1, y1)) 
                rect2 = player_get_down.get_rect(center=(x2, y2))
                rect3 = board.get_rect(center=(x3+400, y3+40))
                if yy < -500:
                    yy=0
                    xx=0
                if keyboard.is_pressed('a'):
                    xx -= 3
                if keyboard.is_pressed('d'):
                    xx += 3
                pygame.display.flip()
        else:
            fall(0,decrease)
        if yy < -1000:
            yy=0
            xx=0
        if keyboard.is_pressed('a'):
            xx -= 3
        if keyboard.is_pressed('d'):
            xx += 3

        
        
            
            
            


    pygame.display.flip()
pygame.quit()#关闭窗口❎


回复

上一页1 页 / 共 1下一页
_昵称副本__昵称副本_

           

点赞0


评论


就在天边等待你就在天边等待你

作者什么时候把图片发一下?

点赞0


评论