epic射击角色_动作游戏核心代码 pygame Shooting Character-Action Game Core Code

pygame游戏关卡制作器演示

"""epic射击角色, 动作射击游戏基础核心源代码哦. 按鼠标射击,按a,d左右行走,按w拿枪攻击,按s倒地."""

__author__= "李兴球"
__date__ = "2019/6/8"
__blog__ = "www.lixingqiu.com"

import time
import pygame
from pygame.locals import *

class Actor:
    
    def __init__(self,right_frames,left_frames,screen):
        self.screen = screen
        self.sw = screen.get_width()
        self.sh = screen.get_height()
        self.right_frames = right_frames
        self.left_frames = left_frames
        self.frames = [right_frames,left_frames]
        self.heading = 0        # 为0表示朝向为右,使用初始是面向右系列造型
        self.index = 0          # 初始状态系列造型中的索引为0的造型
        self.image = self.frames[self.heading][self.index] # 初始造型
        self.rect = self.image.get_rect()
        self.rect.center = self.sw//2,self.sh//2+100 # 初始位置
        self.status = "stand"    # 初始状态为站立
        self.interval = 0.05     # 帧切换间隔时间
        self.start_time = time.time()
        self.speed = (0,0)
        
    def update(self):
        if time.time() - self.start_time > self.interval: # 超时则换造型
            
            if self.status == "run":
                if self.index < 55 :
                    self.index += 1
                    
                else:                    
                    self.index = 48

            if self.status == "shoot":
                if self.index < 6:
                    self.index += 1
                else:
                    self.status = "stand"
                    self.index = 0
                    
            if self.status == "up_attack":
                if self.index < 47:
                    self.index += 1
                else:
                    self.status = "stand"
                    self.index = 0
                    
            if self.status == "hurt":
                if self.index < 33:
                    self.index += 1
                else:
                    self.status = "stand"
                    self.index = 0
                  

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