下面是部分代码预览:
"""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] def update(self): if time.time() - self.start_time > self.interval: # 超时则换造型 def main(): width,height = 480,360 screen = pygame.display.set_mode((width,height)) pygame.display.set_caption("epic射击角色_动作游戏核心代码 www.lixingqiu.com") fighter = Actor(costumes_right,costumes_left,screen) clock = pygame.time.Clock() running = True while running: for event in pygame.event.get(): if event.type == QUIT:running = False if event.type == KEYDOWN: if event.key == K_a: fighter.heading = 1 # 向左 fighter.status = "run" fighter.index = 48 fighter.speed = (-5,0) if event.key == K_d: fighter.heading = 0 # 向右 fighter.status = "run" fighter.index = 48 fighter.speed = (5,0) if event.key == K_w: fighter.status = "up_attack" fighter.index = 32 fighter.start_time = time.time() if event.key == K_s: fighter.status = "hurt" fighter.index = 16 fighter.start_time = time.time() if event.type == KEYUP: if event.key == K_a or event.key == K_d: fighter.status = 'stand' fighter.index = 0 fighter.speed = (0,0) if event.type == MOUSEBUTTONDOWN: fighter.status = "shoot" fighter.index = 0 fighter.start_time = time.time() fighter.update() screen.blit(background,(0,0)) screen.blit(fighter.image,fighter.rect) pygame.display.update() clock.tick(60) pygame.quit() if __name__ == "__main__": main()
下载完整源代码与素材,请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)