''' Created on Jun 20, 2011 @author: catapult ''' ''' Created on Jun 19, 2011 @author: chenowet ''' import pygame from pygame.locals import * from pygame import Color class Mover: def __init__(self, centerX, centerY, radius, color, image="blob4.png", name = "noName"): self.rect = Rect(centerX-radius, centerY-radius, radius*2, radius*2) # if no image, makes a disk self.color = color self.blobimg = pygame.image.load(image) # loads the image we'll use, from file in "src" dir self.xspeed = 0 self.yspeed = 0 self.name = name # for debugging - see "str" method, defined below, which printing an object of this type will use def draw(self, surface): # this draws the mover pygame.draw.circle(surface, self.color, self.rect.center, self.rect.width//2) def draw_special(self, surface): # used for graphic version surface.blit(self.blobimg, self.rect.topleft) def changeSpeed(self, dx, dy): # a good way to use arrow keys to move a graphic object self.xspeed = self.xspeed + dx self.yspeed = self.yspeed + dy def moveWithSpeed(self): # done each time through event loop, to do the actual moving self.rect = self.rect.move(self.xspeed, self.yspeed) def move(self, dx, dy): # alternative - move them 1 pixel at a time self.rect = self.rect.move(dx,dy) def relocate(self, pos): # moving TO a specific location - another way, used here with mouse on "tim" self.rect.topleft = pos def __str__(self): # we can define what to "print" for debugging, for a given object of this class return str(self.name)+" "+str(self.xspeed)+" "+ str(self.yspeed)