Currently when my code runs the update function for the Player class does nothing. I want to update the function to add 1 to the index. This should make the sprite move through an animation. I don't know what to write here.
import pygame
import sys, os
import random
from colors import *
CLOCK = pygame.time.Clock()
FPS = 1
SIZE = WIDTH, HEIGHT = 576, 480
TILESIZE = 32
CAPTION = pygame.display.set_caption('BRRRRRRRRR')
class Player(pygame.sprite.Sprite):
def __init__(self, game):
self.groups = game.sprites
pygame.sprite.Sprite.__init__(self, self.groups)
self.images = []
self.images.append(pygame.image.load("sprites/0.png"))
self.images.append(pygame.image.load("sprites/1.png"))
self.images.append(pygame.image.load("sprites/2.png"))
self.images.append(pygame.image.load("sprites/3.png"))
self.i = 0
self.image = self.images[self.i]
self.rect = pygame.Rect(5,5,32,32)
def update(self):
self.i += 1
print(self.i)
self.image = self.images[self.i]
class Control(object):
"""NOthing to see here folks"""
def __init__(self):
pygame.init()
self.screen = pygame.display.set_mode(SIZE)
self.img_dir = os.path.dirname(__file__), 'img'
#self.load_data()
self.new()
def new(self):
self.sprites = pygame.sprite.Group()
p = Player(self)
def load_data(self):
pass
def update(self):
self.sprites.update()
def draw(self):
self.screen.fill(BGCOLOR)
self.sprites.draw(self.screen)
pygame.display.update()
CLOCK.tick(FPS)
def events(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit(self.screen)
def display_fps(self):
self.caption = "{} - FPS: {:.2f}".format(CAPTION, CLOCK.get_fps())
pygame.display.set_caption(self.caption)
def run(self):
self.display_fps()
self.events()
self.update()
self.draw()
if __name__ == "__main__":
while True:
run_it = Control()
run_it.run()