Skip to content

Commit

Permalink
Animation and menu screens.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew committed Feb 18, 2013
1 parent ade73b9 commit 25b1a7d
Show file tree
Hide file tree
Showing 13 changed files with 192 additions and 6 deletions.
Binary file added assets/default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added assets/skins/skin.json
Empty file.
Binary file modified core/lib/gdx-natives.jar
Binary file not shown.
Binary file modified core/lib/gdx.jar
Binary file not shown.
6 changes: 4 additions & 2 deletions core/src/main/scala/com/rathboma/playpen/PlaypenGame.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.GL20
import com.rathboma.playpen.box2dcharacter.Box2DPlayerScreen
import com.rathboma.playpen.animation.SpriteAnimationScreen
import com.rathboma.playpen.menu.MenuScreen

class PlaypenGame extends Game {

class PlaypenGame(val width: Int, val height: Int) extends Game {

override def create {
setScreen(new SpriteAnimationScreen())
setScreen(new MenuScreen(this))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import com.badlogic.gdx.graphics.{Texture}
import com.badlogic.gdx.InputAdapter
import com.badlogic.gdx.Input.Keys
import com.badlogic.gdx.graphics.GL10
import com.rathboma.playpen.util.Logging
import com.rathboma.playpen.PlaypenGame
import com.rathboma.playpen.menu.MenuScreen

object Movement {
val NONE = -2
Expand All @@ -18,8 +21,8 @@ object SpriteAnimationScreen {
val characterSheet = new Texture(Gdx.files.internal("assets/character.png"))
}

class SpriteAnimationScreen extends InputAdapter with Screen {

class SpriteAnimationScreen(game: PlaypenGame) extends InputAdapter with Screen with Logging {
logger.info("SpriteAnimationScreen hi!")
Gdx.input.setInputProcessor(this)
val width = Gdx.graphics.getWidth
val height = Gdx.graphics.getHeight
Expand Down Expand Up @@ -62,11 +65,16 @@ class SpriteAnimationScreen extends InputAdapter with Screen {
// input adapter

override def keyDown(keycode: Int): Boolean = {

movement = keycode match {
case Keys.W => Movement.UP
case Keys.A => Movement.LEFT
case Keys.S => Movement.DOWN
case Keys.D => Movement.RIGHT
case Keys.ESCAPE => {
game.setScreen(new MenuScreen(game))
Movement.NONE
}
case _ => Movement.NONE
}
false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.rathboma.playpen.box2dcharacter

import com.rathboma.playpen.PlaypenGame
import com.rathboma.playpen.menu.MenuScreen

import com.badlogic.gdx.ApplicationListener
import com.badlogic.gdx.{Gdx, Screen}
Expand Down Expand Up @@ -59,7 +60,7 @@ class Box2DPlayerScreen(game: PlaypenGame) extends InputAdapter with Screen {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT)
cam.position.set(player.position.x, player.position.y, 0)
cam.update
cam.apply(Gdx.gl10)
// cam.apply(Gdx.gl11)
matrix.set(cam.combined)
renderer.render(world, matrix)
cam.project(point.set(player.position.x, player.position.y, 0))
Expand Down Expand Up @@ -118,6 +119,7 @@ class Box2DPlayerScreen(game: PlaypenGame) extends InputAdapter with Screen {
if (keycode == Keys.W) shouldJump = true
if (keycode == Keys.A) leftPressed = true
if (keycode == Keys.D) rightPressed = true
if (keycode == Keys.ESCAPE) game.setScreen(new MenuScreen(game))
false
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.rathboma.playpen.buttons

import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import com.badlogic.gdx.graphics.glutils.ShapeRenderer._
import com.badlogic.gdx.graphics.g2d.BitmapFont
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment
import com.rathboma.playpen.util.Logging

class SimpleButton(text: String, x: Int, y: Int) extends Logging {

val font = new BitmapFont()
val bounds = font.getBounds(text)
val w = bounds.width * 2
val h = bounds.height * 2

// evil vars
var pressed = false
var down = false

var touchFunc: () => Boolean = () => {false}

def onTouch(func: => Boolean) {
touchFunc = () => func
}

def touchDown() = {
down = true
}

def touchUp() = {
down = false
touchFunc()
}

def includes(xt: Int, yt: Int): Boolean = {

val result = xt >= x - (w/2) && xt <= x + (w/2) && yt >= y - (h / 2) && yt <= y + (h/2)
logger.debug("button '%s' includes point? %s".format(text, result.toString))
result
}

def drawShapes(renderer: ShapeRenderer) = {
renderer.begin(ShapeType.FilledRectangle)
renderer.setColor(if (down) Color.RED else Color.BLUE)
renderer.filledRect(x - (w/2), y - (h/2), w, h)
renderer.end()
}

def draw(batch: SpriteBatch) = {
batch.setColor(Color.WHITE)
font.draw(batch, text, x - (bounds.width / 2), y + (bounds.height / 2))
}

}
111 changes: 111 additions & 0 deletions core/src/main/scala/com/rathboma/playpen/menu/MenuScreen.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.rathboma.playpen.menu

import com.badlogic.gdx.{Gdx, Screen}
import com.badlogic.gdx.scenes.scene2d.InputEvent
import com.badlogic.gdx.scenes.scene2d.InputListener
import com.badlogic.gdx.scenes.scene2d.Stage
import com.badlogic.gdx.graphics.g2d.BitmapFont
import com.badlogic.gdx.scenes.scene2d.ui.{Table, TextButton, Skin}
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle
import com.rathboma.playpen.box2dcharacter.Box2DPlayerScreen
import com.rathboma.playpen.animation.SpriteAnimationScreen
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.rathboma.playpen.buttons._
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import com.badlogic.gdx.graphics.GL10
import com.badlogic.gdx.InputAdapter
import com.rathboma.playpen.util.Logging
import com.rathboma.playpen.PlaypenGame

class MenuScreen(game: PlaypenGame) extends InputAdapter with Screen with Logging {
Gdx.input.setInputProcessor(this)
logger.info("menu screen start")
val batch = new SpriteBatch()
val renderer = new ShapeRenderer()

val middle = game.width / 2
val thirdHeight = game.height / 3

val box2dButton = new SimpleButton("Box2D Demo", middle, thirdHeight)
val animationButton = new SimpleButton("Character Animation",middle, thirdHeight*2 )
var updateAction: Option[Int] = None
box2dButton.onTouch {
game.setScreen(new Box2DPlayerScreen(game))
true
}
animationButton.onTouch {
game.setScreen(new SpriteAnimationScreen(game))
true
}

val buttons = List(box2dButton, animationButton)

def render(delta: Float) {


Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
buttons.foreach{button =>
button.drawShapes(renderer)
}

batch.begin()
buttons.foreach{button =>
button.draw(batch)
}
batch.end()
}

val dimensions: Tuple2[Int, Int] = (game.width, game.height)

override def touchDown(x: Int, screenY: Int, pointer: Int, button: Int): Boolean = {
val y = game.height - screenY
logger.info("TOUCH DOWN %d, %d".format(x, y))
buttons.foreach{button =>
if (button.includes(x, y)) button.touchDown()
}
true
}

override def touchUp(x: Int, screenY: Int, pointer: Int, button: Int): Boolean = {
val y = game.height - screenY
logger.info("TOUCH UP %d, %d".format(x, y))
buttons.foreach{button =>
if (button.includes(x, y)) button.touchUp()
}
true
}

override def keyDown(kc: Int) = {
logger.info("KEY DOWN: %d".format(kc))
true
}


def resize(width: Int, height: Int) {

}

def show {

}

def hide {

}

def pause {

}

def resume {

}

def dispose {

}




}
7 changes: 7 additions & 0 deletions core/src/main/scala/com/rathboma/playpen/util/Logging.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

package com.rathboma.playpen.util
import com.badlogic.gdx.utils.Logger

trait Logging {
val logger = new Logger(getClass.getName, Logger.DEBUG)
}
Binary file modified desktop/lib/gdx-backend-lwjgl-natives.jar
Binary file not shown.
Binary file modified desktop/lib/gdx-backend-lwjgl.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion desktop/src/main/scala/com/rathboma/playpen/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ object Main {
cfg.height = 480
cfg.resizable = false

new LwjglApplication(new PlaypenGame(), cfg)
new LwjglApplication(new PlaypenGame(cfg.width, cfg.height), cfg)
}
}

0 comments on commit 25b1a7d

Please sign in to comment.