public override void Process(Entity entity) { Entity player = (Entity)BlackBoard.GetEntry("Player"); CollisionBox playerBox = player.GetComponent<CollisionBox>(); Position playerPosition = player.GetComponent<Position>(); Rectangle playerRectangle = new Rectangle( (int)playerPosition.X + playerBox.OffsetX, (int)playerPosition.Y + playerBox.OffsetY, playerBox.Width, playerBox.Height); CollisionBox enemyBox = entity.GetComponent<CollisionBox>(); Position enemyPosition = entity.GetComponent<Position>(); Rectangle enemyRectangle = new Rectangle( (int)enemyPosition.X + enemyBox.OffsetX, (int)enemyPosition.Y + enemyBox.OffsetY, enemyBox.Width, enemyBox.Height); var type = playerRectangle.GetCollisionType(enemyRectangle); if (type == CollisionType.None || !entity.HasComponent<Script>()) return; Script script = entity.GetComponent<Script>(); _scriptManager.QueueScript(script.FilePath, entity, "OnTouch"); }
public override void Process(Entity entity) { Position position = entity.GetComponent<Position>(); Velocity velocity = entity.GetComponent<Velocity>(); position.X += velocity.X; position.Y += velocity.Y; }
public override void OnAdded(Entity e) { ColoredText ColoredText = e.GetComponent<ColoredText>(); Transform spatial = e.GetComponent<Transform>(); spatial.Width = (int)_font.MeasureString(ColoredText.Text).X; spatial.Height = (int)_font.MeasureString(ColoredText.Text).Y; spatial.Center = new Point((int)spatial.Position.X, (int)spatial.Position.Y); }
public override void Process(Entity entity) { Position position = entity.GetComponent<Position>(); Velocity velocity = entity.GetComponent<Velocity>(); velocity.Y += WorldConstants.Gravity; if (velocity.Y > WorldConstants.Gravity) velocity.Y = WorldConstants.Gravity; }
/// <summary>The process.</summary> /// <param name="entity">The entity.</param> public override void Process(Entity entity) { TestHealthComponent testHealth = entity.GetComponent<TestHealthComponent>(); if (testHealth != null) { testHealth.AddDamage(10); } TestPowerComponent testPower = entity.GetComponent<TestPowerComponent>(); if (testPower != null) { testPower.Power -= 10; } }
public override void Process(Entity entity) { Renderable renderable = entity.GetComponent<Renderable>(); Sprite sprite = entity.GetComponent<Sprite>(); Position position = entity.GetComponent<Position>(); Animation animation = sprite.Animations[sprite.CurrentAnimationName]; Frame frame = animation.Frames[animation.CurrentFrameID]; // Determine next frame to use. sprite.FrameActiveTime += _world.DeltaSeconds(); if (sprite.FrameActiveTime > frame.Length) { if (animation.CurrentFrameID == animation.Frames.Count - 1 && !string.IsNullOrEmpty(animation.NextAnimation)) { sprite.SetCurrentAnimation(animation.NextAnimation); animation = sprite.Animations[sprite.CurrentAnimationName]; frame = animation.Frames[animation.CurrentFrameID]; } else { frame.HasRunOnce = true; animation.CurrentFrameID++; sprite.FrameActiveTime = 0; frame = animation.Frames[animation.CurrentFrameID]; } } while (frame.OnlyRunOnce && frame.HasRunOnce) { animation.CurrentFrameID++; frame = animation.Frames[animation.CurrentFrameID]; } int offsetX = frame.OffsetX; int offsetY = frame.OffsetY; if (position.Facing == Direction.Left) { offsetX = -offsetX; } // Update renderable renderable.Source = new Rectangle(frame.X, frame.Y, frame.Width, frame.Height); renderable.Texture = sprite.Texture; renderable.Position = new Vector2(position.X + offsetX, position.Y + offsetY); renderable.Facing = position.Facing; renderable.ColorOverride = sprite.ColorOverride; }
public override void Process(Entity entity) { CollisionBox box = entity.GetComponent<CollisionBox>(); Position position = entity.GetComponent<Position>(); if (box.IsVisible) { Rectangle bounds = new Rectangle( (int)position.X + box.OffsetX, (int)position.Y + box.OffsetY, box.Width, box.Height ); _spriteBatch.DrawRectangle(bounds, box.Color); } }
public static void SetColorPaletteCustom(Entity entity, int red, int green, int blue, int alpha) { if (entity.HasComponent<Sprite>()) { entity.GetComponent<Sprite>().SetColorOverride(red, green, blue, alpha); } }
public static void ResetColorPalette(Entity entity) { if (entity.HasComponent<Sprite>()) { entity.GetComponent<Sprite>().RemoveColorOverride(); } }
public override void Process(Entity entity) { if (!entity.HasComponent<Heartbeat>()) return; Heartbeat hb = entity.GetComponent<Heartbeat>(); if (hb.Interval <= 0.0f) return; hb.CurrentTimer += _world.DeltaSeconds(); if (!(hb.CurrentTimer >= hb.Interval)) return; if (entity.HasComponent<Script>()) { Script script = entity.GetComponent<Script>(); _scriptManager.QueueScript(script.FilePath, entity, "OnHeartbeat"); } hb.CurrentTimer = 0.0f; }
public override void Process(Entity entity) { Map map = entity.GetComponent<Map>(); Vector2 origin = new Vector2(0, 0); for (int x = 0; x < map.Width; x++) { for (int y = 0; y < map.Height; y++) { TileData tile = map.Tiles[x, y]; if (tile == null) continue; Vector2 position = new Vector2( x * TilesetConstants.TileWidth, y * TilesetConstants.TileHeight); Rectangle source = new Rectangle( tile.X, tile.Y, tile.X * TilesetConstants.TileWidth + TilesetConstants.TileWidth, tile.Y * TilesetConstants.TileHeight + TilesetConstants.TileHeight); _spriteBatch.Draw(map.Spritesheet, // Texture position, // Position source, // Source Color.White, // Color 0.0f, // Rotation origin, // Origin 1.0f, // Scale SpriteEffects.None, // SpriteEffects 0.0f); // Layer Depth } } }
public static void SetColorPalette(Entity entity, ColorType color) { if (entity.HasComponent<Sprite>()) { ColorTypeAttribute attr = color.GetAttributeOfType<ColorTypeAttribute>(); entity.GetComponent<Sprite>().SetColorOverride(attr.Red, attr.Green, attr.Blue, attr.Alpha); } }
/// <summary>The build entity.</summary> /// <param name="entity">The entity.</param> /// <param name="entityWorld">The entity world.</param> /// <param name="args">The args.</param> /// <returns>The built <see cref="Entity" />.</returns> public Entity BuildEntity(Entity entity, EntityWorld entityWorld, params object[] args) { entity.AddComponent(new TestPowerComponent()); entity.GetComponent<TestPowerComponent>().Power = 100; entity.Refresh(); return entity; }
public override void Process(Entity e) { Expires expires = e.GetComponent<Expires>(); expires.LifeTime -= EntityWorld.Delta / 10000000.0; if (expires.LifeTime <= 0) { e.Delete(); } }
public override void OnRemoved(Entity e) { Effect effect = e.GetComponent<Effect>(); BattleStats stats = effect.Owner.GetComponent<BattleStats>(); if (stats != null) { stats.RemoveEffect(effect.Type, effect.Amount); } }
public override void Process(Entity e) { bool isHero = e.GetComponent<Group>().IsHero; Transform spatial = e.GetComponent<Transform>(); Animation animation = e.GetComponent<Animation>(); Acting acting = e.GetComponent<Acting>(); animation.Timer += EntityWorld.Delta / 10000000.0; if (animation.Timer >= animation.MovementTime && !animation.IsActing && animation.IsAdvancing) { foreach (Entity target in acting.Targets) { _entityCreator.GenerateParticle(target, acting.SkillSelected.Name); } animation.IsActing = true; } else if (animation.Timer >= animation.MovementTime + animation.ActionTime && animation.IsActing) { BattleEngine.UseSkill(e, acting.SkillSelected, acting.Targets); animation.IsActing = false; animation.IsAdvancing = false; } else if (animation.Timer >= 2 * animation.MovementTime + animation.ActionTime && !animation.IsActing) { spatial.X = animation.InitialPosition.X; acting.ResetSelection(); return; } if (animation.IsActing) { return; } double movement = animation.SpriteSpeed * EntityWorld.Delta / 10000000; if (!animation.IsAdvancing) { movement = -movement; } if (!isHero) { movement = -movement; } spatial.X += (float)movement; }
public void CreateCounterInfo(Entity target) { Entity entity = _world.CreateEntity(); Point position = target.GetComponent<Transform>().Center; position.Y -= 20; entity.AddComponent(new Transform(position)); entity.AddComponent(new Moving(new Vector2(0, -75))); entity.AddComponent(new ColoredText("Contré", Color.Yellow)); entity.AddComponent(new Expires(1)); entity.Refresh(); }
public override void Process(Entity e) { Acting acting = e.GetComponent<Acting>(); if (acting.State == ActingState.SkillSelection) { bool isHero = e.GetComponent<Group>().IsHero; _fighterManager.Refresh(); IEnumerable<SkillData> skills = e.GetComponent<BattleStats>().Skills; IEnumerable<Entity> targets = _fighterManager.GetFighters(!isHero, false); List<SkillData> attackSkills = new List<SkillData>(); foreach (SkillData skill in skills) { if (skill.IsAttack && skill.IsDamaging) { attackSkills.Add(skill); } } int i = RNG.GetInt(0, attackSkills.Count() - 1); acting.SkillSelected = attackSkills.ElementAt(i); if (acting.SkillSelected.CanTargetGroup && RNG.GetDouble() < 0.5) { acting.Targets.AddRange(targets); } else { if (targets.Count() == 0) { return; } int j = RNG.GetInt(0, targets.Count() - 1); acting.Targets.Add(targets.ElementAt(j)); } acting.State = ActingState.SkillSelected; return; } }
public override void Process(Entity e) { Effect effect = e.GetComponent<Effect>(); BattleStats stats = effect.Owner.GetComponent<BattleStats>(); Acting acting = effect.Owner.GetComponent<Acting>(); if (stats != null && acting != null) { if (acting.State == ActingState.Cooldown) { effect.RemainingDuration -= stats.Speed * EntityWorld.Delta / 10000000; } if (stats.IsDead || effect.RemainingDuration < 0) { e.Delete(); } } }
public override void Process(Entity entity) { Renderable renderable = entity.GetComponent<Renderable>(); SpriteEffects flip = SpriteEffects.None; Vector2 origin = new Vector2((int)(renderable.Source.Width / 2), (int)(renderable.Source.Height / 2)); if (renderable.Facing == Direction.Left) { flip = SpriteEffects.FlipHorizontally; } _spriteBatch.Draw(renderable.Texture, // Texture renderable.Position, // Position renderable.Source, // Source renderable.ColorOverride ?? Color.White, // Color 0.0f, // Rotation origin, // Origin 1.0f, // Scale flip, // SpriteEffects 0.0f); // Layer Depth }
public void CreateDamageInfo(Entity target, int damage, double hitSuccess) { Entity entity = _world.CreateEntity(); string text; Color color; if (hitSuccess == 0) { text = "Raté"; color = Color.Gray; } else { if (hitSuccess == 2) { color = Color.Red; } else if (hitSuccess == 1) { color = Color.White; } else { color = Color.Gray; } if (damage == 0) { text = "Bloqué"; } else { text = damage.ToString(); } } entity.AddComponent(new Transform(target.GetComponent<Transform>().Center)); entity.AddComponent(new Moving(new Vector2(0, -75))); entity.AddComponent(new ColoredText(text, color)); entity.AddComponent(new Expires(1)); entity.Refresh(); }
/// <summary> /// Processes the specified entity. /// </summary> /// <param name="entity">The entity.</param> public override void Process(Artemis.Entity entity) { entity.GetComponent <TestHealthComponent>().AddDamage(10); TestTimeWaster.Delay(1000); }
public override void OnAdded(Entity e) { string name = e.GetComponent<Group>().Name; string[] s = name.Split(' '); name = s[0]; int imageSize = 1; if (name.Contains("Boss")) { imageSize += 1; if (name.Contains("Boss7")) { imageSize += 1; } } if (name.Contains("Challenge")) { imageSize += 2; } Transform spatial = e.GetComponent<Transform>(); bool isHero = e.GetComponent<Group>().IsHero; spatial.IsFlippedHorizontally = !isHero; spatial.Dimension = _window.ToAbsolutePoint(imageSize * SpriteDimension); if (isHero) { if (_heroCount < 3) { spatial.Center = _window.ToAbsolutePoint(new Vector2(0.06f + 0.02f * _heroCount, 0.28f + 0.16f * _heroCount)); } else if (_heroCount < 6) { spatial.Center = _window.ToAbsolutePoint(new Vector2(0.16f + 0.02f * (_heroCount - 3), 0.35f + 0.16f * (_heroCount - 3))); } else { spatial.Center = _window.ToAbsolutePoint(new Vector2(0.26f + 0.02f * (_heroCount - 6), 0.28f + 0.16f * (_heroCount - 6))); } _heroCount += 1; } else { if (imageSize == 2) { spatial.Center = _window.ToAbsolutePoint(new Vector2(0.90f, 0.36f)); _foeCount += 1; } else if (imageSize == 3) { spatial.Center = _window.ToAbsolutePoint(new Vector2(0.87f, 0.4f)); } else { if (_foeCount < 4) { spatial.Center = _window.ToAbsolutePoint(new Vector2(0.94f - 0.02f * _foeCount, 0.28f + 0.16f * _foeCount)); } else if (_foeCount < 7) { spatial.Center = _window.ToAbsolutePoint(new Vector2(0.82f - 0.02f * (_foeCount - 4), 0.35f + 0.16f * (_foeCount - 4))); } else { spatial.Center = _window.ToAbsolutePoint(new Vector2(0.70f - 0.02f * (_foeCount - 7), 0.28f + 0.16f * (_foeCount - 7))); } } _foeCount += 1; } }
/// <summary>The process.</summary> /// <param name="entity">The entity.</param> public override void Process(Entity entity) { entity.GetComponent<TestHealthComponent>().AddDamage(10); TestTimeWaster.Delay(); }
/// <summary>Processes the specified entity.</summary> /// <param name="entity">The entity.</param> public override void Process(Entity entity) { HealthComponent healthComponent = entity.GetComponent<HealthComponent>(); Vector2 textPosition = new Vector2(20, this.spriteBatch.GraphicsDevice.Viewport.Height); this.spriteBatch.DrawString(this.font, "Health: " + healthComponent.HealthPercentage + "%", textPosition, Color.White); }
/// <summary>The collision exists.</summary> /// <param name="entity1">The entity 1.</param> /// <param name="entity2">The entity 2.</param> /// <returns>The <see cref="bool" />.</returns> private bool CollisionExists(Entity entity1, Entity entity2) { var p1 = entity1.GetComponent<PositionComp>(); var p2 = entity2.GetComponent<PositionComp>(); var s1 = entity1.GetComponent<SphereShapeComp>(); var s2 = entity2.GetComponent<SphereShapeComp>(); float dist = Vector2.Distance(p1.Position, p2.Position); return (dist <= (s1.Radius + s2.Radius)); }
public override void Process(Entity entity) { Velocity velocity = entity.GetComponent<Velocity>(); PlayerAction action = entity.GetComponent<PlayerAction>(); Sprite sprite = entity.GetComponent<Sprite>(); Position position = entity.GetComponent<Position>(); if (_inputManager.IsUp(GameButton.Dash) && action.IsDashing) { action.IsDashing = false; action.CurrentDashLength = 0.0f; if(sprite.CurrentAnimationName != "Idle") sprite.SetCurrentAnimation("DashEnd"); velocity.X = 0.0f; } if (_inputManager.IsDown(GameButton.Dash) && action.CurrentDashLength < action.MaxDashLength) { sprite.SetCurrentAnimation("Dash"); action.IsDashing = true; if (position.Facing == Direction.Right) velocity.X = 2.5f; else velocity.X = -2.5f; if (action.IsDashing) { action.CurrentDashLength += _world.DeltaSeconds(); } } if (action.IsDashing && action.CurrentDashLength >= action.MaxDashLength && sprite.CurrentAnimationName == "Dash") { sprite.SetCurrentAnimation("DashEnd"); velocity.X = 0.0f; } if (action.IsDashing && action.CurrentDashLength < action.MaxDashLength) return; if (_inputManager.IsDown(GameButton.MoveRight)) { sprite.SetCurrentAnimation("Move"); velocity.X = 1.5f; position.Facing = Direction.Right; } else if (_inputManager.IsDown(GameButton.MoveLeft)) { sprite.SetCurrentAnimation("Move"); velocity.X = -1.5f; position.Facing = Direction.Left; } else if(sprite.CurrentAnimationName != "DashEnd") { sprite.SetCurrentAnimation("Idle"); velocity.X = 0; } }
public Body LookupBody(Entity entity) { var comp = entity.GetComponent<Physics2dComponent>(); if (comp == null) { return null; } return comp.Body; }
/// <summary>The process.</summary> /// <param name="entity">The entity.</param> public override void Process(Entity entity) { entity.GetComponent<TestHealthComponent>().AddDamage(10); }
public override void Process(Entity e) { _spriteBatch.Draw(_whiteTexture, e.GetComponent<Transform>().BoundingBox, e.GetComponent<Particle>().Color); }
public override void OnAdded(Entity e) { e.GetComponent<Animation>().InitialPosition = e.GetComponent<Transform>().Position; }