python海龟画图制作的合金弹头主角

这是用Python的海龟画图turtle模块制作的一个角色,人物和背景取自合金弹头,角色可以跳,可以左右行走.

python海龟画图制作的合金弹头主角

python海龟画图制作的合金弹头主角

"""
   合金弹头Macro角色
"""
from turtle import *

def main():
    """主要函数"""
    width,height = 480,360
    screen = Screen()
    screen.title("海龟画图制作的合金弹头主角by lixingqiu")
    screen.bgpic("bg/07.png")
    screen.setup(width,height)
    screen.tracer(0)
    macros = ["Marco_r1.gif","Marco_runH1.gif","Marco_runH2.gif",
        "Marco_runH3.gif","Marco_runH4.gif","Marco_runH5.gif",
        "Marco_runH6.gif","Marco_runH9.gif","Marco_runH10.gif",
        "Marco_runH11.gif","Marco_runH12.gif","Marco_runH13.gif",
        "Marco_runH14.gif","Marco_runH15.gif","Marco_runH16.gif",
        "Marco_shoot_pist.gif","Marco_shoot_pist1.gif","Marco_shoot_pist2.gif",
        "Marco_shoot_pist3.gif","Marco_shoot_pist4.gif","Marco_shoot_pist5.gif",
        "Marco_shoot_pist6.gif","Marco_shoot_pist7.gif","Marco_shoot_pist8.gif"]
    mr = ["mr/" + im for im in macros]
    ml = ["ml/" + im for im in macros]
    [screen.addshape(im) for im in mr]
    [screen.addshape(im) for im in ml]
    
    macro = Sprite(mr,ml)
    screen.update() 

class Sprite(Turtle):
    """继承自Turtle类的角色"""
    def __init__(self,mr,ml):
        """
           mr:右造型序列表
           ml:左造型序列表
        """
        Turtle.__init__(self)
        self.penup()
        self.mr = mr         # 右造型序列
        self.ml = ml         # 左造型序列
        self.images = [mr,ml]# 造型列表
        self.shapes_index = 0# 默认为向右造型序列
        self.costume_index = 0
        self.set_costume()    # 设置造型
        self.screen = self.getscreen()
        self.screen.onkeypress(self.move_right,"Right")
        self.screen.onkeypress(self.move_left,"Left")
        self.screen.onkeypress(self.jump,"Up")
        self.screen.listen()
        self.dy = 0
        self.gravity()
    

You must log in to read the rest of this article. Please log in or register as a user.