编者按
哈喽!哈喽!我是程式设计小师妹,本周一格斗游戏预览——Skylanders绚丽上架啦!
Skylanders有啥人还提过这款经典之作格斗游戏?对90、00后如果并不大熟识,但或多或少第一印象中见过
这个反领的胡子穿著TNUMBERA51的路易吉!
这款格斗游戏1985年发售,因上手简单、情节有趣等因素迅速走红!
陪伴70后、80后走过了青涩难忘的童年Skylanders成了大家心目中的经典之作!如果你的童年也曾被魔性的 灯~灯灯~灯~灯灯~灯洗脑那就接着来怀旧一番吧~今天小师妹就带着大家自造一款Skylanders格斗游戏,还原度超高哦~还在等什么动动手就能拥有属于自己的Skylanders格斗游戏呢,赶快学起来吧~
正文
嗯呐~写格斗游戏Python还是用的Pygame模块啦
1)准备中
1.1环境安装
Python3、Pycharm、Pygame模块很多自带的模块等。
模块安装统一用的豆瓣镜像源:
pip install -i https://pypi.douban.com/simple/ 模块名。
1.2图片素材 背景音乐 字体(可修改)
2)开始敲代码
2.1 运行程序:mario_level_1.py。
!/usr/bin/env python
__author__ = Skylanders-源码基地
“””
This is an attempt to recreate the first level of
Super Mario Bros for the NES.
“””
import sys
import pygame as pg
from data.main import main
import cProfile
if __name__==__main__:
main()
pg.quit()
sys.exit()
2.2 配置音乐文字等setup.py。
__author__ = Python源码基地
“””
This module initializes the display and creates dictionaries of resources.
“””
import os
import pygame as pg
from . import tools
from .import constants as c
ORIGINAL_CAPTION = c.ORIGINAL_CAPTION
os.environ[SDL_VIDEO_CENTERED] = 1
pg.init()
pg.event.set_allowed([pg.KEYDOWN, pg.KEYUP, pg.QUIT])
pg.display.set_caption(c.ORIGINAL_CAPTION)
SCREEN = pg.display.set_mode(c.SCREEN_SIZE)
SCREEN_RECT = SCREEN.get_rect()
FONTS = tools.load_all_fonts(os.path.join(“resources”,”fonts”))
MUSIC = tools.load_all_music(os.path.join(“resources”,”music”))
GFX = tools.load_all_gfx(os.path.join(“resources”,”graphics”))
SFX = tools.load_all_sfx(os.path.join(“resources”,”sound”))
2.3格斗游戏音乐设置game_sound.py。
__author__ = Python小师妹
import pygame as pg
from . import setup
from . import constants as c
class Sound(object):
“””Handles all sound for the game”””
def __init__(self, overhead_info):
“””Initialize the class”””
self.sfx_dict = setup.SFX
self.music_dict = setup.MUSIC
self.overhead_info = overhead_info
self.game_info = overhead_info.game_info
self.set_music_mixer()
def set_music_mixer(self):
“””Sets music for level”””
if self.overhead_info.state == c.LEVEL:
pg.mixer.music.load(self.music_dict[main_theme])
pg.mixer.music.play()
self.state = c.NORMAL
elif self.overhead_info.state == c.GAME_OVER:
pg.mixer.music.load(self.music_dict[game_over])
pg.mixer.music.play()
self.state = c.GAME_OVER
def update(self, game_info, mario):
“””Updates sound object with game info”””
self.game_info = game_info
self.mario = mario
self.handle_state()
def handle_state(self):
“””Handles the state of the soundn object”””
if self.state == c.NORMAL:
if self.mario.dead:
self.play_music(death, c.MARIO_DEAD)
elif self.mario.invincible \
and self.mario.losing_invincibility == False:
self.play_music(invincible, c.MARIO_INVINCIBLE)
elif self.mario.state == c.FLAGPOLE:
self.play_music(flagpole, c.FLAGPOLE)
elif self.overhead_info.time == 100:
self.play_music(out_of_time, c.TIME_WARNING)
elif self.state == c.FLAGPOLE:
if self.mario.state == c.WALKING_TO_CASTLE:
self.play_music(stage_clear, c.STAGE_CLEAR)
elif self.state == c.STAGE_CLEAR:
if self.mario.in_castle:
self.sfx_dict[count_down].play()
self.state = c.FAST_COUNT_DOWN
elif self.state == c.FAST_COUNT_DOWN:
if self.overhead_info.time == 0:
self.sfx_dict[count_down].stop()
self.state = c.WORLD_CLEAR
elif self.state == c. TIME_WARNING:
if pg.mixer.music.get_busy() == 0:
self.play_music(main_theme_sped_up, c.SPED_UP_NORMAL)
elif self.mario.dead:
self.play_music(death, c.MARIO_DEAD)
elif self.state == c.SPED_UP_NORMAL:
if self.mario.dead:
self.play_music(death, c.MARIO_DEAD)
elif self.mario.state == c.FLAGPOLE:
self.play_music(flagpole, c.FLAGPOLE)
elif self.state == c.MARIO_INVINCIBLE:
if (self.mario.current_time – self.mario.invincible_start_timer)
2.分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3.不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4.本站提供的源码、模板、插件等其他资源,都不包含技术服务请大家谅解!
5.如有链接无法下载或失效,请联系管理员处理!
6.本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!