[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] Why is there no movement in this code.



#!/usr/bin/env python

import os
import sys
import pygame
from pygame.locals import *

width , height = 1680 , 1050

pygame.init()
fpsclock = pygame.time.Clock()
fpsclock.tick(50)
screen = pygame.display.set_mode((width,height))
pygame.display.set_caption("SteamPunk")


backfile = os.path.join("images","steampunk.jpg")
backfile_surface = pygame.image.load(backfile)
backfile_surface = pygame.transform.scale(backfile_surface ,(1680,1050))
screen.blit(backfile_surface,(0,0))
pygame.display.update()

def input(events): 
   for event in events: 
      if event.type == QUIT: 
         sys.exit(0) 
      else: 
         print event
         
         
         
         
def load_image(name, colorkey=None):
    fullname = os.path.join('images', name)
    try:
        image = pygame.image.load(fullname)
    except pygame.error, message:
        print("Cannot load image:", name)
        raise SystemExit, message
    image = image.convert()
    if colorkey is not None:
        if colorkey is -1:
            colorkey = image.get_at((0,0))
        image.set_colorkey(colorkey, RLEACCEL)
    return image, image.get_rect()

def load_sound(name):
    class NoneSound:
        def play(self): pass
    if not pygame.mixer:
        return NoneSound()
    fullname = os.path.join('images', name)
    try:
        sound = pygame.mixer.Sound(fullname)
    except pygame.error, message:
        print("Cannot load sound:", wav)
        raise SystemExit, message
    return sound


class Fighter(pygame.sprite.Sprite):
   
    def __init__(self):
        pygame.sprite.Sprite.__init__(self) #call Sprite initializer
        self.currentx = 50
        self.currenty = (height - 389)
        self.image, self.rect = load_image("Fighter1.jpg", -1)
        self.rect.topleft = (self.currentx,self.currenty )

    def update(self):

        move = self.rect.move(self.currentx,self.currenty)
        self.rect = move
    
    def moveleft(self):
        "move the fighter to the left of current position"
        self.currentx += 100
        
    

fighter1 = Fighter()
allsprites = pygame.sprite.RenderUpdates()
allsprites.add(fighter1)
rectlist = allsprites.draw(screen)
pygame.display.update(rectlist)

fighter1.moveleft()
fighter1.update()
rectlist = allsprites.draw(screen)
pygame.display.update()



--
View this message in context: http://pygame-users.25799.n6.nabble.com/Why-is-there-no-movement-in-this-code-tp419.html
Sent from the pygame-users mailing list archive at Nabble.com.