예제 #1
0
 def spawndrop(self):
     raindrop = Rectangle() # no self! :p
     raindrop.x = MathUtils.random(0, WIDTH - 64) # screen X co-ords
     raindrop.y = HEIGHT # always spawns on top
     raindrop.width = raindrop.height = 64
     self.raindrops.add(raindrop)
     self.lastdroptime = TimeUtils.nanoTime()
예제 #2
0
    def render(self):
        Gdx.gl.glClearColor(0,0,0.2,0)
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)

        self.camera.update()

        self.batch.setProjectionMatrix(self.camera.combined)
        self.batch.begin()
        self.batch.draw(self.bucketimg, self.bucket.x, self.bucket.y)
        for drop in self.raindrops:
            self.batch.draw(self.dropimg, drop.x, drop.y)
        self.batch.end()

        if Gdx.input.isTouched():
            touchpos = Vector3()
            touchpos.set(Gdx.input.getX(), Gdx.input.getY(), 0)
            self.camera.unproject(touchpos)
            self.bucket.x = touchpos.x - (64 / 2)
        if Gdx.input.isKeyPressed(Input.Keys.LEFT): self.bucket.x -= 200 * Gdx.graphics.getDeltaTime()
        if Gdx.input.isKeyPressed(Input.Keys.RIGHT): self.bucket.x += 200 * Gdx.graphics.getDeltaTime()

        if self.bucket.x < 0: self.bucket.x = 0
        if self.bucket.x > (self.width - 64): self.bucket.x = self.width - 64

        if (TimeUtils.nanoTime() - self.lastdrop) > 1000000000: self.spawndrop()

        iterator = self.raindrops.iterator()
        while iterator.hasNext():
            raindrop = iterator.next()
            raindrop.y -= 200 * Gdx.graphics.getDeltaTime();
            if (raindrop.y + 64) < 0: iterator.remove()
            if raindrop.overlaps(self.bucket):
                self.dropsound.play()
                iterator.remove()
예제 #3
0
 def spawndrop(self):
     raindrop = Rectangle()
     raindrop.x = MathUtils.random(0, self.width - self.IMGLEN) # can't be outside screen
     raindrop.y = self.height
     raindrop.width = self.IMGLEN
     raindrop.height = self.IMGLEN
     self.raindrops.add(raindrop)
     self.lastdrop = TimeUtils.nanoTime()
예제 #4
0
 def spawndrop(self):
     raindrop = Rectangle()
     raindrop.x = MathUtils.random(0, self.width - 64)
     raindrop.y = self.height
     raindrop.width = 64
     raindrop.height = 64
     self.raindrops.add(raindrop)
     self.lastdrop = TimeUtils.nanoTime()
예제 #5
0
    def render(self):
        # update the world with a fixed time step
        startTime = TimeUtils.nanoTime()
        self.world.step(Gdx.app.getGraphics().getDeltaTime(), 3, 3)
        updateTime = (TimeUtils.nanoTime() - startTime) / 1000000000.0

        startTime = TimeUtils.nanoTime()
        # clear the screen and set up the projection matrix
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
        self.camera.update()

        # render the world using the debug renderer
        self.renderer.render(self.world, self.camera.combined)
        renderTime = (TimeUtils.nanoTime() - startTime) / 1000000000.0

        self.batch.begin()
        self.font.draw(self.batch, 'fps:' + str(Gdx.graphics.getFramesPerSecond()) + ', update: ' + str(updateTime) + ', render: ' + str(renderTime), 0, 20)
        self.batch.end()
예제 #6
0
    def render(self, delta):
        Gdx.gl.glClearColor(0, 0, 0.2, 1)
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT)

        self.camera.update()

        self.game.batch.setProjectionMatrix(self.camera.combined)

        SECOND = 1000000000 # nano-seconds
        DROPTIME = SECOND


        self.game.batch.begin() # much less verbose with a context manager....
        self.game.batch.draw(self.bucketimg, self.bucket.x, self.bucket.y)
        self.game.batch.end()
        with rend(self.game.batch) as btch: # don't add an "i"!
            self.game.font.draw(btch, "Drops Collected: {}".format(self.dropsgathered), 0, HEIGHT)
            btch.draw(self.bucketimg, self.bucket.x, self.bucket.y)
            for drop in self.raindrops:
                btch.draw(self.dropimg, drop.x, drop.y)


        if Gdx.input.isTouched():
            touchpos = Vector3()
            touchpos.set(Gdx.input.getX(), Gdx.input.getY(), 0)
            self.camera.unproject(touchpos)
            self.bucket.x = touchpos.x - (IMGLEN / 2)
        if Gdx.input.isKeyPressed(Input.Keys.LEFT):
            self.bucket.x -= self.SPEED * Gdx.graphics.getDeltaTime()
        if Gdx.input.isKeyPressed(Input.Keys.RIGHT):
            self.bucket.x += self.SPEED * Gdx.graphics.getDeltaTime()

        if self.bucket.x < 0: self.bucket.x = 0
        if self.bucket.x > (WIDTH - 64): self.bucket.x = WIDTH - 64

        if (TimeUtils.nanoTime() - self.lastdroptime) > DROPTIME: self.spawndrop()


        iterator = self.raindrops.iterator()
        while iterator.hasNext():
            raindrop = iterator.next()
            raindrop.y -= SPEED * Gdx.graphics.getDeltaTime();
            if (raindrop.y + IMGLEN) < 0: iterator.remove()
            if raindrop.overlaps(self.bucket):
                self.dropsound.play()
                iterator.remove()