arcade制作的模拟海底世界动画章鱼哥

arcade制作的模拟海底世界动画章鱼哥

Octopus demo python街机模块arcade制作的模拟海底动画章鱼哥

Octopus demo python街机模块arcade制作的模拟海底动画章鱼哥

以下是部分代码预览:

"""
Octopus demo in sea  by lixingqiu
python街机模块arcade制作的模拟海底动画章鱼哥

"""

__author__ = "lixingqiu"
__date__ = "2014/4/3"
__url__ = "https://www.lixingqiu.com/?p=313"
__qq__ = "406273900"

import os
import arcade
import random

SCREEN_WIDTH = 500
SCREEN_HEIGHT = 685
SCREEN_TITLE = "Octopus demo python街机模块arcade制作的模拟海底动画章鱼哥 "

COIN_SCALE = 1.0
COIN_COUNT = 50

MOVEMENT_SPEED = 5

class Actor(arcade.AnimatedTimeSprite):
    def __init__(self,images,scale):
        super().__init__()
        while images:self.textures.append(arcade.load_texture(images.pop(0),scale= scale))

class Octopus(arcade.Sprite):
    def __init__(self,images):
        super().__init__()
        self.costume_amount = len(images)

        
    def alt_costume(self):
        self.frame_counter += 1
       
            
        
class MyGame(arcade.Window): 

    def __init__(self, width, height, title):
        """ 初始化方法      """
        super().__init__(width, height, title)

        self.background = None
        self.octopus = None
        # 定义所有角色列表                    
        self.all_actor_list = None 
 
    def setup(self):
        self.all_actor_list = arcade.SpriteList() 

        bgimages = ["images/bg2" + os.sep  + f"{index:04d}"  + ".png" for index in range(1,16)]
        self.background = Actor(bgimages,1.0)
        self.background.center_x = SCREEN_WIDTH//2
        self.background.center_y = SCREEN_HEIGHT//2
        self.all_actor_list.append(self.background)

        octopus_images = ["images/octopus/" +  str(i) + ".png" for i in range(1,82)]
        self.octopus = Octopus(octopus_images)
        
        self.octopus.center_x = SCREEN_WIDTH//2
        self.octopus.center_y = SCREEN_HEIGHT//2
        self.octopus.alpha =  80
        self.all_actor_list.append(self.octopus)

    def on_draw(self):
        """   渲染屏幕       """
   
        arcade.start_render() 
        self.all_actor_list.draw()   

    def update(self, delta_time):
        """ 更新角色"""

        self.all_actor_list.update()
        self.all_actor_list.update_animation()
        self.octopus.alt_costume()
 

def main():
    """ 主要方法 """
    window = MyGame(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
    window.setup()
    arcade.run()


if __name__ == "__main__":
    main()

下载完整源代码与素材,请扫码付款。

李兴球

李兴球的博客是Python创意编程原创博客

评论已关闭。