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
Showing
7 changed files
with
281 additions
and
9 deletions.
There are no files selected for viewing
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
58 changes: 58 additions & 0 deletions
58
Bomberman/src/main/java/com/almasb/bomberman/BombermanFactory.java
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,58 @@ | ||
package com.almasb.bomberman; | ||
|
||
import com.almasb.bomberman.control.BombControl; | ||
import com.almasb.bomberman.control.PlayerControl; | ||
import com.almasb.fxgl.entity.Entities; | ||
import com.almasb.fxgl.entity.GameEntity; | ||
import com.almasb.fxgl.entity.component.CollidableComponent; | ||
import com.almasb.fxgl.parser.EntityFactory; | ||
import com.almasb.fxgl.parser.EntityProducer; | ||
import javafx.scene.paint.Color; | ||
import javafx.scene.shape.Rectangle; | ||
|
||
/** | ||
* @author Almas Baimagambetov (almaslvl@gmail.com) | ||
*/ | ||
public class BombermanFactory extends EntityFactory { | ||
|
||
public BombermanFactory() { | ||
super('0'); | ||
} | ||
|
||
@EntityProducer('w') | ||
public GameEntity newWall(int x, int y) { | ||
return Entities.builder() | ||
.type(EntityType.WALL) | ||
.at(x * BombermanApp.TILE_SIZE, y * BombermanApp.TILE_SIZE) | ||
.viewFromNodeWithBBox(new Rectangle(BombermanApp.TILE_SIZE, BombermanApp.TILE_SIZE)) | ||
.build(); | ||
} | ||
|
||
public GameEntity newPlayer(int x, int y) { | ||
return Entities.builder() | ||
.type(EntityType.PLAYER) | ||
.at(x * BombermanApp.TILE_SIZE, y * BombermanApp.TILE_SIZE) | ||
.viewFromNodeWithBBox(new Rectangle(BombermanApp.TILE_SIZE, BombermanApp.TILE_SIZE, Color.BLUE)) | ||
.with(new CollidableComponent(true)) | ||
.with(new PlayerControl()) | ||
.build(); | ||
} | ||
|
||
public GameEntity newBomb(int x, int y, double radius) { | ||
return Entities.builder() | ||
.type(EntityType.BOMB) | ||
.at(x * BombermanApp.TILE_SIZE, y * BombermanApp.TILE_SIZE) | ||
.viewFromNodeWithBBox(new Rectangle(BombermanApp.TILE_SIZE, BombermanApp.TILE_SIZE, Color.RED)) | ||
.with(new BombControl(radius)) | ||
.build(); | ||
} | ||
|
||
public GameEntity newPowerup(int x, int y) { | ||
return Entities.builder() | ||
.type(EntityType.POWERUP) | ||
.at(x * BombermanApp.TILE_SIZE, y * BombermanApp.TILE_SIZE) | ||
.viewFromNodeWithBBox(new Rectangle(BombermanApp.TILE_SIZE, BombermanApp.TILE_SIZE, Color.YELLOW)) | ||
.with(new CollidableComponent(true)) | ||
.build(); | ||
} | ||
} |
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,8 @@ | ||
package com.almasb.bomberman; | ||
|
||
/** | ||
* @author Almas Baimagambetov (almaslvl@gmail.com) | ||
*/ | ||
public enum EntityType { | ||
PLAYER, WALL, BOMB, POWERUP | ||
} |
42 changes: 42 additions & 0 deletions
42
Bomberman/src/main/java/com/almasb/bomberman/control/BombControl.java
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,42 @@ | ||
package com.almasb.bomberman.control; | ||
|
||
import com.almasb.bomberman.BombermanApp; | ||
import com.almasb.bomberman.EntityType; | ||
import com.almasb.ents.AbstractControl; | ||
import com.almasb.ents.Entity; | ||
import com.almasb.fxgl.app.FXGL; | ||
import com.almasb.fxgl.entity.Entities; | ||
import com.almasb.fxgl.entity.component.BoundingBoxComponent; | ||
|
||
/** | ||
* @author Almas Baimagambetov (almaslvl@gmail.com) | ||
*/ | ||
public class BombControl extends AbstractControl { | ||
|
||
private double radius; | ||
|
||
public BombControl(double radius) { | ||
this.radius = radius; | ||
} | ||
|
||
@Override | ||
public void onUpdate(Entity entity, double tpf) { | ||
|
||
} | ||
|
||
public void explode() { | ||
BoundingBoxComponent bbox = Entities.getBBox(getEntity()); | ||
|
||
FXGL.getApp() | ||
.getGameWorld() | ||
.getEntitiesInRange(bbox.range(radius, radius)) | ||
.stream() | ||
.filter(e -> Entities.getType(e).isType(EntityType.WALL)) | ||
.forEach(e -> { | ||
FXGL.<BombermanApp>getAppCast().onWallDestroyed(e); | ||
e.removeFromWorld(); | ||
}); | ||
|
||
getEntity().removeFromWorld(); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
Bomberman/src/main/java/com/almasb/bomberman/control/PlayerControl.java
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,72 @@ | ||
package com.almasb.bomberman.control; | ||
|
||
import com.almasb.bomberman.BombermanApp; | ||
import com.almasb.ents.AbstractControl; | ||
import com.almasb.ents.Entity; | ||
import com.almasb.fxgl.app.FXGL; | ||
import com.almasb.fxgl.entity.Entities; | ||
import com.almasb.fxgl.entity.GameEntity; | ||
import com.almasb.fxgl.entity.component.PositionComponent; | ||
import javafx.util.Duration; | ||
|
||
/** | ||
* @author Almas Baimagambetov (almaslvl@gmail.com) | ||
*/ | ||
public class PlayerControl extends AbstractControl { | ||
|
||
private PositionComponent position; | ||
private int maxBombs = 1; | ||
private int bombsPlaced = 0; | ||
|
||
@Override | ||
public void onAdded(Entity entity) { | ||
position = Entities.getPosition(entity); | ||
} | ||
|
||
@Override | ||
public void onUpdate(Entity entity, double tpf) { | ||
|
||
} | ||
|
||
public void increaseMaxBombs() { | ||
maxBombs++; | ||
} | ||
|
||
public void placeBomb() { | ||
if (bombsPlaced == maxBombs) { | ||
return; | ||
} | ||
|
||
bombsPlaced++; | ||
|
||
int x = position.getGridX(BombermanApp.TILE_SIZE); | ||
int y = position.getGridY(BombermanApp.TILE_SIZE); | ||
|
||
GameEntity bomb = FXGL.<BombermanApp>getAppCast() | ||
.getEntityFactory() | ||
.newBomb(x, y, BombermanApp.TILE_SIZE / 2); | ||
|
||
getEntity().getWorld().addEntity(bomb); | ||
|
||
FXGL.getMasterTimer().runOnceAfter(() -> { | ||
bomb.getControlUnsafe(BombControl.class).explode(); | ||
bombsPlaced--; | ||
}, Duration.seconds(2)); | ||
} | ||
|
||
public void moveRight() { | ||
position.translateX(BombermanApp.TILE_SIZE); | ||
} | ||
|
||
public void moveLeft() { | ||
position.translateX(-BombermanApp.TILE_SIZE); | ||
} | ||
|
||
public void moveUp() { | ||
position.translateY(-BombermanApp.TILE_SIZE); | ||
} | ||
|
||
public void moveDown() { | ||
position.translateY(BombermanApp.TILE_SIZE); | ||
} | ||
} |
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,10 @@ | ||
0000000000 | ||
0w000000w0 | ||
00ww000000 | ||
000w000w00 | ||
000w00w000 | ||
000w000000 | ||
000w00w000 | ||
000w000000 | ||
0000000000 | ||
0000000000 |