Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """ This code can be used as a starting pointto create an object using pygame. Related to the code an object falls onto another object moving in a circular path and stays without falling off"""
- import pygame
- 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 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
- self.speedx = colob.speedx
- self.speedy += colob.speedy
- """when there was no change to self.speedy with regard to the platform the box fell off the left edge.
- when self.speedy = colob.speedy
- the box moved to the right and fell of the right edge after 36 rotations.
- But when self.speedy += colob.speedy
- and the box speed was restricted by the code below the box stayed on the platform even after 570 rotations and there was no visible displacement."""
- if self.speedy >= 4 or self.speedy <= 2:
- self.speedy = 4
- def move(self): # wallsprites, Herosprite, looptime
- self.rect.x += self.speedx
- self.rect.y += self.speedy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement