blackarchan 0 Newbie Poster

I have a problem i wrote a code and copyed some code but now my sprite dosent move anymore....and i dont know why

# Import a library functions called 'pygame'
import pygame
from pygame.locals import *

# Initialize the game engine
pygame.init()


# Define some colors
black = (0, 0, 0)
white = (255, 255, 255)
green = (0, 255, 0)
red = (255, 0, 0)
blue = (0, 0, 255)

class Block(pygame.sprite.Sprite):

    # -- Attributes
    # Set speed vector
    change_x=0
    change_y=0

    def __init__(self,color, filename,x,y):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load(filename).convert()
        self.image.set_colorkey(black)
        self.rect = self.image.get_rect()
        self.rect.topleft = [x,y]
    def changespeed(self,x,y):
        self.change_x+=x
        self.change_y+=y
    # Find a new position for the player
    def update(self):
        self.rect.top += self.change_y
        self.rect.left += self.change_x


# Define some variables
pi = 3.141592653

# Set the width and height of the screen
size = [700, 500]

screen = pygame.display.set_mode(size)

pygame.display.set_caption("Black`s Cool Game")

x_speed = 0
y_speed = 0
x_cord  = 10
y_cord  = 10

player = Block(red,"plyr.png",10,10)
movingsprites = pygame.sprite.RenderPlain((player))
# Loop until the user clicks the close button.
done = False

# Useed to manage how fast the screen updates
clock = pygame.time.Clock()

# --------- Main Program Loop --------
while done == False:
    # ALL EVENT PROCESSING SHOULD GO BELOW THIS COMMENT
    for event in pygame.event.get():   # User did something
        if event.type == pygame.QUIT:  # If user clicked close
            done = True    # Flag that we are done so we exit thisw loop


        # Set the speed based on the key pressed
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                player.changespeed(-3,0)
            if event.key == pygame.K_RIGHT:
                player.changespeed(3,0)
            if event.key == pygame.K_UP:
                player.changespeed(0,-3)
            if event.key == pygame.K_DOWN:
                player.changespeed(0,3)

        # Reset speed when key goes up
        if event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT:
                player.changespeed(3,0)
            if event.key == pygame.K_RIGHT:
                player.changespeed(-3,0)
            if event.key == pygame.K_UP:
                player.changespeed(0,3)
            if event.key == pygame.K_DOWN:
                player.changespeed(0,-3)


    # ALL EVENT PROCESSING SHOULD GO ABOVE THIS COMMENT



    # ALL GAME LOGIC SHOULD GO BELLOW THIS COMMENT

    # ALL GAME LOGIC SHOULD GO ABOVE THIS COMMENT



    # ALL CODE TO DRAW SHOULD GO BELLOS THIS COMMENT
    # Clear the screen and set the screen background
    screen.fill(blue)
#
#    pygame.draw.rect(screen,red,[x_cord,y_cord,23,33],0)
#    x_cord += x_speed
#    y_cord += y_speed
    movingsprites.draw(screen)
    # ALL CODE TO DRAW SHOULD GO ABOVE THIS COMMENT

    # Go ahead and update the screen with what we`ve drawn.
    pygame.display.flip()

    # Limit to 20 frames per second
    clock.tick(20)


# Close the window and quit.
# If you forget this, the program will 'hang'
# on exit if running from IDLE
pygame.quit()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.