added physics
This commit is contained in:
parent
4414104edd
commit
d82c3b9959
|
|
@ -1,90 +1 @@
|
|||
[
|
||||
[
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
|
||||
],
|
||||
[
|
||||
1, 2, 2, 2, 2, 2, 2, 0, 2, 2, 3, 2, 4, 0, 2, 2, 2, 2, 2, 4, 2, 4, 2, 2, 2,
|
||||
2, 2, 2, 2, 0, 2, 2, 2, 2, 4, 2, 2, 2, 2, 1
|
||||
],
|
||||
[
|
||||
1, 2, 4, 9, 4, 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 3, 2, 2,
|
||||
4, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 0, 2, 2, 1
|
||||
],
|
||||
[
|
||||
1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 0, 2, 2, 2, 2, 2, 4, 2, 4, 2, 2,
|
||||
4, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 1
|
||||
],
|
||||
[
|
||||
1, 4, 2, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 4, 2, 2, 4,
|
||||
2, 2, 2, 2, 4, 2, 2, 2, 4, 2, 2, 2, 2, 2, 1
|
||||
],
|
||||
[
|
||||
1, 4, 2, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 2, 2, 4, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 4, 2, 2, 2, 2, 2, 2, 4, 2, 4, 0, 2, 1
|
||||
],
|
||||
[
|
||||
1, 2, 2, 2, 4, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 4, 2, 0,
|
||||
4, 2, 2, 2, 2, 2,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+ 1);
|
||||
GameState.sceneManager.GetCurrentScene()?.Update(context);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
class Diamond : Rock
|
||||
class Diamond : Tile
|
||||
{
|
||||
private TileSet tileSet;
|
||||
private double i;
|
||||
private int tileX;
|
||||
|
||||
public Diamond(TileSet tileSet, int srcX, int srcY) : base(tileSet, srcX, srcY)
|
||||
|
|
@ -11,9 +10,23 @@ class Diamond : Rock
|
|||
|
||||
public override void Update(Context context, Map map, int x, int y)
|
||||
{
|
||||
++i;
|
||||
i = i % 512;
|
||||
tileX = (int)(i * (8.0 / 512.0));
|
||||
if (map.GetTile(x, y + 1) is (int)TileType.AIR)
|
||||
{
|
||||
map.SetTile(x, y, 0);
|
||||
map.SetTile(x, y + 1, (int)TileType.DIAMOND_FALLING);
|
||||
}
|
||||
if (map.GetTile(x, y + 1) is (int)TileType.ROCK && map.GetTile(x + 1, y) is (int)TileType.AIR && map.GetTile(x + 1, y + 1) is (int)TileType.AIR)
|
||||
{
|
||||
map.SetTile(x, y, 0);
|
||||
map.SetTile(x + 1, y, (int)TileType.DIAMOND_FALLING);
|
||||
}
|
||||
if (map.GetTile(x, y + 1) is (int)TileType.ROCK && map.GetTile(x - 1, y) is (int)TileType.AIR && map.GetTile(x - 1, y + 1) is (int)TileType.AIR)
|
||||
{
|
||||
map.SetTile(x, y, 0);
|
||||
map.SetTile(x - 1, y, (int)TileType.DIAMOND_FALLING);
|
||||
}
|
||||
var i = GameState.tick % 32;
|
||||
tileX = (int)(i * (8.0 / 32.0));
|
||||
}
|
||||
|
||||
public override void Draw(Context context, int x, int y)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
class DiamondFalling : Tile
|
||||
{
|
||||
private TileSet tileSet;
|
||||
private int tileX;
|
||||
|
||||
public DiamondFalling(TileSet tileSet, int srcX, int srcY) : base(tileSet, srcX, srcY)
|
||||
{
|
||||
this.tileSet = tileSet;
|
||||
}
|
||||
|
||||
public override void Update(Context context, Map map, int x, int y)
|
||||
{
|
||||
if (GameState.tick % 16 == 0)
|
||||
if (map.GetTile(x, y + 1) is (int)TileType.AIR)
|
||||
{
|
||||
map.SetTile(x, y, 0);
|
||||
map.SetTile(x, y + 1, (int)TileType.DIAMOND_FALLING);
|
||||
}
|
||||
else if (map.GetTile(x, y + 1) is (int)TileType.PLAYER)
|
||||
{
|
||||
y += 1;
|
||||
map.SetTile(x + 1, y, (int)TileType.EXPLOSION);
|
||||
map.SetTile(x, y, (int)TileType.EXPLOSION);
|
||||
map.SetTile(x - 1, y, (int)TileType.EXPLOSION);
|
||||
map.SetTile(x + 1, y + 1, (int)TileType.EXPLOSION);
|
||||
map.SetTile(x, y + 1, (int)TileType.EXPLOSION);
|
||||
map.SetTile(x - 1, y + 1, (int)TileType.EXPLOSION);
|
||||
map.SetTile(x + 1, y - 1, (int)TileType.EXPLOSION);
|
||||
map.SetTile(x, y - 1, (int)TileType.EXPLOSION);
|
||||
map.SetTile(x - 1, y - 1, (int)TileType.EXPLOSION);
|
||||
}
|
||||
else
|
||||
{
|
||||
map.SetTile(x, y, (int)TileType.DIAMOND);
|
||||
}
|
||||
var i = GameState.tick % 32;
|
||||
tileX = (int)(i * (8.0 / 32.0));
|
||||
}
|
||||
|
||||
public override void Draw(Context context, int x, int y)
|
||||
{
|
||||
context.renderer.DrawTileSet(tileSet, x, y, tileX, 10);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
class Explosion : Tile
|
||||
{
|
||||
private int i = 32 * 9;
|
||||
public Explosion(TileSet tileSet, int srcX, int srcY) : base(tileSet, srcX, srcY)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Update(Context context, Map map, int x, int y)
|
||||
{
|
||||
i--;
|
||||
if (i <= 0)
|
||||
{
|
||||
map.SetTile(x, y, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,4 +3,23 @@ class Rock : Tile
|
|||
public Rock(TileSet tileSet, int srcX, int srcY) : base(tileSet, srcX, srcY)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Update(Context context, Map map, int x, int y)
|
||||
{
|
||||
if (map.GetTile(x, y + 1) is (int)TileType.AIR)
|
||||
{
|
||||
map.SetTile(x, y, 0);
|
||||
map.SetTile(x, y + 1, (int)TileType.ROCK_FALLING);
|
||||
}
|
||||
if (map.GetTile(x, y + 1) is (int)TileType.ROCK && map.GetTile(x + 1, y) is (int)TileType.AIR && map.GetTile(x + 1, y + 1) is (int)TileType.AIR)
|
||||
{
|
||||
map.SetTile(x, y, 0);
|
||||
map.SetTile(x + 1, y, (int)TileType.ROCK_FALLING);
|
||||
}
|
||||
if (map.GetTile(x, y + 1) is (int)TileType.ROCK && map.GetTile(x - 1, y) is (int)TileType.AIR && map.GetTile(x - 1, y + 1) is (int)TileType.AIR)
|
||||
{
|
||||
map.SetTile(x, y, 0);
|
||||
map.SetTile(x - 1, y, (int)TileType.ROCK_FALLING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
class RockFalling : Tile
|
||||
{
|
||||
public RockFalling(TileSet tileSet, int srcX, int srcY) : base(tileSet, srcX, srcY)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Update(Context context, Map map, int x, int y)
|
||||
{
|
||||
if (GameState.tick % 16 == 0)
|
||||
if (map.GetTile(x, y + 1) is (int)TileType.AIR)
|
||||
{
|
||||
map.SetTile(x, y, 0);
|
||||
map.SetTile(x, y + 1, (int)TileType.ROCK_FALLING);
|
||||
}
|
||||
else if (map.GetTile(x, y + 1) is (int)TileType.PLAYER)
|
||||
{
|
||||
y += 1;
|
||||
map.SetTile(x + 1, y, (int)TileType.EXPLOSION);
|
||||
map.SetTile(x, y, (int)TileType.EXPLOSION);
|
||||
map.SetTile(x - 1, y, (int)TileType.EXPLOSION);
|
||||
map.SetTile(x + 1, y + 1, (int)TileType.EXPLOSION);
|
||||
map.SetTile(x, y + 1, (int)TileType.EXPLOSION);
|
||||
map.SetTile(x - 1, y + 1, (int)TileType.EXPLOSION);
|
||||
map.SetTile(x + 1, y - 1, (int)TileType.EXPLOSION);
|
||||
map.SetTile(x, y - 1, (int)TileType.EXPLOSION);
|
||||
map.SetTile(x - 1, y - 1, (int)TileType.EXPLOSION);
|
||||
}
|
||||
else
|
||||
{
|
||||
map.SetTile(x, y, (int)TileType.ROCK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,9 @@ enum TileType : int
|
|||
DIAMOND = 3,
|
||||
ROCK = 4,
|
||||
WALL = 5,
|
||||
ROCK_FALLING = 6,
|
||||
DIAMOND_FALLING = 7,
|
||||
EXPLOSION = 8,
|
||||
PLAYER = 9
|
||||
}
|
||||
|
||||
|
|
@ -25,8 +28,11 @@ class Level : Scene
|
|||
tiles.Add((int)TileType.BORDER, new Tile(tileSet, 1, 6));
|
||||
tiles.Add((int)TileType.DIAMOND, new Diamond(tileSet, 0, 10));
|
||||
tiles.Add((int)TileType.ROCK, new Rock(tileSet, 0, 7));
|
||||
tiles.Add((int)TileType.ROCK_FALLING, new RockFalling(tileSet, 0, 7));
|
||||
tiles.Add((int)TileType.DIAMOND_FALLING, new DiamondFalling(tileSet, 0, 10));
|
||||
tiles.Add((int)TileType.WALL, new Tile(tileSet, 3, 6));
|
||||
tiles.Add((int)TileType.PLAYER, new Player(tileSet, 0, 0));
|
||||
tiles.Add((int)TileType.EXPLOSION, new Explosion(tileSet, 2, 0));
|
||||
this.map = new Map(levelJson, tiles);
|
||||
this.map.Dump();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ class MainMenu : Scene
|
|||
public override void Create(Context context)
|
||||
{
|
||||
context.fontManager.RegisterFont("MainMenu", "assets.font.ttf", 24);
|
||||
context.fontManager.RegisterFont("MainMenuSmall", "assets.font.ttf", 16);
|
||||
}
|
||||
|
||||
public override void Update(Context context)
|
||||
|
|
@ -29,8 +30,11 @@ class MainMenu : Scene
|
|||
{
|
||||
var windowSize = context.window.GetSize();
|
||||
var font = context.fontManager.GetFont("MainMenu");
|
||||
var fontSmall = context.fontManager.GetFont("MainMenuSmall");
|
||||
context.renderer.SetFont(font, new Color(255, 255, 255));
|
||||
context.renderer.DrawText("Main Menu", windowSize.width / 2, windowSize.height / 2, true);
|
||||
context.renderer.DrawText("Boulder Dash", windowSize.width / 2, windowSize.height / 2, true);
|
||||
context.renderer.SetFont(fontSmall, new Color(255, 255, 255));
|
||||
context.renderer.DrawText("Press Space to Start!", windowSize.width / 2, windowSize.height / 2 + 30, true);
|
||||
context.renderer.SetColor(255, 255, 255);
|
||||
context.renderer.DrawRect(x, 0, 30, 30);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue