猫史档案馆


【Python作品分享】The World(半成品)

用户:WahahaWahaha查看:0 回复:1 评论:0 创建时间:2024-01-06T11:35:56


【作品展示】

center_image

 

【作品介绍】

一个冒险游戏

发出来求帮助

大佬给点建议

 

【作品源代码】

# 导入库
import time
from pgzrun import *


class GamePlayer:
    def __init__(self, picture, pos, hp, speed=5):
        self.actor = Actor(picture, pos)
        self.hp = hp
        self.speed = speed
        self.x = self.actor.x
        self.y = self.actor.y

    def walk_A(self):
        self.actor.x -= self.speed

    def walk_D(self):
        self.actor.x += self.speed

    def jump(self):
        if self.actor.colliderect(world):
            for i in range(1,9):
                self.actor.y -= 10


class GameActor:
    def __init__(self, picture, pos, hp):
        self.actor = Actor(picture, pos)
        self.hp = hp


# 设置窗口大小及标题
TITLE = 'The world'
WIDTH = 1400
HEIGHT = 900
# 一些位置的变量
center = [WIDTH/2, HEIGHT/2]
midbottom = [WIDTH/2, HEIGHT]
midtop = [WIDTH/2, 0]
# 角色创建
player = GamePlayer('player1', center, 10)
world = Actor('world', [center[0], center[1]+55])
#标志
player_die = player.hp < 0




def draw():
    screen.clear()
    screen.fill((0, 204, 255))
    player.actor.draw()
    world.draw()


def update():
    #按键事件
    if keyboard.A:
        player.walk_A()
    elif keyboard.D:
        player.walk_D()
    elif keyboard.SPACE:
        player.jump()
    #世界事件
    if not player.actor.colliderect(world):
        player.actor.y += 3
    elif player.y - HEIGHT == 100:
        player.hp =0
    elif player_die:



#开始游戏
go()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
WahahaWahaha

(⊙o⊙)…发现有点bug

点赞0


评论