예제 #1
0
    def create(self):
        w = Gdx.graphics.getWidth()
        h = Gdx.graphics.getHeight()

        self.camera = OrthographicCamera()
        self.camera.setToOrtho(False, (w / h) * 320, 320)
        self.camera.update()

        self.cameraController = OrthoCamController(self.camera)
        Gdx.input.setInputProcessor(self.cameraController)

        self.font = BitmapFont()
        self.batch = SpriteBatch()

        self.tiles = Texture(
            Gdx.files.internal('../../data/maps/tiled/tiles.png'))
        splitTiles = TextureRegion.split(self.tiles, 32, 32)
        self.map = TiledMap()
        layers = self.map.getLayers()
        for l in range(20):
            layer = TiledMapTileLayer(150, 100, 32, 32)
            for x in range(150):
                for y in range(100):
                    ty = int(Math.random() * len(splitTiles))
                    tx = int(Math.random() * len(splitTiles[ty]))
                    cell = Cell()
                    cell.setTile(StaticTiledMapTile(splitTiles[ty][tx]))
                    layer.setCell(x, y, cell)
            layers.add(layer)

        self.renderer = OrthogonalTiledMapRenderer(self.map)
예제 #2
0
    def create(self):
        '''
        setup the camera. In Box2D we operate on a
        meter scale, pixels won't do it. So we use
        an orthographic camera with a viewport of
        48 meters in width and 32 meters in height.
        we also position the camera so that it
        looks at (0, 16) (that's where the middle of the
        screen will be located).
        '''
        self.camera = OrthographicCamera(48, 32)
        self.camera.position.set(0, 15, 0)

        # create the debug renderer
        self.renderer = Box2DDebugRenderer()

        # create the world
        self.world = World(Vector2(0, -10), True)

        # we also need an invisible zero size ground body
        # to which we can connect the mouse joint
        bodyDef = BodyDef()
        self.groundBody = self.world.createBody(bodyDef)

        # call abstract method to populate the world
        self.createWorld(self.world)

        self.batch = SpriteBatch()
        self.font = BitmapFont(Gdx.files.internal('../data/arial-15.fnt'), False)

        Gdx.input.setInputProcessor(self)
예제 #3
0
    def __init__(self, game):
        """Dont need `create` in Screen instances. Constructor will do
         (even though __init__ isnt really a constructor...)
        """
        self.game = game

        self.dropimg = Texture("assets/droplet.png")
        self.bucketimg = Texture("assets/bucket.png")

        self.dropsound = Gdx.audio.newSound(Gdx.files.internal("assets/drop.wav"))
        self.rainmusic = Gdx.audio.newMusic(Gdx.files.internal("assets/rain.mp3"))
        self.rainmusic.setLooping(True)

        self.camera = OrthographicCamera()
        self.camera.setToOrtho(False, WIDTH, HEIGHT)

        self.bucket = Rectangle()
        self.bucket.x = 800 / 2 - 64 / 2 # initial starting point @ center of screen
        self.bucket.y = 20

        self.raindrops = Array()
        self.spawndrop()

        self.lastdroptime = 0
        self.dropsgathered = 0
예제 #4
0
class MainMenuScreen(Screen):
    def __init__(self, game):
        self.game = game

        self.camera = OrthographicCamera()
        self.camera.setToOrtho(False, 800, 400)


    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)

        with rend(self.game.batch) as btch:
            self.game.font.draw(btch, "Welcome to Drop!", 100, 150)
            self.game.font.draw(btch, "Tap Anywhere to begin!", 100, 100)

        if Gdx.input.isTouched():
            self.game.setScreen(GameScreen(self.game))
            self.dispose()

    def resize(self, w, h):
        pass

    def show(self):
        pass

    def hide(self):
        pass

    def pause(self):
        pass

    def resume(self):
        pass

    def dispose(self):
        pass
예제 #5
0
class TiledMapBench(GdxTest):
    def __init__(self):
        self.map = None
        self.renderer = None
        self.camera = None
        self.cameraController = None
        self.assetManager = None
        self.tiles = None
        self.texture = None
        self.font = None
        self.batch = None

    def create(self):
        w = Gdx.graphics.getWidth()
        h = Gdx.graphics.getHeight()

        self.camera = OrthographicCamera()
        self.camera.setToOrtho(False, (w / h) * 320, 320)
        self.camera.update()

        self.cameraController = OrthoCamController(self.camera)
        Gdx.input.setInputProcessor(self.cameraController)

        self.font = BitmapFont()
        self.batch = SpriteBatch()

        self.tiles = Texture(
            Gdx.files.internal('../../data/maps/tiled/tiles.png'))
        splitTiles = TextureRegion.split(self.tiles, 32, 32)
        self.map = TiledMap()
        layers = self.map.getLayers()
        for l in range(20):
            layer = TiledMapTileLayer(150, 100, 32, 32)
            for x in range(150):
                for y in range(100):
                    ty = int(Math.random() * len(splitTiles))
                    tx = int(Math.random() * len(splitTiles[ty]))
                    cell = Cell()
                    cell.setTile(StaticTiledMapTile(splitTiles[ty][tx]))
                    layer.setCell(x, y, cell)
            layers.add(layer)

        self.renderer = OrthogonalTiledMapRenderer(self.map)

    def render(self):
        Gdx.gl.glClearColor(100.0 / 255.0, 100.0 / 255.0, 250.0 / 255.0, 1.0)
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
        self.camera.update()
        self.renderer.setView(self.camera)
        self.renderer.render()
        self.batch.begin()
        self.font.draw(self.batch,
                       'FPS: ' + str(Gdx.graphics.getFramesPerSecond()), 10,
                       20)
        self.batch.end()
예제 #6
0
파일: __init__.py 프로젝트: paul-g/smash
    def create(self):
        self.input = SmashInput()
        Gdx.input.setInputProcessor(self.input)

        self.camera = OrthographicCamera()
        self.camera.setToOrtho(False, WIDTH, HEIGHT)
        self.batch = SpriteBatch()
        self.state = PLAYING

        self.background = Texture("assets/swahili.png")
        self.ball = Ball(Texture("assets/red_ball_16_16.png"),
                         BALL_SPEED, Circle(), Rectangle())
        self.dropimg = Texture("assets/red_rectangle.png")
        self.textures = {
            "r": Texture("assets/red_rectangle.png"),
            "b": Texture("assets/blue_rectangle.png"),
            "g": Texture("assets/green_rectangle.png"),
        }
        self.hud_font = BitmapFont()
        self.power_ups = {
            "r": (FireBall(2, Texture("assets/fire_ball.png")), 0.9),
            "b": (None, 1),
            "g": (LargeBall(2, Texture("assets/red_ball_32_32.png")), 0.9)
            }

        paddle_width = 100
        paddle_height = 50
        self.paddle = Paddle(Texture("assets/paddle.png"),
                             Rectangle((WIDTH - paddle_width) / 2, 0,
                                       paddle_width, paddle_height), self)
        self.drop_sound = Gdx.audio.newSound(
            Gdx.files.internal("assets/drop.wav"))
        self.rain_music = Gdx.audio.newSound(
            Gdx.files.internal("assets/rain.mp3"))

        with open("assets/checker_board.level") as f:
            blockLayout = f.read().split("\n")
        self.blocks = Blocks(blockLayout=blockLayout,
                             textures=self.textures,
                             hit_sound=self.drop_sound,
                             power_ups=self.power_ups)

        self.broken_blocks = 0
        self.delta_acc = 0
        self.play_time = 0
예제 #7
0
파일: Gdx.py 프로젝트: sinistersnare/PyGdx
 def create(self):        
     self.camera = OrthographicCamera()
     self.camera.setToOrtho(False, self.width, self.height)
     self.batch = SpriteBatch()
     self.dropimg = Texture("assets/droplet.png")
     self.bucketimg = Texture("assets/bucket.png")
     self.dropsound = Gdx.audio.newSound(Gdx.files.internal("assets/drop.wav"))
     self.rainmusic = Gdx.audio.newSound(Gdx.files.internal("assets/rain.mp3"))
     
     self.bucket = Rectangle()
     self.bucket.x = (self.width / 2) - (64 / 2)
     self.bucket.y = 20
     self.bucket.width = 64
     self.bucket.height = 64
     
     self.raindrops = Array()
     self.spawndrop()
     
     self.rainmusic.setLooping(True, True)
     self.rainmusic.play()
예제 #8
0
class GameScreen(Screen):

    def __init__(self, game):
        """Dont need `create` in Screen instances. Constructor will do
         (even though __init__ isnt really a constructor...)
        """
        self.game = game

        self.dropimg = Texture("assets/droplet.png")
        self.bucketimg = Texture("assets/bucket.png")

        self.dropsound = Gdx.audio.newSound(Gdx.files.internal("assets/drop.wav"))
        self.rainmusic = Gdx.audio.newMusic(Gdx.files.internal("assets/rain.mp3"))
        self.rainmusic.setLooping(True)

        self.camera = OrthographicCamera()
        self.camera.setToOrtho(False, WIDTH, HEIGHT)

        self.bucket = Rectangle()
        self.bucket.x = 800 / 2 - 64 / 2 # initial starting point @ center of screen
        self.bucket.y = 20

        self.raindrops = Array()
        self.spawndrop()

        self.lastdroptime = 0
        self.dropsgathered = 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()


    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()


    def resize(self, width, height):
        pass

    def show(self):
        self.rainmusic.play()

    def hide(self):
        pass

    def pause(self):
        pass

    def resume(self):
        pass

    def dispose(self):
        self.dropimg.dispose()
        self.bucketimg.dispose()
        self.dropsound.dispose()
        self.rainmusic.dispose()
예제 #9
0
class PyGDX(ApplicationAdapter):
    def __init__(self):
        self.camera = None
        self.batch = None
        self.texture = None
        self.bucketimg = None
        self.dropsound = None
        self.rainmusic = None
        self.bucket = None
        self.raindrops = None

        self.IMGLEN = 64 # width and height of bucket and drop
        self.SPEED = 200

        self.lastdrop = 0
        self.width = 800
        self.height = 480

    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()

    def create(self):
        self.camera = OrthographicCamera()
        self.camera.setToOrtho(False, self.width, self.height)
        self.batch = SpriteBatch()

        self.dropimg = Texture("assets/droplet.png")
        self.bucketimg = Texture("assets/bucket.png")
        self.dropsound = Gdx.audio.newSound(Gdx.files.internal("assets/drop.wav"))
        self.rainmusic = Gdx.audio.newSound(Gdx.files.internal("assets/rain.mp3"))

        self.bucket = Rectangle()
        self.bucket.x = (self.width / 2) - (self.IMGLEN / 2) # center of screen
        self.bucket.y = 20 # how far up it is
        self.bucket.width = self.IMGLEN
        self.bucket.height = self.IMGLEN

        self.raindrops = Array()
        self.spawndrop()

        self.rainmusic.setLooping(True, True)
        self.rainmusic.play()

    def render(self):
        SECOND = 1000000000
        DROPTIME = SECOND / 6
        Gdx.gl.glClearColor(0, 0, 0.2, 0)
        Gdx.gl.glClear(GL10.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 - (self.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 > (self.width - self.IMGLEN): self.bucket.x = self.width - self.IMGLEN

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


        # rip from java, don't hate me ;)
        iterator = self.raindrops.iterator()
        while iterator.hasNext():
            raindrop = iterator.next()
            raindrop.y -= self.SPEED * Gdx.graphics.getDeltaTime();
            if (raindrop.y + self.IMGLEN) < 0: iterator.remove()
            if raindrop.overlaps(self.bucket):
                self.dropsound.play()
                iterator.remove()


    def dispose(self):
        self.batch.dispose()
        self.dropimg.dispose()
        self.bucketimg.dispose()
        self.dropsound.dispose()
        self.rainmusic.dispose()
예제 #10
0
    def __init__(self, game):
        self.game = game

        self.camera = OrthographicCamera()
        self.camera.setToOrtho(False, 800, 400)
예제 #11
0
파일: __init__.py 프로젝트: paul-g/smash
class SmashGame(ApplicationListener):
    def __init__(self):
        super(SmashGame, self).__init__()
        self.camera = None
        self.batch = None
        self.textures = None
        self.paddle = None
        self.drop_sound = None
        self.rain_music = None
        self.blocks = None
        self.background = None
        self.state = None
        self.ball = None
        self.dropimg = None
        self.hud_font = None
        self.input = None
        self.power_ups = None
        self.broken_blocks = 0
        self.delta_acc = 0
        self.play_time = 0

    def screen_width(self):
        return WIDTH

    def screen_height(self):
        return HEIGHT

    def create(self):
        self.input = SmashInput()
        Gdx.input.setInputProcessor(self.input)

        self.camera = OrthographicCamera()
        self.camera.setToOrtho(False, WIDTH, HEIGHT)
        self.batch = SpriteBatch()
        self.state = PLAYING

        self.background = Texture("assets/swahili.png")
        self.ball = Ball(Texture("assets/red_ball_16_16.png"),
                         BALL_SPEED, Circle(), Rectangle())
        self.dropimg = Texture("assets/red_rectangle.png")
        self.textures = {
            "r": Texture("assets/red_rectangle.png"),
            "b": Texture("assets/blue_rectangle.png"),
            "g": Texture("assets/green_rectangle.png"),
        }
        self.hud_font = BitmapFont()
        self.power_ups = {
            "r": (FireBall(2, Texture("assets/fire_ball.png")), 0.9),
            "b": (None, 1),
            "g": (LargeBall(2, Texture("assets/red_ball_32_32.png")), 0.9)
            }

        paddle_width = 100
        paddle_height = 50
        self.paddle = Paddle(Texture("assets/paddle.png"),
                             Rectangle((WIDTH - paddle_width) / 2, 0,
                                       paddle_width, paddle_height), self)
        self.drop_sound = Gdx.audio.newSound(
            Gdx.files.internal("assets/drop.wav"))
        self.rain_music = Gdx.audio.newSound(
            Gdx.files.internal("assets/rain.mp3"))

        with open("assets/checker_board.level") as f:
            blockLayout = f.read().split("\n")
        self.blocks = Blocks(blockLayout=blockLayout,
                             textures=self.textures,
                             hit_sound=self.drop_sound,
                             power_ups=self.power_ups)

        self.broken_blocks = 0
        self.delta_acc = 0
        self.play_time = 0

    def score(self):
        return "Blocks %d, Time %.1f, Rating: %s" % (
            self.broken_blocks, self.play_time,
            self.ball.get_power_ups_string())

    def draw(self):
        """ Do any and all drawing. """
        self.camera.update()
        self.batch.setProjectionMatrix(self.camera.combined)
        self.batch.begin()
        self.batch.draw(self.background, 0, 0, WIDTH, HEIGHT)
        self.blocks.draw(self.batch)
        self.paddle.draw(self.batch)
        self.ball.draw(self.batch)
        self.hud_font.draw(self.batch, self.score(), 20, 20)
        if self.state == LOST:
            self.big_centered_text(self.batch, "You are lose!")
        elif self.state == WON:
            self.big_centered_text(self.batch, "A winner is you!")
        self.batch.end()

    def tick(self, delta, input):
        """ Another 1/60 seconds have passed.  Update state. """
        if self.state == PLAYING:
            self.play_time += delta

            if input.touched:
                # not tested
                self.paddle.set_x(input.touched.x - (64 / 2))
            if input.is_left_pressed():
                self.paddle.move(delta, -1)
            if input.is_right_pressed():
                self.paddle.move(delta)

            if (self.ball.rectangle.y < self.paddle.top()
                and not self.paddle.hits(self.ball)):
                self.state = LOST

            if self.blocks.blocks.size == 0:
                self.state = WON

            self.ball.tick(delta)
            self.ball.update_coordinates(
                delta, WIDTH, HEIGHT,
                check_hits_block=self.check_hits_block,
                check_hits_paddle=self.paddle.hits)

    def render(self):
        Gdx.gl.glClearColor(0, 0, 0, 0)
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT)

        self.delta_acc += Gdx.graphics.getDeltaTime()
        while self.delta_acc > TICK_TIME:
            input = self.input.tick(TICK_TIME, self.camera)
            self.tick(TICK_TIME, input)
            self.delta_acc -= TICK_TIME

        self.draw()

    def big_centered_text(self, batch, text):
        self.hud_font.draw(
            batch, text,
            (WIDTH - self.hud_font.getBounds(text).width) / 2,
            HEIGHT / 3 * 2)

    def check_hits_block(self, ball):
        block = self.blocks.check_hit(ball)
        if block:
            self.broken_blocks += 1
            power_up = block.get_power_up()
            if power_up:
                ball.add_power_up(power_up)
                power_up.reset_remaining()
        return block

    def updatePowerUps(self):
        self.ball.updatePowerUps()

    def resize(self, width, height):
        pass

    def pause(self):
        pass

    def resume(self):
        pass

    def dispose(self):
        """"Handle dispose event"""
        self.batch.dispose()
        for (_, texture) in self.textures.items():
            texture.dispose()
        self.paddle.texture.dispose()
        self.drop_sound.dispose()
        self.rain_music.dispose()
        self.hud_font.dispose()
예제 #12
0
class PyGdx(ApplicationListener):
    def __init__(self):
        self.camera = None
        self.batch = None
        self.texture = None
        self.bucketimg = None
        self.dropsound = None
        self.rainmusic = None
        self.bucket = None
        self.raindrops = None

        self.lastdrop = 0
        self.width = 800
        self.height = 480

    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()

    def create(self):        
        self.camera = OrthographicCamera()
        self.camera.setToOrtho(False, self.width, self.height)
        self.batch = SpriteBatch()

        self.dropimg = Texture("../assets/droplet.png")
        self.bucketimg = Texture("../assets/bucket.png")
        self.dropsound = Gdx.audio.newSound(Gdx.files.internal("../assets/drop.wav"))
        self.rainmusic = Gdx.audio.newSound(Gdx.files.internal("../assets/rain.mp3"))

        self.bucket = Rectangle()
        self.bucket.x = (self.width / 2) - (64 / 2)
        self.bucket.y = 20
        self.bucket.width = 64
        self.bucket.height = 64

        self.raindrops = Array()
        self.spawndrop()

        self.rainmusic.setLooping(True, True)
        self.rainmusic.play()

    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()

    def resize(self, width, height):
        pass

    def pause(self):
        pass

    def resume(self):
        pass

    def dispose(self):
        self.batch.dispose()
        self.dropimg.dispose()
        self.bucketimg.dispose()
        self.dropsound.dispose()
        self.rainmusic.dispose()
예제 #13
0
class Box2DTest(ApplicationListener, InputProcessor):
    '''
    Base class for all Box2D Testbed tests, all subclasses must implement
    the createWorld() method.
    '''
    def __init__(self):
        # the camera
        self.camera = None

        # the renderer
        self.renderer = None

        self.batch = None
        self.font = None

        # our box2D world
        self.world = None

        # ground body to connect the mouse joint to
        self.groundBody = None

        # our mouse joint
        self.mouseJoint = None

        # a hit body
        self.hitBody = None

        self.testPoint = Vector3()
        self.callback = Box2DTest.QueryCallbackNew(self)

        # temp vector
        self.tmp = Vector2()

        # another temporary vector
        self.target = Vector2()

    def createWorld(self, world):
        raise NotImplementedError()

    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()

    def create(self):
        '''
        setup the camera. In Box2D we operate on a
        meter scale, pixels won't do it. So we use
        an orthographic camera with a viewport of
        48 meters in width and 32 meters in height.
        we also position the camera so that it
        looks at (0, 16) (that's where the middle of the
        screen will be located).
        '''
        self.camera = OrthographicCamera(48, 32)
        self.camera.position.set(0, 15, 0)

        # create the debug renderer
        self.renderer = Box2DDebugRenderer()

        # create the world
        self.world = World(Vector2(0, -10), True)

        # we also need an invisible zero size ground body
        # to which we can connect the mouse joint
        bodyDef = BodyDef()
        self.groundBody = self.world.createBody(bodyDef)

        # call abstract method to populate the world
        self.createWorld(self.world)

        self.batch = SpriteBatch()
        self.font = BitmapFont(Gdx.files.internal('../data/arial-15.fnt'), False)

        Gdx.input.setInputProcessor(self)

    def dispose(self):
        self.renderer.dispose()
        self.world.dispose()

        self.renderer = None
        self.world = None
        self.mouseJoint = None
        self.hitBody = None

    def keyDown(self, keycode):
        return False

    def keyTyped(self, character):
        return False

    def keyUp(self, keycode):
        return False

    class QueryCallbackNew(QueryCallback):
        def __init__(self, test):
            self.test = test

        def reportFixture(self, fixture):
            # if the hit point is inside the fixture of the body
            # we report it
            if fixture.testPoint(self.test.testPoint.x, self.test.testPoint.y):
                self.test.hitBody = fixture.getBody()
                return False
            else:
                return True

    def touchDown(self, x, y, pointer, button):
        print 'Touch down!'
        # translate the mouse coordinates to world coordinates
        self.camera.unproject(self.testPoint.set(x, y, 0))
        # ask the world which bodies are within the given
        # bounding box around the mouse pointer
        self.hitBody = None
        self.world.QueryAABB(self.callback, self.testPoint.x - 0.0001, self.testPoint.y - 0.0001, self.testPoint.x + 0.0001, self.testPoint.y + 0.0001)

        if self.hitBody == self.groundBody: self.hitBody = None

        # ignore kinematic bodies, they don't work with the mouse joint
        if self.hitBody != None and self.hitBody.getType() == BodyType.KinematicBody: return False

        # if we hit something we create a new mouse joint
        # and attach it to the hit body
        if self.hitBody != None:
            deff = MouseJointDef()
            deff.bodyA = self.groundBody
            deff.bodyB = self.hitBody
            deff.collideConnected = True
            deff.target.set(self.testPoint.x, self.testPoint.y)
            deff.maxForce = 1000 * self.hitBody.getMass()

            self.mouseJoint = self.world.createJoint(deff)
            self.hitBody.setAwake(True)

        return False

    def touchDragged(self, x, y, pointer):
        '''
        if a mouse joint exists we simply update
        the target of the joint based on the new
        mouse coordinates
        '''
        print 'Touch dragged!'
        if self.mouseJoint:
            self.camera.unproject(self.testPoint.set(x, y, 0))
            self.mouseJoint.setTarget(self.target.set(self.testPoint.x, self.testPoint.y))
        return False

    def touchUp(self, x, y, pointer, button):
        # if a mouse joint exists we simply destroy it
        print 'Touch up!'
        if self.mouseJoint:
            self.world.destroyJoint(self.mouseJoint)
            self.mouseJoint = None
        return False

    def mouseMoved(self, x, y):
        return False

    def scrolled(self, amount):
        return False

    def pause(self):
        pass

    def resume(self):
        pass

    def resize(self, width, height):
        pass