public override void draw(GameTime gameTime, AbstractGameState gameState, SpriteBatch spriteBatch) { Entity unit = null; int id = entityIds[2].getLast(); unit = entityManager.getEntity(id); Vector2 location = unit.getComponent<LocationComponent>().getCurrentLocation(); float direction = unit.getComponent<LocationComponent>().getFacingRadians(); Rectangle leftLine = new Rectangle(0, 0, 1, 500); Rectangle rightLine = new Rectangle(0, 0, 1, 500); int heldWeaponId = unit.getComponent<ArsenalComponent>().getCurrentWeaponId(); float weaponAcc = WeaponLibrary.getWeaponFromId(heldWeaponId).getAccuracy(); float leftAngle = - weaponAcc / 2; float rightAngle = weaponAcc / 2; SpriteBatchWrapper.DrawGame(EditorContent.blank, unit.getComponent<LocationComponent>().getCurrentLocation(), leftLine, Color.DarkGray * 0.3f, leftAngle + direction, new Vector2(0.5f), new Vector2(1), SpriteEffects.None, 1); SpriteBatchWrapper.DrawGame(EditorContent.blank, unit.getComponent<LocationComponent>().getCurrentLocation(), rightLine, Color.DarkGray * 0.3f, rightAngle + direction, new Vector2(0.5f), new Vector2(1), SpriteEffects.None, 1); SpriteBatchWrapper.DrawGame(EditorContent.blank, unit.getComponent<LocationComponent>().getCurrentLocation(), rightLine, Color.DarkGray * 0.3f, direction, new Vector2(0.5f), new Vector2(1), SpriteEffects.None, 1); }
public override void draw(GameTime gameTime, AbstractGameState gameState, Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch) { foreach (int id in entityIds[0]) { Entity entity = entityManager.getEntity(id); MovementComponent movement = entity.getComponent<MovementComponent>(); SpriteBatchWrapper.DrawGame(EditorContent.yellowBullet, entity.getComponent<LocationComponent>().getCurrentLocation(), new Rectangle(0, 0, 10, 10), Color.HotPink, GeometryHelper.CalculateAngle(Vector2.Zero, movement.getVelocity()), new Vector2(5f), new Vector2(1), SpriteEffects.None, 1); } }
public override void draw(GameTime gameTime, AbstractGameState gameState, SpriteBatch spriteBatch) { foreach (int id in this.entityIds[0]) { Entity entity = entityManager.getEntity(id); TextureDefinition model = TextureLibrary.getTextureFromId(entity.getComponent<EntityTextureComponent>() .getTextureId()); LocationComponent locationComponent = entity.getComponent<LocationComponent>(); SpriteBatchWrapper.DrawGame(model.getSpriteSheet(), locationComponent.getCurrentLocation(), model.getSourceRectangle(), Color.White, locationComponent.getFacingRadians(), model.getOrigin(), model.getScale(), SpriteEffects.None, 0.8f); } }
public override void draw(GameTime gameTime, AbstractGameState gameState, Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch) { if (entityIds[0].count() != 0) { TrackingComponent tracking = entityManager.getEntity(entityIds[0].getLast()) .getComponent<TrackingComponent>(); MouseState mouseState = Mouse.GetState(); SpriteBatchWrapper.DrawGame(EditorContent.blank, new Rectangle(100, 75, 5, 5), Color.Red); DrawStringHelper.drawStringUI(spriteBatch, gameState.getCamera().translateToUI(new Vector2(100,75)).ToString(), "mentone", 12, Color.White, new Vector2(300, 10)); DrawStringHelper.drawStringUI(spriteBatch, tracking.getTrackingLocation().ToString(), "mentone", 12, Color.White, new Vector2(300, 40)); } }
public override void update(GameTime gameTime, AbstractGameState gameState) { foreach (int entityId in entityIds[0]) { Entity entity = entityManager.getEntity(entityId); StatusDrawComponent statusDrawComponent = entity.getComponent<StatusDrawComponent>(); for (int i = 0; i < statusDrawComponent.getCount(); i++) { statusDrawComponent.getMillisLeft()[i] -= gameTime.ElapsedGameTime.Milliseconds; if (statusDrawComponent.getMillisLeft()[i] <= 0) { statusDrawComponent.removeAt(i); } } } }
public override void draw(GameTime gameTime, AbstractGameState gameState, Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch) { if (entityIds[0].count() == 0) return; int id = entityIds[0].getLast(); Entity entity = entityManager.getEntity(id); MovementTime movementTime = entity.getComponent<MovementTime>(); float fractionLeftToMove = movementTime.getMillisToMove() / (float)movementTime.getFullMillisToMove(); // spriteBatch.End(); // DrawHelper.spriteBatchBeginUI(spriteBatch); SpriteBatchWrapper.DrawUI(EditorContent.blank, new Rectangle(10, 10, 200, 5), Color.DarkGray); SpriteBatchWrapper.DrawUI(EditorContent.blank, new Rectangle(10, 11, (int)(200 * fractionLeftToMove), 2), Color.LightBlue); // spriteBatch.End(); // DrawHelper.spriteBatchBeginGame(spriteBatch); }
public override void draw(GameTime gameTime, AbstractGameState gameState, SpriteBatch spriteBatch) { foreach (int id in entityIds[0]) { Entity entity = entityManager.getEntity(id); Vector2 location = entity.getComponent<LocationComponent>().getCurrentLocation(); if (entity.getComponent<AllegianceComponent>() .getControlId() == GameEntity.turnId) { if (entity.hasComponent<Selected>()) { DrawHelper.drawBetween(location - new Vector2(-5, 5), location - new Vector2(-25, 30), spriteBatch, Color.Orange, 1); StringBuilder sb = new StringBuilder(); sb.Append("Command cost: " + entity.getComponent<Controllable>().getCommandCost()); sb.AppendLine(); if (entity.hasComponent<MovementTime>()) { sb.Append("Time to move: " + entity.getComponent<MovementTime>().getFullMillisToMove()); } DrawStringHelper.drawStringGame(spriteBatch, sb.ToString(), "mentone", 10, Color.Orange, location - new Vector2(-28, 36),0); } else { SpriteBatchWrapper.DrawGame(EditorContent.blank, location, new Rectangle(0, 0, 1, 1), Color.White, (float)Math.PI / 2, new Vector2(0.5f), new Vector2(2), SpriteEffects.None, 1); } } else { /* spriteBatch.Draw(EditorContent.blank, location, new Rectangle(0, 0, 1, 1), Color.Red, (float)Math.PI / 2, new Vector2(0.5f), new Vector2(5), SpriteEffects.None, 1); */ } } // spriteBatch.End(); // DrawHelper.spriteBatchBeginUI(spriteBatch); DrawStringHelper.drawStringUI(spriteBatch, "Command points remaining: " + ((UnitSelectState)gameState).getCommandPoints(), "mentone", 12, Color.Gray, new Vector2(5)); // spriteBatch.End(); // DrawHelper.spriteBatchBeginGame(spriteBatch); }
public override void update(GameTime gameTime, AbstractGameState gameState) { foreach (int e in entityIds[0]) { Entity entity = entityManager.getEntity(e); IsProjectile isProjectile = entity.getComponent<IsProjectile>(); LocationComponent locationComponent = entity.getComponent<LocationComponent>(); Vector2 distance = gameTime.ElapsedGameTime.Milliseconds * entity.getComponent<MovementComponent>().getVelocity() * 0.1f; locationComponent.setCurrentLocation(locationComponent.getCurrentLocation() + distance); isProjectile.addToTravelled(distance.Length()); if (isProjectile.getTravelled() > isProjectile.getMaxRange()) { entityManager.removeEntity(e); } } }
public override void update(GameTime gameTime, AbstractGameState gameState) { if (entityIds[0].count() != 0) { gameState.getCamera().setDesiredZoom(1f); TrackingComponent tracking = entityManager.getEntity(entityIds[0].getLast()) .getComponent<TrackingComponent>(); gameState.getCamera().setDesiredWorldPosition(tracking.getTrackingLocation()); gameState.getCamera().setDesiredTrackingRotation(tracking.getTrackingRotation()); } else { gameState.getCamera().setDesiredZoom(0.75f); gameState.getCamera().setDesiredRotation(0); gameState.getCamera().setDesiredWorldPosition(Vector2.Zero); } }
public override void draw(GameTime gameTime, AbstractGameState gameState, SpriteBatch spriteBatch) { foreach (int entityId in entityIds[0]) { Entity entity = entityManager.getEntity(entityId); StatusDrawComponent statusDrawComponent = entity.getComponent<StatusDrawComponent>(); LocationComponent locationComponent = entity.getComponent<LocationComponent>(); for (int i = 0; i < statusDrawComponent.getCount(); i++) { Tuple<string, Color, long, long> entry = statusDrawComponent.getEntry(i); DrawStringHelper.drawStringGame(spriteBatch, entry.Item1, "mentone", 10, entry.Item2 * MathHelper.SmoothStep(0, 1.5f, (float)statusDrawComponent.getMillisLeft()[i] / statusDrawComponent.millisToDisplays[i]), locationComponent.getCurrentLocation() + GeometryHelper.rotateVec( new Vector2(15, 15 + MathHelper.SmoothStep(35, 0, (float)statusDrawComponent.getMillisLeft()[i]/statusDrawComponent.millisToDisplays[i])), gameState.getCamera().getRotation()), gameState.getCamera().getRotation() + (float) Math.PI); } } }
public override void draw(GameTime gameTime, AbstractGameState gameState, SpriteBatch spriteBatch) { foreach (int id in entityIds[0]) { float area = 0; float centerX = 0; float centerY = 0; List<Vector2> points = entityManager.getEntity(id).getComponent<VertexListComponent>().getPoints(); for (int i = 0; i < points.Count; i++) { Vector2 start = points[i]; Vector2 end; if (i + 1 == points.Count) { end = points[0]; } else { end = points[i + 1]; } float areaToAdd = start.X * end.Y - end.X * start.Y; centerX += (start.X + end.X) * areaToAdd; centerY += (start.Y + end.Y) * areaToAdd; area += areaToAdd; DrawHelper.drawBetween(start, end, spriteBatch, col, 2); } area /= 2; if (area != 0) { centerX /= 6 * area; centerY /= 6 * area; } DrawStringHelper.drawStringGame(spriteBatch, "Map\nitem", "mentone", 10, col, new Vector2(centerX, centerY), 0, VerticalAlignment.CENTERED, HorizontalAlignment.CENTERED); } }
public override void update(GameTime gameTime, AbstractGameState gameState) { IControl control = DefaultControl.Instance; UnitSelectState state = ((UnitSelectState)gameState); List<int> selectableIds = new List<int>(); Entity selected = null; foreach (int id in entityIds[0]) { Entity entity = entityManager.getEntity(id); if (entity.getComponent<AllegianceComponent>() .getControlId() == GameEntity.turnId) { selectableIds.Add(id); } if (entity.hasComponent<Selected>()) { selected = entity; } } if (selected == null) { selected = entityManager.getEntity(selectableIds[0]); selected.addComponent(new Selected()); } int index = selectableIds.IndexOf(selected.getId()); //If the player presses next. if (control.isLRightPressed()) { index = (index + 1) % selectableIds.Count; } //If the player presses back. if (control.isLLeftPressed()) { if (index == 0) index = selectableIds.Count - 1; else index = (index - 1) % selectableIds.Count; } if (selectableIds[index] != selected.getId()) { // Switch selected entity. selected.removeComponent<Selected>(); selected = entityManager.getEntity(selectableIds[index]); selected.addComponent(new Selected()); } //If the player presses action(one). if (control.isActionAPressed()) { selected.addComponent(new TrackingComponent()); int commandCost = selected.getComponent<Controllable>().getCommandCost(); if (state.getCommandPoints() >= commandCost) { state.selectUnit(commandCost); } } if (control.isActionCPressed()) { state.endTurn(); } }
public override void update(GameTime gameTime, AbstractGameState gameState) { IControl control = DefaultControl.Instance; EngageState state = (EngageState)gameState; Entity entity = entityManager.getEntity(entityIds[2].getLast()); LocationComponent locationComponent = entity.getComponent<LocationComponent>(); MovementComponent movementComponent = entity.getComponent<MovementComponent>(); Entity targetted = null; List<int> targettableIds = new List<int>(); //Not firing. if (entityIds[4].count() == 0) { foreach (int id in entityIds[1]) { Entity potentialEnemy = entityManager.getEntity(id); if (potentialEnemy.getComponent<AllegianceComponent>() .getControlId() != GameEntity.turnId) { targettableIds.Add(id); } if (potentialEnemy.hasComponent<IsTarget>()) { targetted = potentialEnemy; } } // Target enemy aiming. if (targettableIds.Count > 0) { if (targetted == null) { targetted = entityManager.getEntity(targettableIds[0]); targetted.addComponent(new IsTarget()); } int index = targettableIds.IndexOf(targetted.getId()); if (control.isRLeftPressed()) { if (index == 0) index = targettableIds.Count - 1; else index = (index - 1) % targettableIds.Count; } else if (control.isRRightPressed()) { index = (index + 1) % targettableIds.Count; } if (targettableIds[index] != targetted.getId()) { targetted.removeComponent<IsTarget>(); targetted = entityManager.getEntity(targettableIds[index]); targetted.addComponent(new IsTarget()); Entity newTarget = entityManager.getEntity(targettableIds[index]); Vector2 newTargetLocation = newTarget.getComponent<LocationComponent>().getCurrentLocation(); locationComponent.setFacingRadians(GeometryHelper.CalculateAngle(newTargetLocation, locationComponent.getCurrentLocation())); } } // Manual control aiming. if (control.isLLeftHeld()) { locationComponent.setFacingRadians(entity.getComponent<LocationComponent>().getFacingRadians() - movementComponent.getTurningSpeed(gameTime)); } else if (control.isLRightHeld()) { locationComponent.setFacingRadians(entity.getComponent<LocationComponent>().getFacingRadians() + movementComponent.getTurningSpeed(gameTime)); } // Change weapon. if (control.isActionEPressed()) { entity.getComponent<ArsenalComponent>().selectNextWeapon(); } else if (control.isActionDPressed()) { entity.getComponent<ArsenalComponent>().selectPreviousWeapon(); } if (control.isActionBPressed()) { int[] entityIdsUnchanged = entityIds[0].ToArray<int>(); foreach (int id2 in entityIdsUnchanged) { entityManager.removeEntity(id2); } entity.removeComponent<IsFiring>(); state.disengage(); } else if (control.isActionAHeld() && !entity.getComponent<Selected>().getHasFired()) // Firing action. { entity.addComponent(new IsFiring()); } } else // firing mini-state. { long time = entity.getComponent<IsFiring>().getTimeSinceFirstShot(); entity.getComponent<IsFiring>().setTimeSinceFirstShot(time + gameTime.ElapsedGameTime.Milliseconds); WeaponStats heldWeapon = WeaponLibrary.getWeaponFromId( entity.getComponent<ArsenalComponent>().getCurrentWeaponId()); int shotsPerTurn = heldWeapon.getShotsPerTurn(); long timeBetweenShots = heldWeapon.getTimeBetweenShots(); int shotsFired = entity.getComponent<IsFiring>().getShotsFired(); if (shotsFired < shotsPerTurn) { if (time > timeBetweenShots * shotsFired) { float unitDirection = locationComponent.getFacingRadians(); Vector2 unitLocation = locationComponent.getCurrentLocation(); float weaponAcc = heldWeapon.getAccuracy(); float maximum = weaponAcc / 2; float minimum = -weaponAcc / 2; float bulletDirection = GeometryHelper.getRandomFloat(minimum, maximum); List<BaseComponent> components = new List<BaseComponent>(); components.Add(new LocationComponent(unitLocation, bulletDirection)); components.Add(new MovementComponent(4, 4 * Vector2.Normalize(GeometryHelper.rotateVec(new Vector2(0, 1), bulletDirection + unitDirection)))); components.Add(new IsProjectile(100, true, 100)); components.Add(new CollisionHitBox(new RectangleShape(new Rectangle((int)unitLocation.X, (int)unitLocation.Y, 10, 10), new Vector2(5f), 0, 10))); entityManager.addEntity(Entity.EntityFactory.createEntityWithComponents(components)); entity.getComponent<IsFiring>().incrementShotsFired(); } } else { if (entityIds[0].count() == 0) { entity.getComponent<Selected>().setHasFired(true); entity.removeComponent<IsFiring>(); ((Observer)gameState).handleFinishedFiring(); } } } }
public override void update(GameTime gameTime, AbstractGameState gameState) { }
protected void changeState(AbstractGameState gameState) { gameStateManager.swapState(this, gameState); }
protected void addStateOnTopOfThis(AbstractGameState gameState) { gameStateManager.addOnTop(this, gameState); }
protected void addStateOnTop(AbstractGameState gameState) { gameStateManager.pushState(gameState); }
public override void update(GameTime gameTime, AbstractGameState gameState) { MovementServiceObserver observer = (MovementServiceObserver)gameState; if (entityIds[0].count() == 0) { observer.endMovement(); return; } IControl control = DefaultControl.Instance; int id = entityIds[0].getLast(); Entity entity = entityManager.getEntity(id); if (entity.hasComponent<LocationComponent>()) { LocationComponent locationComponent = entity.getComponent<LocationComponent>(); MovementComponent movementComponent = entity.getComponent<MovementComponent>(); MovementTime movementTime = entity.getComponent<MovementTime>(); // Need controller input. Vector2 moveInDirection = Vector2.Zero; if (control.isLLeftHeld()) { moveInDirection += new Vector2(1, 0); } if (control.isLRightHeld()) { moveInDirection += new Vector2(-1, 0); } if (control.isLDownHeld()) { moveInDirection += new Vector2(0, -1); } if (control.isLUpHeld()) { moveInDirection += new Vector2(0, 1); } if (moveInDirection != Vector2.Zero) moveInDirection.Normalize(); moveInDirection = moveInDirection * movementComponent.getBaseMovementSpeed(gameTime); if (control.isRLeftHeld()) { locationComponent.setFacingRadians(locationComponent.getFacingRadians() - movementComponent.getTurningSpeed(gameTime)); } if (control.isRRightHeld()) { locationComponent.setFacingRadians(locationComponent.getFacingRadians() + movementComponent.getTurningSpeed(gameTime)); } if (movementTime.getMillisToMove() > 0) { moveInDirection = GeometryHelper.rotateVec(moveInDirection, locationComponent.getFacingRadians()); locationComponent.setCurrentLocation(locationComponent.getCurrentLocation() + moveInDirection); } if (movementTime.getFullMillisToMove() == movementTime.getMillisToMove() && moveInDirection != Vector2.Zero || movementTime.getFullMillisToMove() != movementTime.getMillisToMove()) { movementTime.decrementMillisToMove(gameTime.ElapsedGameTime.Milliseconds); } if (entity.hasComponent<TrackingComponent>()) { entity.getComponent<TrackingComponent>() .setTrackingLocation(locationComponent.getCurrentLocation()) .setTrackingRotation(locationComponent.getFacingRadians()); } if (control.isActionAPressed()) { movementTime.incrementMovedAmount(); entity.removeComponent<TrackingComponent>(); entity.removeComponent<Selected>(); observer.endMovement(); } if (control.isActionBPressed()) { observer.engageUnit(); } } }
public override void update(GameTime gameTime, AbstractGameState gameState) { if (entityIds[0].count() == 0) { ((Observer)gameState).handleEndRetaliation(); } else if (entityIds[3].count() == 0) // Select the most damaged. { int mostDamaged = entityIds[0].ElementAt(0); for (int i = 1; i < entityIds[0].count(); i++) { RetaliateComponent r1 = entityManager.getEntity(mostDamaged).getComponent<RetaliateComponent>(); RetaliateComponent r2 = entityManager.getEntity(entityIds[0].ElementAt(i)).getComponent<RetaliateComponent>(); if (r1.getDamage() < r2.getDamage()) mostDamaged = i; } Entity attacker = entityManager.getEntity(mostDamaged); LocationComponent locationComponent = attacker.getComponent<LocationComponent>(); Entity target = entityManager.getEntity(entityIds[2].getLast()); Vector2 newTargetLocation = target.getComponent<LocationComponent>().getCurrentLocation(); locationComponent.setFacingRadians(GeometryHelper.CalculateAngle(newTargetLocation, locationComponent.getCurrentLocation())); // Most damage now firing. attacker.addComponent(new IsFiring()); } else if (!entityManager.getEntity(entityIds[3].getLast()).getComponent<IsFiring>().getCompleted()) { Entity entity = entityManager.getEntity(entityIds[3].getLast()); LocationComponent locationComponent = entity.getComponent<LocationComponent>(); WeaponStats heldWeapon = WeaponLibrary.getWeaponFromId( entity.getComponent<ArsenalComponent>().getCurrentWeaponId()); int shotsPerTurn = heldWeapon.getShotsPerTurn(); long timeBetweenShots = heldWeapon.getTimeBetweenShots(); int shotsFired = entity.getComponent<IsFiring>().getShotsFired(); long time = entity.getComponent<IsFiring>().getTimeSinceFirstShot(); entity.getComponent<IsFiring>().setTimeSinceFirstShot(time + gameTime.ElapsedGameTime.Milliseconds); if (shotsFired < shotsPerTurn) { if (time > timeBetweenShots * shotsFired) { float unitDirection = locationComponent.getFacingRadians(); Vector2 unitLocation = locationComponent.getCurrentLocation(); float weaponAcc = heldWeapon.getAccuracy(); float maximum = weaponAcc / 2; float minimum = -weaponAcc / 2; float bulletDirection = GeometryHelper.getRandomFloat(minimum, maximum); List<BaseComponent> components = new List<BaseComponent>(); components.Add(new LocationComponent(unitLocation, bulletDirection)); components.Add(new MovementComponent(4, 4 * Vector2.Normalize(GeometryHelper.rotateVec(new Vector2(0, 1), bulletDirection + unitDirection)))); components.Add(new IsProjectile(100, true, 100)); components.Add(new CollisionHitBox(new RectangleShape(new Rectangle((int)unitLocation.X, (int)unitLocation.Y, 10, 10), new Vector2(5f), 0, 10))); entityManager.addEntity(Entity.EntityFactory.createEntityWithComponents(components)); entity.getComponent<IsFiring>().incrementShotsFired(); } } else { if (entityIds[1].count() == 0) { foreach (int id in entityIds[0]) { entityManager.getEntity(id).removeComponent<RetaliateComponent>(); } entity.removeComponent<IsFiring>(); ((Observer)gameState).handleEndRetaliation(); } } } }