public HandgunBullet(AbstractScene scene, Vector2 position, Vector2 direction, float speedMultiplier = 2) : base(scene.LayerManager.EntityLayer, null, position) { Vector2 movement = direction - position; if (movement != Vector2.Zero) { movement.Normalize(); } Velocity = movement * speedMultiplier; CollisionOffsetBottom = 1; CollisionOffsetLeft = 0; CollisionOffsetRight = 0; CollisionOffsetTop = 0; AddCollisionAgainst("Enemy"); AddCollisionAgainst("Door"); HorizontalFriction = 0f; VerticalFriction = 0f; HasGravity = false; AddComponent(new Sprite(this, Assets.GetTexture("HandgunBulletPoint"), new Rectangle(0, 0, 2, 1), drawOffset)); AddComponent(new BoxCollisionComponent(this, 2, 2, drawOffset)); //DEBUG_SHOW_COLLIDER = true; //DEBUG_SHOW_PIVOT = true; }
public Lava(AbstractScene scene, int width, int height, Vector2 position) : base(scene.LayerManager.LavaLayer, null, position) { AddCollisionAgainst("Hero"); int spriteSize = 32; TileGroup tg = new TileGroup(32); Texture2D tileSet = Assets.GetTexture("Lava"); Color[] data = new Color[spriteSize * spriteSize]; tileSet.GetData(0, new Rectangle(0, 0, spriteSize, spriteSize), data, 0, data.Length); for (int i = 0; i < width; i += spriteSize) { for (int j = 0; j < height; j += spriteSize) { tg.AddColorData(data, new Vector2(i, j)); } } AddComponent(new Sprite(this, tg.GetTexture(), new Rectangle(0, 0, width, height))); HorizontalFriction = 0; VerticalFriction = 0; VelocityY = 0.005f; HasGravity = false; CheckGridCollisions = false; Visible = true; Active = true; AddComponent(new BoxCollisionComponent(this, width, height)); //DEBUG_SHOW_COLLIDER = true; }
public Ammo(AbstractScene scene, Vector2 position, int amount, Type weaponType) : base(scene, position) { DrawPriority = 8; Amount = amount; WeaponType = weaponType; if (WeaponType.Equals(typeof(Machinegun))) { AddComponent(new Sprite(this, Assets.GetTexture("MachineGunAmmo"))); } else if (WeaponType.Equals(typeof(Handgun))) { AddComponent(new Sprite(this, Assets.GetTexture("HandgunAmmo"))); } else if (WeaponType.Equals(typeof(Shotgun))) { AddComponent(new Sprite(this, Assets.GetTexture("ShotgunAmmo"))); } AddComponent(new BoxCollisionComponent(this, Config.GRID, Config.GRID)); #if DEBUG //(GetCollisionComponent() as AbstractCollisionComponent).DEBUG_DISPLAY_COLLISION = true; //DEBUG_SHOW_PIVOT = true; #endif }
static void DrawLoadingStatus(AbstractScene scene) { VisibleProgressRate = clamp(close(VisibleProgressRate, scene.LoadingProgress, 0.02f), 0, scene.LoadingProgress); var device = GraphicsDeviceContext.Instance; var device2d = Graphics2D.Instance; var proj = new Matrix4x4().Orthogonal(DisplayAspect * 2, 2, 0, 1); device.SetBlendState(Addition); device.SetDepthStencilState(ZTestOff); device.SetRasterizerState(CullingOff); device2d.SetColor(ColorCode.White); device2d.SetMatrix(new Matrix4x3().Identity().Translate(0.5f, -0.75f).Scale(0.06f) * proj); device2d.DrawText("Now Loading" + "...".Substring(0, (frame / 30) % 3), TextAlignment.Left, TextAlignment.Center); device2d.SetColor(ColorCode.Gray); device2d.SetMatrix(new Matrix4x3().Identity().Translate(0.5f, -0.75f).Translate(0, -0.05f).Scale(0.5f, 0.02f, 1) * proj); device2d.SetVertexPositions(0, 0.5f, 1, -0.5f); device2d.DrawRectangleWithDynamical(); device2d.SetColor(ColorCode.White); device2d.SetMatrix(new Matrix4x3().Identity().Translate(0.5f, -0.75f).Translate(0, -0.05f).Scale(0.5f, 0.02f, 1) * proj); device2d.SetVertexPositions(0, 0.5f, VisibleProgressRate, -0.5f); device2d.DrawRectangleWithDynamical(); device2d.SetMatrix(new Matrix4x3().Identity().Translate(1.05f, -0.75f).Translate(0, -0.05f).Scale(0.04f) * proj); device2d.DrawText(VisibleProgressRate.ToString("P0"), TextAlignment.Left, TextAlignment.Center); }
public Saw(AbstractScene scene, Vector2 position, bool horizontal) : base(scene.LayerManager.EntityLayer, null, position) { AddTag("Trap"); this.horizontal = horizontal; HorizontalFriction = 0; VerticalFriction = 0; DrawPriority = 22; if (horizontal) { Movement = new Vector2(0.1f, 0); offset = new Vector2(0, 8); } else { Movement = new Vector2(0, 0.1f); offset = new Vector2(8, 0); } Velocity = Movement; HasGravity = false; CheckGridCollisions = false; sprite = new Sprite(this, Assets.GetTexture("Saw"), drawOffset: offset, origin: new Vector2(8, 8)); AddComponent(sprite); CanFireTriggers = true; AddComponent(new CircleCollisionComponent(this, 8, offset)); //DEBUG_SHOW_COLLIDER = true; //DEBUG_SHOW_PIVOT = true; }
public TextPopup(AbstractScene scene, Texture2D texture, Vector2 position, float scale = 1, float timeout = 0) : base(scene.LayerManager.TutorialLayer, null, position) { input = new UserInputController(); if (timeout == 0) { Scene.LayerManager.PauseForUserInput(); Timer.TriggerAfter(1000, () => { input.RegisterKeyPressAction(Keys.Space, (thumbstickPos) => { Scene.LayerManager.Continue(); Destroy(); }); }); } else { Timer.TriggerAfter(timeout, () => { Destroy(); }); } Sprite s = new Sprite(this, texture, new Rectangle(0, 0, texture.Width, texture.Height)); s.Scale = scale; AddComponent(s); Active = true; Visible = true; }
public TutorialTrigger(AbstractScene scene, Vector2 position, int width, int height, string tutorialName) : base(scene.LayerManager.EntityLayer, null, position) { AddComponent(new BoxTrigger(this, width, height, Vector2.Zero, tag: "")); this.tutorialName = tutorialName; //DEBUG_SHOW_COLLIDER = true; Active = true; }
public MountedGun(AbstractScene scene, Vector2 position, Direction direction, int triggerWidth, int triggerHeight, int triggerXoffset, int triggerYoffset) : base(scene, position, direction) { AddTag("Enemy"); Static = true; sprite = new Sprite(this, Assets.GetTexture("MountedGun")); DamageEffect = true; sprite.Origin = new Vector2(4, 8); if (direction == Direction.WEST) { sprite.BaseRotation = MathUtil.DegreesToRad(180); } else if (direction == Direction.SOUTH) { sprite.BaseRotation = MathUtil.DegreesToRad(90); } AddComponent(sprite); AddComponent(new BoxTrigger(this, triggerWidth, triggerHeight, new Vector2(triggerXoffset, triggerYoffset), tag: "")); AddComponent(new BoxCollisionComponent(this, 16, 16, new Vector2(-8, -8))); #if DEBUG //DEBUG_SHOW_COLLIDER = true; (GetComponent <ITrigger>() as BoxTrigger).DEBUG_DISPLAY_TRIGGER = true; #endif HasGravity = false; //(GetComponent<ITrigger>() as BoxTrigger).DEBUG_DISPLAY_TRIGGER = true; }
public Handgun(AbstractScene scene, Hero hero) : base(scene, hero) { LeftFacingOffset = new Vector2(-3, -17); RightFacingOffset = new Vector2(3, -17); if (hero.CurrentFaceDirection == Direction.EAST) { Transform.Position = RightFacingOffset; } else { Transform.Position = LeftFacingOffset; } ClipSize = 7; AmmoInClip = ClipSize; AllAmmo = 0; Animations.Offset = Offset; SpriteSheetAnimation animLeft = new SpriteSheetAnimation(this, Assets.GetTexture("Gun"), 40); animLeft.StartFrame = 1; animLeft.EndFrame = 2; SpriteSheetAnimation animRight = animLeft.CopyFlipped(); animLeft = animLeft.CopyFlipped(); animLeft.FlipVertical(); Animations.RegisterAnimation("GunLeft", animLeft, () => CurrentFaceDirection == Direction.WEST); Animations.RegisterAnimation("GunRight", animRight, () => CurrentFaceDirection == Direction.EAST); //AddComponent(Texture); //DEBUG_SHOW_PIVOT = true; }
public Machinegun(AbstractScene scene, Hero hero) : base(scene, hero) { Animations = new AnimationStateMachine(); RemoveComponent <AnimationStateMachine>(); AddComponent(Animations); AllAmmo = 0; //LeftFacingOffset = new Vector2(50, 0); //RightFacingOffset = new Vector2(-50, 0); if (hero.CurrentFaceDirection == Direction.EAST) { Transform.Position = RightFacingOffset; } else { Transform.Position = LeftFacingOffset; } /*SpriteSheetAnimation machineGunLeft = new SpriteSheetAnimation(this, Assets.GetTexture("Machinegun"), 1); * Animations.RegisterAnimation("MachineGunLeft", machineGunLeft, () => CurrentFaceDirection == Direction.WEST); * * SpriteSheetAnimation machineGunRight = machineGunLeft.CopyFlipped(); * machineGunLeft.FlipVertical(); * Animations.RegisterAnimation("MachineGunRight", machineGunRight, () => CurrentFaceDirection == Direction.EAST);*/ SpriteSheetAnimation animLeft = new SpriteSheetAnimation(this, Assets.GetTexture("Machinegun"), 32, 32, 1); SpriteSheetAnimation animRight = animLeft.CopyFlipped(); animLeft = animLeft.CopyFlipped(); animLeft.FlipVertical(); Animations.RegisterAnimation("MachineGunLeft", animLeft, () => CurrentFaceDirection == Direction.WEST); Animations.RegisterAnimation("MachineGunRight", animRight, () => CurrentFaceDirection == Direction.EAST); }
public Circle(AbstractScene scene, Entity parent, Vector2 center, int radius, Color color) : base(scene.LayerManager.EntityLayer, parent, center) { SetSprite(AssetUtil.CreateCircle(radius, color)); this.color = color; this.center = center; this.radius = radius; this.offset = new Vector2(radius, radius) / 2; }
internal Layer(AbstractScene scene, int priority = 0, bool ySorting = false, float scrollSpeedModifier = 1f, bool lockY = true) { this.scrollSpeedModifier = scrollSpeedModifier; Priority = priority; this.lockY = lockY; this.ySorting = ySorting; Scene = scene; }
public AbstractEnemy(AbstractScene scene, Vector2 position, Direction direction) : base(scene.LayerManager.EntityLayer, null, position) { AddTag("Enemy"); CanFireTriggers = true; CurrentFaceDirection = direction; DrawPriority = 5; }
public TrapTrigger(AbstractScene scene, Vector2 position, int width, int height) : base(scene.LayerManager.EntityLayer, null, position) { Active = true; AddComponent(new BoxTrigger(this, width, height, Vector2.Zero, tag: "")); //(GetComponent<ITrigger>() as BoxTrigger).DEBUG_DISPLAY_TRIGGER = true; //DEBUG_SHOW_PIVOT = true; }
public EnemyPatrolTrigger(AbstractScene scene, int width, int height, Vector2 position) : base(scene.LayerManager.EntityLayer, null, position) { AddComponent(new BoxTrigger(this, width, height, Vector2.Zero, tag: "")); Visible = true; Active = true; //DEBUG_SHOW_COLLIDER = true; this.width = width; }
public StaticCollider(AbstractScene scene, Vector2 gridPosition) : base(null) { Transform = new StaticTransform(this) { GridCoordinates = gridPosition }; this.scene = scene; scene.GridCollisionChecker.Add(this); }
public void SetNextScene(AbstractScene scene, object argument = null) { if (this.Running) { throw new RuntimeException(); } this.Scene = scene; this.thread = new Thread(new ParameterizedThreadStart(run)); this.argument = argument; }
public Line(AbstractScene scene, Entity parent, Vector2 from, Vector2 to, Color color, float thickness = 1f) : base(scene.LayerManager.EntityLayer, parent, from) { this.From = fromSaved = from; this.To = toSaved = to; this.thickness = thickness; this.color = color; SetSprite(AssetUtil.CreateRectangle(1, Color.White)); length = Vector2.Distance(from, to); angleRad = MathUtil.RadFromVectors(from, to); Origin = new Vector2(0f, 0f); Scale = new Vector2(length, thickness); }
public Line(AbstractScene scene, Entity parent, Vector2 from, float angleRad, float length, Color color, float thickness = 1f) : base(scene.LayerManager.EntityLayer, parent, from) { this.From = fromSaved = from; this.thickness = thickness; this.color = color; SetSprite(AssetUtil.CreateRectangle(1, Color.White)); this.length = length; this.angleRad = angleRad; To = toSaved = MathUtil.EndPointOfLine(from, length, this.angleRad); Origin = new Vector2(0f, 0f); Scale = new Vector2(length, thickness); }
public HealthPickup(AbstractScene scene, Vector2 position) : base(scene, position) { DrawPriority = 7; AddComponent(new Sprite(this, Assets.GetTexture("UIHealth"), new Rectangle(0, 0, 32, 32), offset)); AddComponent(new BoxCollisionComponent(this, 32, 32, offset)); #if DEBUG //(GetCollisionComponent() as AbstractCollisionComponent).DEBUG_DISPLAY_COLLISION = true; //DEBUG_SHOW_COLLIDER = true; #endif }
public EnemyTest(AbstractScene scene, Vector2 position, Direction direction) : base(scene, position, direction) { AddCollisionAgainst("Spikes"); CurrentFaceDirection = Direction.EAST; AnimationStateMachine animations = new AnimationStateMachine(); animations.Offset = offset; AddComponent(animations); SpriteSheetAnimation runLeft = new SpriteSheetAnimation(this, Assets.GetTexture("EnemyRun"), 32, 32, 40); animations.RegisterAnimation("RunLeft", runLeft, () => Velocity.X != 0 && CurrentFaceDirection == Direction.WEST); SpriteSheetAnimation runRight = runLeft.CopyFlipped(); animations.RegisterAnimation("RunRight", runRight, () => Velocity.X != 0 && CurrentFaceDirection == Direction.EAST); animations.AddFrameTransition("RunLeft", "RunRight"); SpriteSheetAnimation idleLeft = new SpriteSheetAnimation(this, Assets.GetTexture("EnemyIdle"), 32, 32, 1); animations.RegisterAnimation("IdleLeft", idleLeft, () => Velocity.X == 0 && CurrentFaceDirection == Direction.WEST); SpriteSheetAnimation idleRight = idleLeft.CopyFlipped(); animations.RegisterAnimation("IdleRight", idleRight, () => Velocity.X == 0 && CurrentFaceDirection == Direction.EAST); SpriteSheetAnimation jumpLeft = new SpriteSheetAnimation(this, Assets.GetTexture("EnemyRun"), 1); jumpLeft.StartFrame = 6; jumpLeft.EndFrame = 7; animations.RegisterAnimation("JumpLeft", jumpLeft, () => !IsOnGround && CurrentFaceDirection == Direction.WEST, 1); SpriteSheetAnimation jumpRight = jumpLeft.CopyFlipped(); animations.RegisterAnimation("JumpRight", jumpRight, () => !IsOnGround && CurrentFaceDirection == Direction.EAST, 1); CollisionOffsetBottom = 1; //AddComponent(new BoxCollisionComponent(this, 18, 30, new Vector2(-8, -30))); if (!Tutorial) { AddComponent(new BoxCollisionComponent(this, 18, 30, new Vector2(-8, -30))); } else { AddComponent(new BoxCollisionComponent(this, 22, 30, new Vector2(-8, -30))); } //DEBUG_SHOW_COLLIDER = true; }
public FuelCan(AbstractScene scene, Vector2 position, float amount) : base(scene, position) { DrawPriority = 8; Amount = amount; AddComponent(new Sprite(this, Assets.GetTexture("FuelCan"))); AddComponent(new BoxCollisionComponent(this, Config.GRID, Config.GRID)); #if DEBUG //(GetCollisionComponent() as AbstractCollisionComponent).DEBUG_DISPLAY_COLLISION = true; //DEBUG_SHOW_PIVOT = true; #endif }
public BulletShell(AbstractScene scene, Vector2 position, float destoryTime = 2000, Vector2 force = default) : base(scene.LayerManager.EntityLayer, null, position) { DrawPriority = 20; AddComponent(new Sprite(this, Assets.GetTexture("HandgunBulletShell"), new Rectangle(0, 0, 2, 1), new Vector2(0, -1))); Velocity = force; CollisionOffsetBottom = 1; HorizontalFriction = 0.9f; VerticalFriction = 0.9f; //Bump(new Vector2(0, -1f)); Timer.TriggerAfter(destoryTime, Destroy); }
public AbstractWeapon(AbstractScene scene, Hero owner) : base(scene.LayerManager.EntityLayer, owner, Vector2.Zero) { hero = owner; CurrentFaceDirection = hero.CurrentFaceDirection; Animations = new AnimationStateMachine(); AddComponent(Animations); if (hero.CurrentFaceDirection == Direction.EAST) { Transform.Position = RightFacingOffset; } else { Transform.Position = LeftFacingOffset; } }
public DoorKey(AbstractScene scene, Vector2 position) : base(scene.LayerManager.EntityLayer, null, position) { AddTag("Key"); AddComponent(new Sprite(this, Assets.GetTexture("Keycard"))); AddComponent(new BoxCollisionComponent(this, Config.GRID, Config.GRID)); CollisionsEnabled = false; Timer.TriggerAfter(500, () => { CollisionsEnabled = true; }); //DEBUG_SHOW_COLLIDER = true; }
public Door(AbstractScene scene, Vector2 position, int height, bool locked) : base(scene.LayerManager.EntityLayer, null, position) { AddTag("Door"); CheckGridCollisions = false; HasGravity = false; /*TileGroup tg = new TileGroup(); * Texture2D tileSet = AssetUtil.CreateRectangle(Config.GRID, Color.Bisque); * Color[] data = new Color[Config.GRID * Config.GRID]; * HasGravity = false; * * for (int i = 0; i < height; i += Config.GRID) * { * if (i == 0) * { * tileSet.GetData(0, new Rectangle(0, 0, Config.GRID, Config.GRID), data, 0, data.Length); * } * else if (i == height - Config.GRID) * { * data = new Color[Config.GRID * Config.GRID]; * tileSet.GetData(0, new Rectangle(0, 0, Config.GRID, Config.GRID), data, 0, data.Length); * } * else * { * data = new Color[Config.GRID * Config.GRID]; * tileSet.GetData(0, new Rectangle(0, 0, Config.GRID, Config.GRID), data, 0, data.Length); * } * for (int j = 0; j < Config.GRID; j += Config.GRID) * { * tg.AddColorData(data, new Vector2(i, j)); * } * } * Sprite sprite = new Sprite(this, tg.GetTexture(), new Rectangle(0, 0, Config.GRID, height)); * AddComponent(sprite);*/ closedSprite = new Sprite(this, Assets.GetTexture("Door"), new Rectangle(0, 0, Config.GRID, 112)); openSprite = new Sprite(this, Assets.GetTexture("Door"), new Rectangle(Config.GRID, 0, Config.GRID, 112)); AddComponent(closedSprite); AddComponent(new BoxCollisionComponent(this, Config.GRID, height)); //DEBUG_SHOW_COLLIDER = true; }
public void LoadEntities(AbstractScene scene, string levelID) { foreach (EntityInstance entity in world.ParseLevel(scene, levelID)) { Vector2 position = new Vector2(entity.Px[0], entity.Px[1]); if (entity.Identifier.Equals("Hero")) { hero = new Hero(scene, position); } else if (entity.Identifier.Equals("Lava")) { new Lava(scene, (int)entity.Width, (int)entity.Height, position); } else if (entity.Identifier.Equals("Spikes")) { Direction dir = default; foreach (FieldInstance field in entity.FieldInstances) { if (field.Identifier == "Direction") { dir = Enum.Parse(typeof(Direction), field.Value); } } float size = entity.Width > entity.Height ? entity.Width : entity.Height; new Spikes(scene, position, (int)size, dir); } else if (entity.Identifier.Equals("Fuel")) { float amount = 0; bool gravity = true; foreach (FieldInstance field in entity.FieldInstances) { if (field.Identifier == "Amount") { amount = (float)field.Value; } else if (field.Identifier == "HasGravity") { gravity = field.Value; } } FuelCan can = new FuelCan(scene, position, amount); can.HasGravity = gravity; } else if (entity.Identifier.Equals("EnemyPatrolTrigger")) { new EnemyPatrolTrigger(scene, (int)entity.Width, (int)entity.Height, position); } else if (entity.Identifier.Equals("Enemy")) { Direction dir = Direction.WEST; bool patrol = true; bool tutorial = false; Newtonsoft.Json.Linq.JArray array = null; foreach (FieldInstance field in entity.FieldInstances) { if (field.Identifier == "Direction") { dir = Enum.Parse(typeof(Direction), field.Value); } else if (field.Identifier == "Patrol") { patrol = field.Value; } else if (field.Identifier == "Tutorial") { tutorial = field.Value; } else if (field.Identifier == "CarriedItems") { array = field.Value; } } List <string> carriedItems = array.ToObject <List <string> >(); EnemyTest enemy = new EnemyTest(scene, position, dir); enemy.Patrol = patrol; enemy.Tutorial = tutorial; if (carriedItems != null && carriedItems.Count > 0) { enemy.CarriedItems = carriedItems; } } else if (entity.Identifier.Equals("Door")) { bool locked = false; foreach (FieldInstance field in entity.FieldInstances) { if (field.Identifier == "Locked") { locked = field.Value; } } new Door(scene, position, (int)entity.Height, locked); } else if (entity.Identifier.Equals("MountedGun")) { Direction dir = default; Newtonsoft.Json.Linq.JArray array = null; foreach (FieldInstance field in entity.FieldInstances) { if (field.Identifier == "Direction") { dir = Enum.Parse(typeof(Direction), field.Value); } else if (field.Identifier == "Integer") { array = field.Value; } } List <int> param = array.ToObject <List <int> >(); new MountedGun(scene, position, dir, param[0], param[1], param[2], param[3]); } else if (entity.Identifier.Equals("Saw")) { bool horizontal = false; foreach (FieldInstance field in entity.FieldInstances) { if (field.Identifier == "Horizontal") { horizontal = field.Value; } } new Saw(scene, position, horizontal); } else if (entity.Identifier.Equals("TrapTrigger")) { new TrapTrigger(scene, position, (int)entity.Width, (int)entity.Height); } else if (entity.Identifier.Equals("TutorialTrigger")) { string tutorial = ""; foreach (FieldInstance field in entity.FieldInstances) { if (field.Identifier == "Tutorial") { tutorial = field.Value; } } new TutorialTrigger(scene, position, (int)entity.Width, (int)entity.Height, tutorial); } else if (entity.Identifier.Equals("Ammo")) { Type weaponType = null; int amount = 0; foreach (FieldInstance field in entity.FieldInstances) { if (field.Identifier == "Weapon") { if (field.Value == "Handgun") { weaponType = typeof(Handgun); } else if (field.Value == "Machinegun") { weaponType = typeof(Machinegun); } else if (field.Value == "Shotgun") { weaponType = typeof(Shotgun); } } else if (field.Identifier == "Amount") { amount = (int)field.Value; } } new Ammo(scene, position, amount, weaponType); } else if (entity.Identifier.Equals("HealthPickup")) { new HealthPickup(scene, position); } else if (entity.Identifier.Equals("EndGameTrigger")) { new EndGameTrigger(scene, position, (int)entity.Width, (int)entity.Height); } } }
public AbstractItem(AbstractScene scene, Vector2 position) : base(scene.LayerManager.EntityLayer, null, position) { AddCollisionAgainst("Item"); CurrentFaceDirection = Direction.EAST; }
public Hero(AbstractScene scene, Vector2 position) : base(scene.LayerManager.EntityLayer, null, position) { //DEBUG_SHOW_PIVOT = true; AddTag("Hero"); AddCollisionAgainst("Enemy"); AddCollisionAgainst("Spikes"); AddCollisionAgainst("Trap"); CanFireTriggers = true; DrawPriority = 10; AddCollisionAgainst("Pickup"); AddCollisionAgainst("Door", false); AddCollisionAgainst("Key"); AddCollisionAgainst("MountedGunBullet"); SetupController(); CollisionOffsetBottom = 1; CollisionOffsetLeft = 0.5f; CollisionOffsetRight = 0.5f; CollisionOffsetTop = 1; CurrentFaceDirection = Direction.EAST; collisionComponent = new BoxCollisionComponent(this, 18, 30, new Vector2(-8, -30)); AddComponent(collisionComponent); //DEBUG_SHOW_COLLIDER = true; AnimationStateMachine animations = new AnimationStateMachine(); animations.Offset = offset; AddComponent(animations); SpriteSheetAnimation idleLeft = new SpriteSheetAnimation(this, Assets.GetTexture("HeroIdle"), 24); /*idleLeft.AnimationSwitchCallback = () => { if (CurrentWeapon != null) CurrentWeapon.SetAnimationBreathingOffset(Vector2.Zero); }; * idleLeft.EveryFrameAction = (frame) => * { * if (CurrentWeapon == null) return; * float unit = 0.5f; * float offsetY = 0; * if (frame == 2 || frame == 3 || frame == 4) * { * offsetY += unit; * } * else if (frame == 6 || frame == 7) * { * offsetY -= unit; * } * CurrentWeapon.SetAnimationBreathingOffset(new Vector2(0, offsetY)); * };*/ idleLeft.StartedCallback = () => { if (CurrentWeapon == null) { return; } if (CurrentWeapon is Shotgun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17)); } else if (CurrentWeapon is Machinegun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17)); } else if (CurrentWeapon is Handgun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17)); } }; animations.RegisterAnimation("IdleLeft", idleLeft, () => previousPosition == Transform.Position && CurrentFaceDirection == Direction.WEST); SpriteSheetAnimation idleRight = idleLeft.CopyFlipped(); animations.RegisterAnimation("IdleRight", idleRight, () => previousPosition == Transform.Position && CurrentFaceDirection == Direction.EAST); SpriteSheetAnimation runLeft = new SpriteSheetAnimation(this, Assets.GetTexture("HeroRun"), 40); runLeft.StartedCallback = () => { if (CurrentWeapon == null) { return; } if (CurrentWeapon is Shotgun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17)); } else if (CurrentWeapon is Machinegun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17)); } else if (CurrentWeapon is Handgun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(1, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(-1, -17)); } }; animations.RegisterAnimation("RunLeft", runLeft, () => Velocity.X < 0 && CurrentFaceDirection == Direction.WEST); SpriteSheetAnimation runRight = runLeft.CopyFlipped(); animations.RegisterAnimation("RunRight", runRight, () => Velocity.X > 0 && CurrentFaceDirection == Direction.EAST); SpriteSheetAnimation runBackwardsLeft = new SpriteSheetAnimation(this, Assets.GetTexture("HeroRunBackwards"), 40); runBackwardsLeft.StartedCallback = () => { if (CurrentWeapon == null) { return; } if (CurrentWeapon is Shotgun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17)); } else if (CurrentWeapon is Machinegun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17)); } else if (CurrentWeapon is Handgun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(1, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(-1, -17)); } }; animations.RegisterAnimation("RunBackwardsLeft", runBackwardsLeft, () => Velocity.X > 0 && CurrentFaceDirection == Direction.WEST); SpriteSheetAnimation runRighrunBackwardsRight = runBackwardsLeft.CopyFlipped(); animations.RegisterAnimation("RunBackwardsRight", runRighrunBackwardsRight, () => Velocity.X < 0 && CurrentFaceDirection == Direction.EAST); SpriteSheetAnimation jumpLeft = new SpriteSheetAnimation(this, Assets.GetTexture("HeroRun"), 1); jumpLeft.StartFrame = 6; jumpLeft.EndFrame = 7; animations.RegisterAnimation("JumpLeft", jumpLeft, () => !IsOnGround && CurrentFaceDirection == Direction.WEST, 1); SpriteSheetAnimation jumpRight = jumpLeft.CopyFlipped(); animations.RegisterAnimation("JumpRight", jumpRight, () => !IsOnGround && CurrentFaceDirection == Direction.EAST, 1); SpriteSheetAnimation jetpackLeft = new SpriteSheetAnimation(this, Assets.GetTexture("Jetpacking"), 40); animations.RegisterAnimation("JetpackLeft", jetpackLeft, () => flying && CurrentFaceDirection == Direction.WEST, 2); SpriteSheetAnimation jetpackRight = jetpackLeft.CopyFlipped(); animations.RegisterAnimation("JetpackRight", jetpackRight, () => flying && CurrentFaceDirection == Direction.EAST, 2); SpriteSheetAnimation kickLeft = new SpriteSheetAnimation(this, Assets.GetTexture("Kick"), 40); kickLeft.Looping = false; kickLeft.AddFrameAction(5, (frame) => { AudioEngine.Play("Kick"); IsKicking = true; if (THIS_IS_SPARTAAAAA && collidingWith.Count > 0) { THIS_IS_SPARTAAAAA = false; Vector2 canSpawnPos = collidingWith[0].Transform.Position; FuelCan can = new FuelCan(scene, canSpawnPos + new Vector2(0, -20), TankCapacity); can.Velocity += new Vector2(-3, -1); can.CollisionsEnabled = false; Ammo ammo = new Ammo(scene, canSpawnPos + new Vector2(0, -20), 20, typeof(Handgun)); ammo.Velocity += new Vector2(-4f, -1.5f); ammo.CollisionsEnabled = false; Timer.TriggerAfter(2000, () => { can.CollisionsEnabled = true; ammo.CollisionsEnabled = true; new TextPopup(Scene, Assets.GetTexture("FuelAmmoText"), Transform.Position + new Vector2(-20, -80), 0.3f, 3000); }); } }); kickLeft.AddFrameAction(6, (frame) => { IsKicking = false; }); kickLeft.StartedCallback = () => { if (THIS_IS_SPARTAAAAA && collidingWith.Count > 0) { THIS_IS_SPARTA(); Globals.FixedUpdateMultiplier = 0.1f; Timer.TriggerAfter(3000, () => { Globals.FixedUpdateMultiplier = 0.5f; Timer.Repeat(1000, (elapsedTime) => { Scene.Camera.Zoom -= 0.002f * elapsedTime; }); }); } //IsKicking = true; if (IsOnGround) { MovementSpeed = 0; } if (CurrentWeapon == null) { return; } if (CurrentWeapon is Shotgun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17)); } else if (CurrentWeapon is Machinegun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17)); } else if (CurrentWeapon is Handgun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(1, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(-1, -17)); } }; kickLeft.AnimationSwitchCallback = () => { IsKicking = false; MovementSpeed = Config.CHARACTER_SPEED; foreach (AbstractEnemy enemy in collidingWith) { enemy.IsKicked = false; } }; animations.RegisterAnimation("KickLeft", kickLeft, () => false); SpriteSheetAnimation kickRight = kickLeft.CopyFlipped(); animations.RegisterAnimation("KickRight", kickRight, () => false); SpriteSheetAnimation kickJetpackLeft = new SpriteSheetAnimation(this, Assets.GetTexture("KickJetpacking"), 40); kickJetpackLeft.Looping = false; kickJetpackLeft.AddFrameAction(5, (frame) => { AudioEngine.Play("Kick"); IsKicking = true; }); kickJetpackLeft.AddFrameAction(6, (frame) => { IsKicking = false; }); kickJetpackLeft.StartedCallback = () => { //IsKicking = true; if (CurrentWeapon == null) { return; } if (CurrentWeapon is Shotgun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17)); } else if (CurrentWeapon is Machinegun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17)); } else if (CurrentWeapon is Handgun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(1, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(-1, -17)); } }; kickJetpackLeft.AnimationSwitchCallback = () => { IsKicking = false; }; animations.RegisterAnimation("KickJetpackLeft", kickJetpackLeft, () => false); SpriteSheetAnimation kickJetpackRight = kickJetpackLeft.CopyFlipped(); animations.RegisterAnimation("KickJetpackRight", kickJetpackRight, () => false); animations.AddFrameTransition("RunLeft", "RunBackwardsLeft"); animations.AddFrameTransition("RunRight", "RunBackwardsRight"); animations.AddFrameTransition("RunLeft", "RunRight"); animations.AddFrameTransition("RunBackwardsLeft", "RunBackwardsRight"); animations.AddFrameTransition("JetpackLeft", "JetpackRight"); Visible = true; Active = true; /*DebugFunction = () => * { * return "Fuel: " + (int)(((float)(Fuel / TankCapacity)) * 100) + " %"; * };*/ CurrentWeapon = new Handgun(scene, this); weapons.Add(CurrentWeapon); Machinegun mg = new Machinegun(scene, this); mg.Visible = false; Shotgun sg = new Shotgun(scene, this); sg.Visible = false; weapons.Add(mg); weapons.Add(sg); }
public LayerManager(AbstractScene scene) { this.scene = scene; }