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3, 2, 2, 2, 2, 4, 2, 2, 2, + 2, 2, 4, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 1 + ], + [ + 1, 0, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 2, 2, 4, 2, 2, 0, 0, 0, 2, 2, 2, + 4, 2, 2, 2, 2, 2, 2, 4, 2, 4, 0, 2, 2, 1, 1 + ], + [ + 1, 2, 4, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 4, 2, 0, 0, 2, + 2, 2, 2, 3, 2, 2, 2, 4, 2, 4, 4, 2, 2, 2, 1 + ], + [ + 1, 2, 2, 2, 2, 4, 3, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, + 4, 2, 4, 3, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 1 + ], + [ + 1, 2, 2, 2, 0, 2, 2, 0, 2, 4, 2, 2, 4, 2, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 4, 2, 4, 3, 2, 2, 2, 2, 2, 2, 4, 2, 2, 4, 1 + ], + [ + 1, 2, 3, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, + 4, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 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 + ] +] diff --git a/src/actors/Tiles/Diamond.cs b/src/actors/Tiles/Diamond.cs index e593ee8..cc2130f 100644 --- a/src/actors/Tiles/Diamond.cs +++ b/src/actors/Tiles/Diamond.cs @@ -12,8 +12,8 @@ class Diamond : Rock public override void Update(Context context, Map map, int x, int y) { ++i; - i = i % 128; - tileX = (int)(i * (8.0 / 128.0)); + i = i % 512; + tileX = (int)(i * (8.0 / 512.0)); } public override void Draw(Context context, int x, int y) diff --git a/src/actors/Tiles/Player.cs b/src/actors/Tiles/Player.cs index 9ea8976..c1dc570 100644 --- a/src/actors/Tiles/Player.cs +++ b/src/actors/Tiles/Player.cs @@ -1,19 +1,66 @@ +enum Animation : int +{ + NORMAL = 0, + IDLE1 = 1, + IDLE2 = 2, + IDLE3 = 3, + WALK_LEFT = 4, + WALK_RIGHT = 5, +} + class Player : Tile { private int walkCD = 0; - const int TICKS_PAR_TILE = 10; + const int TICKS_PER_TILE = 10; + private double i, j; + private int tileXIdle; + private int tileXWalk; + private bool isMoving = false; + private bool direction = true; + private int idleCD = 512; + private TileSet tileSet; public Player(TileSet tileSet, int srcX, int srcY) : base(tileSet, srcX, srcY) { + this.tileSet = tileSet; } public override void Draw(Context context, int x, int y) { - base.Draw(context, x, y); + var animation = Animation.NORMAL; + var tileX = 0; + if (isMoving) + { + animation = direction ? Animation.WALK_RIGHT : Animation.WALK_LEFT; + tileX = tileXWalk; + } + else + { + if (idleCD < 0) + { + animation = Animation.IDLE1; + tileX = tileXIdle; + } + if (idleCD < -256) + { + animation = Animation.IDLE2; + } + if (idleCD < -512) + { + animation = Animation.IDLE3; + } + } + context.renderer.DrawTileSet(tileSet, x, y, tileX, (int)animation); } public override void Update(Context context, Map map, int x, int y) { + ++i; + i = i % 64; + tileXIdle = (int)(i * (8.0 / 64.0)); + ++j; + j = j % 32; + tileXWalk = (int)(j * (8.0 / 32.0)); if (GameState.keyState.isPressed(Control.UP) && walkCD is 0) { if (!map.IsSolid(x, y - 1) || map.IsSemiSolid(x, y - 1)) @@ -21,7 +68,7 @@ class Player : Tile map.SetTile(x, y - 1, 9); map.SetTile(x, y, 0); } - walkCD = TICKS_PAR_TILE; + walkCD = TICKS_PER_TILE; } if (GameState.keyState.isPressed(Control.DOWN) && walkCD is 0) { @@ -30,7 +77,7 @@ class Player : Tile map.SetTile(x, y + 1, 9); map.SetTile(x, y, 0); } - walkCD = TICKS_PAR_TILE; + walkCD = TICKS_PER_TILE; } if (GameState.keyState.isPressed(Control.LEFT) && walkCD is 0) { @@ -39,7 +86,7 @@ class Player : Tile map.SetTile(x - 1, y, 9); map.SetTile(x, y, 0); } - walkCD = TICKS_PAR_TILE; + walkCD = TICKS_PER_TILE; } if (GameState.keyState.isPressed(Control.RIGHT) && walkCD is 0) { @@ -48,7 +95,21 @@ class Player : Tile map.SetTile(x + 1, y, 9); map.SetTile(x, y, 0); } - walkCD = TICKS_PAR_TILE; + walkCD = TICKS_PER_TILE; + } + if (GameState.keyState.isPressed(Control.LEFT) || GameState.keyState.isPressed(Control.RIGHT)) + { + direction = GameState.keyState.isPressed(Control.RIGHT); + } + if (GameState.keyState.isPressed(Control.LEFT) || GameState.keyState.isPressed(Control.RIGHT) || GameState.keyState.isPressed(Control.UP) || GameState.keyState.isPressed(Control.DOWN)) + { + isMoving = true; + idleCD = 512; + } + else + { + isMoving = false; + idleCD--; } walkCD = Math.Max(0, walkCD - 1); base.Update(context, map, x, y); diff --git a/src/scenes/Level.cs b/src/scenes/Level.cs index 4d18571..b0e2c81 100644 --- a/src/scenes/Level.cs +++ b/src/scenes/Level.cs @@ -12,7 +12,7 @@ enum TileType : int class Level : Scene { private Map? map; - private int debugSelectedTile = 0; + private int debugSelectedTile = 1; private TileSet? tileSet; private Dictionary? tiles;