Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- from math import cos, sin, pi
- class object_factory(pygame.sprite.Sprite):
- #----------------------------------------------------------------------
- def __init__(self, imagelist, xpos = 0, ypos = 0, speedx = 0, speedy = 0, value = 0):
- """Constructor"""
- pygame.sprite.Sprite.__init__(self)
- self.name = ""
- self.frame = 0
- self.imagelist = imagelist
- self.image = imagelist[self.frame]
- self.mask = pygame.mask.from_surface(self.image) # pixelmask
- self.rect = self.image.get_rect()
- self.rect.x = xpos
- self.rect.y = ypos
- self.speedx = speedx
- self.speedy = speedy
- self.timer = 0
- self.timerlimit = 10
- #----------------------------------------------------------------------
- def move(self): # wallsprites, Herosprite, looptime
- self.rect.x += self.speedx
- self.rect.y += self.speedy
- #----------------------------------------------------------------------
- def update(self):
- """"""
- self.image = self.imagelist[self.frame]
- if self.timer >= self.timerlimit:
- self.frame += 1
- if self.frame >= len(self.imagelist):
- self.frame = 0
- self.timer = 0
- self.timer += 1
- #----------------------------------------------------------------------
- def collide(self, colwith):
- """"""
- hit_list = pygame.sprite.spritecollide(self, colwith, False, collided = pygame.sprite.collide_rect)
- for colob in hit_list:
- if self.rect.bottom > colob.rect.top:
- self.rect.bottom = colob.rect.top
- print self.rect.x, self.rect.y, colob.speedx, colob.speedy
- self.speedx = colob.speedx
- #self.rect.y = colob.rect.y - self.rect.height
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement