Created
October 27, 2012 21:37
-
-
Save bfb/3966429 to your computer and use it in GitHub Desktop.
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
package my.company.app | |
import net.scage.ScageScreenApp | |
import net.scage.ScageLib._ | |
import net.scage.support.{State, Vec} | |
import com.weiglewilczek.slf4s.Logger | |
import net.scage.support.tracer3.{TraceTrait, ScageTracer} | |
import net.scage.support.physics.ScagePhysics | |
import net.scage.support.physics.objects.{StaticLine, StaticBox, DynaBall} | |
object HomerTheDrunk extends ScageScreenApp("Homer, The Drunk", 800, 600) { | |
private val log = Logger(this.getClass.getName) | |
val physics = ScagePhysics() | |
val BACKGROUND_IMAGE = image("background.png", 800, 600, 0, 0, 800, 600) | |
//var game_over = new GameOver() | |
backgroundColor = BLACK | |
render(-10) { | |
drawDisplayList(BACKGROUND_IMAGE, windowCenter) | |
} | |
log.info("START") | |
//val down_edge = new StaticLine(Vec(windowWidth, 0), Vec(0, 0), true) | |
//physics.addPhysicals(down_edge) | |
var count = 0 | |
init { | |
count = 0 | |
} | |
var lifes = 3 | |
var homer = new Homer | |
var beers = List(new Beer(Vec(math.random*windowWidth, windowHeight-5))) | |
//var beer = new Beer(Vec(windowWidth/2, windowHeight-5)) | |
key(KEY_RIGHT, 2,homer.coord = Vec(homer.coord.x + 2, 53), homer.coord = Vec(homer.coord.x, 53)) | |
key(KEY_LEFT, 2, homer.coord = Vec(homer.coord.x - 2, 53), homer.coord = Vec(homer.coord.x, 53)) | |
key(KEY_R, onKeyDown = newGame()) | |
physics.addPhysicals(homer) | |
var beer_speed = property("game.speed", 20) | |
action(beer_speed) { | |
log.info("BEERS=>" + beers) | |
var beer_qtt = 100 | |
if((math.random*beer_qtt).toInt == 1){ | |
log.info("ADD NEW BEER") | |
// Add new beer | |
beers = beers ++ List(new Beer(Vec(math.random*windowWidth, windowHeight-5))) | |
} | |
beers.foreach { beer => | |
physics.addPhysicals(beer) | |
beer.move(Vec(0,-5)) | |
var x = beer.coord.x - homer.coord.x | |
var y = beer.coord.y - homer.coord.y | |
// Check if Homer drunk the beer | |
if((x<=50 && x>=0) && (y>=0 && y<= 4)){ | |
count += 1 | |
if(count > 10){ | |
beer_qtt = 200 | |
} | |
// Game level | |
if(count == 10){ | |
beer_speed = property("game.speed", 15) | |
} else if(count == 20){ | |
beer_speed = property("game.speed", 10) | |
} else if(count == 30){ | |
beer_speed = property("game.speed", 5) | |
} | |
beer.coord = Vec(-99999, -99999) | |
//beer = new Beer(Vec(windowWidth/2, windowHeight-5)) | |
//physics.addPhysicals(beer) | |
} | |
// Check lost beer | |
log.info("BEER X => " + beer.coord.x) | |
if(beer.coord.y.toInt == 0){ | |
lifes -= 1 | |
} | |
log.info("LIFES=>"+lifes) | |
if(lifes == 0){ | |
//pause() | |
// physics.addPhysicals(GameOver) | |
restart() | |
} | |
} | |
//beer.move(Vec(0,-1)) | |
} | |
interface { | |
print(count, 150, 564, WHITE) | |
print(lifes, 750, 564, WHITE) | |
} | |
def newGame(){ | |
//.removePhysicals(GameOver) | |
restart() | |
} | |
} | |
import HomerTheDrunk._ | |
class Beer(init_coord:Vec) extends StaticBox(init_coord, 80, 50, true) { | |
val beer_image = image("beer.png", 45, 87, 0, 0, 45, 87) | |
render { | |
drawDisplayList(beer_image, coord) | |
} | |
} | |
class Homer extends StaticBox(Vec(0, 53), 80, 50, true) { | |
val homer_image = image("homer.png", 203, 140, 0, 0, 203, 140)//, 0, 0, 203, 140) | |
render { | |
drawDisplayList(homer_image, coord) | |
} | |
} | |
object GameOver extends StaticBox(Vec(400,300), 0, 0, true){ | |
val gameover_image = image("gameover.png", 800, 600, 0, 0, 800, 600) | |
render { | |
drawDisplayList(gameover_image, coord) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment