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, 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
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ class Diamond : Rock
|
||||||
public override void Update(Context context, Map map, int x, int y)
|
public override void Update(Context context, Map map, int x, int y)
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
i = i % 128;
|
i = i % 512;
|
||||||
tileX = (int)(i * (8.0 / 128.0));
|
tileX = (int)(i * (8.0 / 512.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw(Context context, int x, int y)
|
public override void Draw(Context context, int x, int y)
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,66 @@
|
||||||
|
enum Animation : int
|
||||||
|
{
|
||||||
|
NORMAL = 0,
|
||||||
|
IDLE1 = 1,
|
||||||
|
IDLE2 = 2,
|
||||||
|
IDLE3 = 3,
|
||||||
|
WALK_LEFT = 4,
|
||||||
|
WALK_RIGHT = 5,
|
||||||
|
}
|
||||||
|
|
||||||
class Player : Tile
|
class Player : Tile
|
||||||
{
|
{
|
||||||
private int walkCD = 0;
|
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)
|
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)
|
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)
|
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 (GameState.keyState.isPressed(Control.UP) && walkCD is 0)
|
||||||
{
|
{
|
||||||
if (!map.IsSolid(x, y - 1) || map.IsSemiSolid(x, y - 1))
|
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 - 1, 9);
|
||||||
map.SetTile(x, y, 0);
|
map.SetTile(x, y, 0);
|
||||||
}
|
}
|
||||||
walkCD = TICKS_PAR_TILE;
|
walkCD = TICKS_PER_TILE;
|
||||||
}
|
}
|
||||||
if (GameState.keyState.isPressed(Control.DOWN) && walkCD is 0)
|
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 + 1, 9);
|
||||||
map.SetTile(x, y, 0);
|
map.SetTile(x, y, 0);
|
||||||
}
|
}
|
||||||
walkCD = TICKS_PAR_TILE;
|
walkCD = TICKS_PER_TILE;
|
||||||
}
|
}
|
||||||
if (GameState.keyState.isPressed(Control.LEFT) && walkCD is 0)
|
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 - 1, y, 9);
|
||||||
map.SetTile(x, y, 0);
|
map.SetTile(x, y, 0);
|
||||||
}
|
}
|
||||||
walkCD = TICKS_PAR_TILE;
|
walkCD = TICKS_PER_TILE;
|
||||||
}
|
}
|
||||||
if (GameState.keyState.isPressed(Control.RIGHT) && walkCD is 0)
|
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 + 1, y, 9);
|
||||||
map.SetTile(x, y, 0);
|
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);
|
walkCD = Math.Max(0, walkCD - 1);
|
||||||
base.Update(context, map, x, y);
|
base.Update(context, map, x, y);
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ enum TileType : int
|
||||||
class Level : Scene
|
class Level : Scene
|
||||||
{
|
{
|
||||||
private Map? map;
|
private Map? map;
|
||||||
private int debugSelectedTile = 0;
|
private int debugSelectedTile = 1;
|
||||||
private TileSet? tileSet;
|
private TileSet? tileSet;
|
||||||
private Dictionary<int, Tile>? tiles;
|
private Dictionary<int, Tile>? tiles;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue