Beispiel #1
0
 def __init__(self, screen):
     self.balls = ScatteringsHandler()
     ball = Ball(50, screen.get_height()/2)
     ball.velocity = Vector(3.0, -1.0)
     self.balls.add(ball)
     bar = Bar(screen.get_width()/2, screen.get_height()/2)
     self.balls.add(bar)
     self.blobble1 = Blobble(screen.get_width()/2, screen.get_height()/2)
     self.balls.add(self.blobble1)
     self.screen = screen
     self.background = screen.copy()
     self.background.fill((0,0,0))
     self.lastTicks = pg.time.get_ticks()
Beispiel #2
0
class Engine(object):
    def __init__(self, screen):
        self.balls = ScatteringsHandler()
        ball = Ball(50, screen.get_height()/2)
        ball.velocity = Vector(3.0, -1.0)
        self.balls.add(ball)
        bar = Bar(screen.get_width()/2, screen.get_height()/2)
        self.balls.add(bar)
        self.blobble1 = Blobble(screen.get_width()/2, screen.get_height()/2)
        self.balls.add(self.blobble1)
        self.screen = screen
        self.background = screen.copy()
        self.background.fill((0,0,0))
        self.lastTicks = pg.time.get_ticks()

    def mainLoop(self):
        t = pg.time.get_ticks()
        if t - self.lastTicks > 10:
            self.lastTicks = t
            self._moveEverything()
        else:
            pg.time.wait(2)
        self._drawEverything()

    def _drawEverything(self):
        self.balls.clear(self.screen, self.background)
        pg.display.update(self.balls.draw(self.screen))

    def _moveEverything(self):
        self.balls.update(self.screen.get_rect())
        self.balls.handleScatterings()

        keys = pg.key.get_pressed()
        if keys[pg.K_LEFT]: self.blobble1.walkLeft()
        if keys[pg.K_RIGHT]: self.blobble1.walkRight()
        if not (keys[pg.K_RIGHT] or keys[pg.K_LEFT]): self.blobble1.stop()
        if keys[pg.K_UP]: self.blobble1.jump()