-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
matthew
committed
Feb 18, 2013
1 parent
ade73b9
commit 25b1a7d
Showing
13 changed files
with
192 additions
and
6 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
core/src/main/scala/com/rathboma/playpen/buttons/SimpleButton.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
111
core/src/main/scala/com/rathboma/playpen/menu/MenuScreen.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
} | ||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters