public Game(int seed, Form window, Options options) { this.window = window; this.world = new World(seed, @"saves/save.csf"); this.view = new View(window, this.world.GetPlayer()); this.ui = new UI(this.world.GetPlayer()); this.running = false; this.options = options; }
public void Draw(Graphics g, World world) { Reset(); DrawLine(g, "X: " + this.player.X + ", Y: " + this.player.Y); DrawLine(g, "S: " + world.Seed + ", L: " + Chunk.GetLocalSeed(world.Seed) + ", B: " + Chunk.GetBiomeSeed(world.Seed) + ", C: " + Chunk.GetContinentSeed(world.Seed)); Biome C = Biome.GetContinentFromNoise(Chunk.GetContinentNoise(this.player.X, this.player.Y, Chunk.GetContinentSeed(world.Seed))); Biome B = C.GetBiomeFromNoise(Chunk.GetBiomeNoise(this.player.X, this.player.Y, Chunk.GetBiomeSeed(world.Seed))); DrawLine(g, "C: " + C.Name + ", B: " + B.Name); float CN = Chunk.GetContinentNoise(this.player.X, this.player.Y, Chunk.GetContinentSeed(world.Seed)); float BN = Chunk.GetBiomeNoise(this.player.X, this.player.Y, Chunk.GetBiomeSeed(world.Seed)); float LN = Chunk.GetLocalNoise(this.player.X, this.player.Y, Chunk.GetLocalSeed(world.Seed)); DrawLine(g, "CN: " + CN + ", BN: " + BN + ", LN: " + LN); }
public void Tick(World world, float delta) { if ((this.unload += delta) > 1) { this.unload = 0; foreach (Chunk chunk in this.chunks) { if (this.GetChunk(chunk.X - 1, chunk.Y - 1) != null && this.GetChunk(chunk.X, chunk.Y - 1) != null && this.GetChunk(chunk.X + 1, chunk.Y - 1) != null && this.GetChunk(chunk.X - 1, chunk.Y) != null && this.GetChunk(chunk.X + 1, chunk.Y) != null && this.GetChunk(chunk.X - 1, chunk.Y + 1) != null && this.GetChunk(chunk.X, chunk.Y + 1) != null && this.GetChunk(chunk.X + 1, chunk.Y + 1) != null) { if (!this.active.Contains(chunk)) { this.active.Add(chunk); } } else if (this.active.Contains(chunk)) { this.active.Remove(chunk); } } } foreach (Chunk chunk in this.active) { chunk.Tick(world, delta); } foreach (Chunk chunk in this.active) { chunk.CheckEntityPosition(world); } }
public virtual void Tick(World world, int x, int y) { }
public virtual void Draw(Graphics g, View view, World world, int x, int y, int up, int down, int left, int right) { g.DrawImage(ImageManager.GetImage(this.image), x * Tile.size - view.GetX(), y * Tile.size - view.GetY(), 32, 32); }
public virtual void Create(World world, int x, int y) { }
public void Tick(World world, float delta) { foreach (Entity entity in this.entities) { entity.Tick(world, delta); } }
public override void Tick(World world, float delta) { if (this.action == Actions.None) { this.progress = 0; if (this.nextAction != Actions.None) { this.action = this.nextAction; this.nextAction = Actions.None; } } switch (this.action) { case (Actions.Move): if (this.progress == 0) { this.SetDirection(); } Tile a = Tile.GetTile(world.GetTile(this.x, this.y)); int dx = this.x; int dy = this.y; if (this.direction <= 1 || this.direction >= 7) { dy--; } if (this.direction >= 3 && this.direction <= 5) { dy++; } if (this.direction >= 1 && this.direction <= 3) { dx++; } if (this.direction >= 5 && this.direction <= 7) { dx--; } Tile b = Tile.GetTile(world.GetTile(dx, dy)); float friction; if (this.progress >= 0.5) { friction = a.GetFriction(); } else { friction = b.GetFriction(); } double distance = 0.5; if (dx != this.x && dy != this.y) { distance = Math.Sqrt(2) / 2; } this.progress += (float) ((double) this.speed / distance * Math.Sin(friction) * (double) delta); if (this.progress >= 1) { this.x = dx; this.y = dy; this.action = this.nextAction; this.nextAction = Actions.None; if (this.action == Actions.Move) { this.progress--; this.SetDirection(); } else { this.progress = 0; } } break; } base.Tick(world, delta); }
public void Draw(Graphics g, View view, World world, float delta) { Chunk cUp = world.GetChunk(this.x, this.y - 1); Chunk cDown = world.GetChunk(this.x, this.y + 1); Chunk cLeft = world.GetChunk(this.x - 1, this.y); Chunk cRight = world.GetChunk(this.x + 1, this.y); int X = this.x * Chunk.size; int Y = this.y * Chunk.size; for (int y = 0; y < Chunk.size; y++) { for (int x = 0; x < Chunk.size; x++) { int up = (y > 0 ? this.tiles[this.ToIndex(x, y - 1)] : (cUp == null ? 0 : cUp.GetTile(x, y - 1))); int down = (y < Chunk.size - 1 ? this.tiles[this.ToIndex(x, y + 1)] : (cDown == null ? 0 : cDown.GetTile(x, y + 1))); int left = (x > 0 ? this.tiles[this.ToIndex(x - 1, y)] : (cLeft == null ? 0 : cLeft.GetTile(x - 1, y))); int right = (x < Chunk.size - 1 ? this.tiles[this.ToIndex(x + 1, y)] : (cRight == null ? 0 : cRight.GetTile(x + 1, y))); Tile.GetTile(this.tiles[this.ToIndex(x, y)]).Draw(g, view, world, X + x, Y + y, up, down, left, right); } } }
public void CheckEntityPosition(World world) { List<Entity> remove = new List<Entity>(); foreach (Entity entity in this.entities) { int x = (int)Math.Floor((double)entity.X / (double)Chunk.size); int y = (int)Math.Floor((double)entity.Y / (double)Chunk.size); if (this.x != x || this.y != y) { Chunk chunk = world.GetChunk(x, y); if (chunk != null) { remove.Add(entity); chunk.AddEntity(entity); } } } foreach (Entity entity in remove) { this.entities.Remove(entity); } }
public virtual void Draw(Graphics g, View view, World world, float delta, int offX, int offY) { this.Draw(g, view, world, delta, image, offX, offY); }
public virtual void Draw(Graphics g, View view, World world, float delta) { this.Draw(g, view, world, delta, image); }
protected virtual void Draw(Graphics g, View view, World world, float delta, int image, int offsetX, int offsetY) { g.DrawImage(ImageManager.GetImage(image), this.x * Tile.size - view.GetX() + offsetX, this.y * Tile.size - Tile.size / 4 - view.GetY() + offsetY); }
public virtual void Tick(World world, float delta) { }
public void DrawEntities(Graphics g, View view, World world, float delta) { List<Entity>[] entities = new List<Entity>[size]; for (int y = 0; y < size; y++) { entities[y] = new List<Entity>(5); } foreach (Entity entity in this.entities) { entities[(entity.Y % Chunk.size + Chunk.size) % Chunk.size].Add(entity); } for (int y = 0; y < size; y++) { foreach (Entity entity in entities[y]) { entity.Draw(g, view, world, delta); } } }
public virtual void Use(World world, Unit source) { }
protected override void Draw(Graphics g, View view, World world, float delta, int image) { g.DrawImage(ImageManager.GetImage(image), this.GetVisualX() - view.GetX(), this.GetVisualY() - Tile.size / 4 - view.GetY()); }