奉贤区专业建网站,昆明seo网站排名优化,如何建设一个工业品采购网站,网站基本常识前言
嗨喽~大家好呀#xff0c;这里是魔王呐 ❤ ~! 走迷宫#xff0c;是一项充满智慧的挑战~
作为经常刷短视频的我们#xff0c;见识过不少迷宫小游戏
当然印象深刻的当然是小动物走迷宫 这里有几组挑战走迷宫的小可爱。先来看看吧#xff01;
#xff08;1#xff…前言
嗨喽~大家好呀这里是魔王呐 ❤ ~! 走迷宫是一项充满智慧的挑战~
作为经常刷短视频的我们见识过不少迷宫小游戏
当然印象深刻的当然是小动物走迷宫 这里有几组挑战走迷宫的小可爱。先来看看吧
1毛茸茸的小仓鼠大家还记得这视频嘛过关斩将走完了6层迷宫。 让小动物走迷宫显然不是仓鼠党的专利。
仓鼠热门事件之后更多的小动物大军参与了进来萌宠猫咪。 人类对“迷宫”的热爱是有很长的历史的奇门遁甲八卦里面也经常有迷宫的效果。
今天小编的话就带着大伙儿一起制作一款走迷宫小游戏
代码展示
首先定义一个可以移动的素材这里大家可修改成自己喜欢的小人物 ‘’‘配置文件’‘’
SCREENSIZE (800, 625)
BGMPATH resources/audios/bgm.mp3
HEROPICPATH resources/images/hero.png
FPS 20
BLOCKSIZE 15
MAZESIZE (35, 50) # num_rows * num_cols
BORDERSIZE (25, 50) # 25 * 2 50 * 15 800, 50 * 2 35 * 15 625‘’‘主要运行程序’‘’
导入模块
import cfg
import pygame
from modules.misc import *
from modules.mazes import *
from modules.Sprites import *主函数
def main(cfg):# 初始化pygame.init()pygame.mixer.init()pygame.font.init()pygame.mixer.music.load(cfg.BGMPATH)pygame.mixer.music.play(-1, 0.0)screen pygame.display.set_mode(cfg.SCREENSIZE)pygame.display.set_caption(Maze - 完整源码Vqian97378免费获取)font pygame.font.SysFont(Consolas, 15)开始界面 Interface(screen, cfg, game_start)记录关卡数 num_levels 0记录最少用了多少步通关 best_scores None关卡循环切换 while True:num_levels 1clock pygame.time.Clock()screen pygame.display.set_mode(cfg.SCREENSIZE)–随机生成关卡地图 maze_now RandomMaze(cfg.MAZESIZE, cfg.BLOCKSIZE, cfg.BORDERSIZE)–生成hero hero_now Hero(cfg.HEROPICPATH, [0, 0], cfg.BLOCKSIZE, cfg.BORDERSIZE)–统计步数 num_steps 0–关卡内主循环 while True:dt clock.tick(cfg.FPS)screen.fill((255, 255, 255))is_move False----↑↓←→控制hero for event in pygame.event.get():if event.type pygame.QUIT:pygame.quit()sys.exit(-1)elif event.type pygame.KEYDOWN:if event.key pygame.K_UP:is_move hero_now.move(up, maze_now)elif event.key pygame.K_DOWN:is_move hero_now.move(down, maze_now)elif event.key pygame.K_LEFT:is_move hero_now.move(left, maze_now)elif event.key pygame.K_RIGHT:is_move hero_now.move(right, maze_now)num_steps int(is_move)hero_now.draw(screen)maze_now.draw(screen)----显示一些信息 showText(screen, font, LEVELDONE: %d % num_levels, (255, 0, 0), (10, 10))showText(screen, font, BESTSCORE: %s % best_scores, (255, 0, 0), (210, 10))showText(screen, font, USEDSTEPS: %s % num_steps, (255, 0, 0), (410, 10))showText(screen, font, S: your starting point D: your destination, (255, 0, 0), (10, 600))----判断游戏是否胜利 if (hero_now.coordinate[0] cfg.MAZESIZE[1] - 1) and (hero_now.coordinate[1] cfg.MAZESIZE[0] - 1):breakpygame.display.update()更新最优成绩 if best_scores None:best_scores num_stepselse:if best_scores num_steps:best_scores num_steps关卡切换 Interface(screen, cfg, modegame_switch)‘’‘run’‘’
if __name__ __main__:main(cfg)好啦这迷宫有点儿庞大哈走不走的出来就看你自己了
尾语
感谢你观看我的文章呐~本次航班到这里就结束啦
生一场也犹如走迷宫靠努力也靠运气。努力多一点成功近一点儿
希望本篇文章有对你带来帮助 有学习到一点知识~
躲起来的星星也在努力发光你也要努力加油让我们一起努力叭。 最后宣传一下呀~更多源码、资料、素材、解答、交流皆点击下方名片获取呀