Skip to content

Commit

Permalink
Merge 76b8f3e into b3937ce
Browse files Browse the repository at this point in the history
  • Loading branch information
ivojawer committed Sep 19, 2019
2 parents b3937ce + 76b8f3e commit a927f1c
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ abstract class Position {
def abstract int getX()
def abstract int getY()

def getXinPixels() { x * Gameboard.CELLZISE }
def getXinPixels() { x * Gameboard.instance.cellsize }

def getYinPixels() { y * Gameboard.CELLZISE }
def getYinPixels() { y * Gameboard.instance.cellsize }

override public int hashCode() {
val prime = 31
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ class VisualComponent {
val yMouse = Gdx.input.y
val bottomX = position.xinPixels
val bottomY = Gameboard.getInstance().pixelHeight - position.yinPixels
val topX = bottomX + Gameboard.CELLZISE
val topY = bottomY - Gameboard.CELLZISE
val topX = bottomX + Gameboard.instance.cellsize
val topY = bottomY - Gameboard.instance.cellsize
return (xMouse > bottomX && xMouse < topX) && (yMouse < bottomY && yMouse > topY)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Cell {

new(Position position, Image image) {
this.position = position
this.image = image => [ size = new CellSize(Gameboard.CELLZISE) ]
this.image = image => [ size = new CellSize(Gameboard.instance.cellsize) ]
}

def draw(Window window) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import static org.uqbar.project.wollok.sdk.WollokSDK.*

@Accessors
class Gameboard {
public static Gameboard instance
public static final int CELLZISE = 50
static Gameboard instance

val Logger log = Logger.getLogger(this.class)

Expand All @@ -32,6 +31,7 @@ class Gameboard {
String boardGround
int height
int width
@Accessors int cellsize = 50
Background background
List<VisualComponent> components = newArrayList
List<GameboardListener> listeners = newArrayList
Expand All @@ -41,10 +41,14 @@ class Gameboard {

def static getInstance() {
if (instance === null) {
instance = new Gameboard()
resetInstance
}
instance
}

def static resetInstance() {
instance = new Gameboard()
}

new() {
title = "Wollok Game"
Expand Down Expand Up @@ -102,9 +106,9 @@ class Gameboard {
null
}

def pixelHeight() { height * CELLZISE }
def pixelHeight() { height * cellsize }

def pixelWidth() { width * CELLZISE }
def pixelWidth() { width * cellsize }

def clear() {
components.clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class GameboardInputProcessor implements InputProcessor {

override boolean touchDown(int x, int y, int pointer, int button) {
val inverseY = Gameboard.getInstance().pixelHeight() - y
val position = new WGPosition(x / Gameboard.CELLZISE, inverseY / Gameboard.CELLZISE )
val position = new WGPosition(x / Gameboard.instance.cellsize, inverseY / Gameboard.instance.cellsize )

val Iterable<VisualComponent> lista = Gameboard.getInstance.getComponentsInPosition(position)

Expand Down
14 changes: 14 additions & 0 deletions org.uqbar.project.wollok.lib/src/wollok/game.wlk
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,20 @@ object game {
*/
method ground(image) native

/**
* Sets cells size.
*/
method cellSize(size){
if(size<=0)
throw new Exception(message = "Cell size can't be 0 or lower")
self.doCellSize(size)
}

/**
* @private
*/
method doCellSize(size) native

/**
* Sets full background image.
*/
Expand Down
2 changes: 2 additions & 0 deletions org.uqbar.project.wollok.lib/src/wollok/game/GameObject.xtend
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,6 @@ class GameObject {
def ground(String image) { board.ground = image }
def boardGround(String image) { board.boardGround = image }

def doCellSize(WollokObject size) { board.cellsize = size.coerceToInteger }

}
Loading

0 comments on commit a927f1c

Please sign in to comment.