// TODO: Might need to pass in the owner entity, so that if a potion is used up, the player will get an empty bottle. public void Use(Level level, ChunkLayer layer, int blockX, int blockY) { var isConsumed = false; GetItem().Use(level, layer, blockX, blockY, out isConsumed); if (isConsumed) { StackSize--; } }
public WorldManager(Viewport viewport, Level level) { Level = level; GeneratePlayer(); Camera = GameCore.Camera.CreateOrthographicCamera(viewport); _chunkRenderer = new ChunkRenderer(viewport); }
public GameplayState(GameStateManager manager, Level level) : base(manager) { var viewport = new Viewport(0, 0, manager.GameWindow.Width, manager.GameWindow.Height); _frameCount = 0; _totalGameTime = TimeSpan.Zero; _timer = Stopwatch.StartNew(); _worldManager = new WorldManager(viewport, level); _uiManager = new UIManager(manager.GameWindow, viewport, _worldManager); _tessellator = new VertexBufferTessellator() { Mode = VertexTessellatorMode.Render }; }
// TODO: I can make farmland; now I need something to plant. /// <summary> /// You can only till dirt or grass. /// </summary> public override void Use(Level level, ChunkLayer layer, int blockX, int blockY, out bool isConsumed) { base.Use(level, layer, blockX, blockY, out isConsumed); layer = level.GetHighestVisibleLayer(blockX, blockY); var blockId = level[layer, blockX, blockY]; if ((blockId == _tilledSoil)) { level[layer, blockX, blockY] = _wheatPlant; isConsumed = true; } // TODO: If durability <= 0, isConsumed = true. }
public override void Update(TimeSpan elapsed, Level level, ChunkLayer layer, int blockX, int blockY) { _totalElapsedTime += elapsed; if (_totalElapsedTime.TotalSeconds > 5) { _totalElapsedTime = TimeSpan.Zero; var oldMetadata = level.GetMetadata(layer, blockX, blockY); var newMetadata = oldMetadata + 1; if (newMetadata <= 7) { level.SetMetadata(layer, blockX, blockY, newMetadata); } } }
public override void LoadContent(ContentManager content) { base.LoadContent(content); _ascii = content.Load<TileSet>("TileSets/ASCII.xml"); var progress = new Progress<string>(message => _progressMessages.Push(message)); content.Load<BlockRegistry>("Blocks/SampleBlockRegistry.xml"); ItemRegistry.Instance.Initialize(); _loadingTask = Task.Run(() => { _level = new Level(ChunkType.Overworld); var chunk = _level[ChunkLayer.Floor, 0, 0]; // generate the first chunk }).ContinueWith(x => Thread.Sleep(100)); }
// TODO: When farmland is broken, it should drop a dirt block. public override void Use(Level level, ChunkLayer layer, int blockX, int blockY, out bool isConsumed) { base.Use(level, layer, blockX, blockY, out isConsumed); var blockId = level[layer, blockX, blockY]; if (blockId > 0) { level[layer, blockX, blockY] = 0; var blockEntity = new BlockEntity(blockId); blockEntity.MoveTo(level, new Vector2(blockX, blockY)); level.AddEntity(blockEntity); } // TODO: If durability <= 0, isConsumed = true. isConsumed = false; }
private void Move(Level level) { Move(level, _orientation); }
private void Move(Level level, Direction direction) { // TODO: Modify speed according to the friction value of the current block. // TODO: Move slower if traveling on the background layer. // TODO: Don't allow walking through a position where all layers, including the background, are empty. MoveBy(level, direction, _speed); }
private void MoveBy(Level level, Direction direction, float speed) { var vi = direction.ToVector2I(); MoveBy(level, new Vector2(vi.X * speed, vi.Y * speed)); }
private void MoveBy(Level level, Vector2 delta) { MoveTo(level, _position + delta); }
/// <summary> /// This allows us to either update all of the entities in the level, or only the entities in the given chunk, i.e. the player's chunk. /// This may not be necessary, or it may need to be expanded to the nearest 3 chunks, etc. /// Looking up the player's chunk every frame may slow things down more than just updating every entity. I'm not sure yet. /// </summary> private void UpdateEntities(TimeSpan elapsed, Level level) { var deadEntities = new List<Entity>(); foreach (var entity in Entities) { entity.Update(level, elapsed); if (!entity.IsAlive) { deadEntities.Add(entity); } } foreach (var entity in deadEntities) { level.GetChunk(entity).RemoveEntity(entity); } }
/// <summary> /// Use this item on the selected location. /// </summary> public virtual void Use(Level level, ChunkLayer layer, int blockX, int blockY, out bool isConsumed) { isConsumed = false; }
public virtual void Update(TimeSpan elapsed, Level level, ChunkLayer layer, int blockX, int blockY) { }
public override void Update(Level level, TimeSpan elapsed) { base.Update(level, elapsed); _rotation += Speed; }
public void Update(TimeSpan elapsed, Level level) { _ambientLightLevel = level.AmbientLightLevel; UpdateBlocks(elapsed, level, ChunkLayer.Background); UpdateBlocks(elapsed, level, ChunkLayer.Floor); UpdateEntities(elapsed, level); UpdateBlocks(elapsed, level, ChunkLayer.Blocking); UpdateBlocks(elapsed, level, ChunkLayer.Ceiling); }
public virtual void Update(Level level, TimeSpan elapsed) { if (_isMoving) { Move(level); } }
private void UpdateBlocks(TimeSpan elapsed, Level level, ChunkLayer layer) { for (var blockX = 0; blockX < Width; blockX++) { for (var blockY = 0; blockY < Height; blockY++) { var blockId = _blockIndex[(int)layer, blockY, blockX]; if (blockId != NULL_BLOCK_ID) { BlockRegistry.Instance.GetById(blockId).Update(elapsed, level, layer, blockX, blockY); } } } }
public void MoveTo(Level level, Vector2 newPosition) { var center = new Vector2(newPosition.X + Size / 2.0f, newPosition.Y + Size / 2.0f); var impactEntities = level.GetEntitiesAt(center, new Vector2(Size / 2.0f, Size / 2.0f)); if (impactEntities != null) { foreach (var impactEntity in impactEntities) { if (impactEntity != this) { impactEntity.Touched(this); //_isMoving = false; // TODO: Is it good to continue moving through an entity like this? Should the Speed by modified at all? } } } if (CanMoveTo(level, newPosition)) { var oldChunk = level.GetChunk(this); // (int)(_position.X + Size / 2), (int)(_position.Y + Size / 2)); _position = newPosition; var newChunk = level.GetChunk(this); if (oldChunk != newChunk) { oldChunk.RemoveEntity(this); newChunk.AddEntity(this); } } else { _isMoving = false; } }
/// <summary> /// Is there a block blocking this position? /// </summary> protected bool CanMoveTo(Level level, Vector2 newPosition) { // This looks right, and visually it looks mostly right. var topLeft = new Vector2(newPosition.X, newPosition.Y); var bottomRight = new Vector2(topLeft.X + Size, topLeft.Y + Size); return !level.IsBlockedAt((int)Math.Floor(topLeft.X), (int)Math.Floor(topLeft.Y)) && !level.IsBlockedAt((int)Math.Floor(topLeft.X), (int)Math.Floor(bottomRight.Y)) && !level.IsBlockedAt((int)Math.Floor(bottomRight.X), (int)Math.Floor(bottomRight.Y)) && !level.IsBlockedAt((int)Math.Floor(bottomRight.X), (int)Math.Floor(topLeft.Y)); }
public override void Update(Level level, TimeSpan elapsed) { base.Update(level, elapsed); // Clear out empty item stacks. UpdateItems(Inventory); UpdateItems(Toolbelt); }