python - How to change sprite after certain amount of time? -


i'm making game , want change sprite punch image stand image after few frames can figure out. trying find solution last resort. in advance.

import pygame import os import time  pygame.init() # screen display_width = 1350 display_height = 700 screen = pygame.display.set_mode((display_width, display_height))  # colors white = (255, 255, 255) frame = 0  # constants clock = pygame.time.clock()  # images img = pygame.image.load("stand.png") stand_img = pygame.image.load('stand.png') crouch_img = pygame.image.load('crouch.png') jump_img = pygame.image.load('jump.png') punch_img = pygame.image.load('punch.png')  class fighter:     def __init__(self, x_pos, y_pos, image, health):         self.x_pos = x_pos         self.y_pos = y_pos         self.image = image         self.health = health      def draw(self):         screen.blit(self.image, (self.x_pos, self.y_pos))      def move(self, accel_x, accel_y):         self.x_pos += accel_x         self.y_pos += accel_y      def damage(self, damage_done):         self.health -= damage_done      def punch(self, direction):         c = 0         while c < 30:             c += 1             if direction == 'left':                 self.image = pygame.transform.flip(punch_img, true, false)                 self.x_pos -= 91             if direction == 'right':                 self.image = punch_img             pygame.display.update()  class mainrun:     def __init__(self, displayw, displayh):         self.dw = displayw         self.dh = displayh      def mainloop(self):         global frame         playing = true         time_up = 0         frame_cycle = 0          # player 1 info         p1_x = display_width - 400         p1_y = 400         p1_direction = 'left'         p1_accel_x = 0         p1_accel_y = 0         p1_health = 200         player_1 = fighter(p1_x, p1_y, img, p1_health)          while playing:             event in pygame.event.get():                 if event.type == pygame.quit:                     playing = false                  if event.type == pygame.keydown:                     # player 1 event handlers                     if event.key == pygame.k_left:                         p1_accel_x = -10                         p1_accel_y = 0                         p1_direction = 'left'                     elif event.key == pygame.k_right:                         p1_accel_x = 10                         p1_accel_y = 0                         p1_direction = 'right'                     elif event.key == pygame.k_up:                         player_1.y_pos = 300                         player_1.image = jump_img                     elif event.key == pygame.k_down:                         player_1.y_pos = 500                         player_1.image = crouch_img                     elif event.key == pygame.k_period:                         player_1.punch(p1_direction)                  if event.type == pygame.keyup:                     # player 1 event handlers                     if event.key == pygame.k_left:                         p1_accel_x = 0                         p1_accel_y = 0                     if event.key == pygame.k_right:                         p1_accel_x = 0                         p1_accel_y = 0                     if event.key == pygame.k_up:                         player_1.y_pos = p1_y                         player_1.image = stand_img                     if event.key == pygame.k_down:                         player_1.y_pos = p1_y                         player_1.image = stand_img                     if event.key == pygame.k_period:                         player_1.image = stand_img                         if p1_direction == 'left':                             player_1.x_pos += 91              screen.fill(white)             player_1.move(p1_accel_x, p1_accel_y)             player_1.draw()             pygame.display.update()             frame += 1             if frame == 29:                 frame = 0                 frame_cycle += 1              #print(frame_cycle, frame)             clock.tick(60)          pygame.quit()         quit()   run = mainrun(1000, 600) run.mainloop() 


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -