Beispiel #1
0
        public Entity CreateStartingPlayer()
        {
            var result = new Entity()
            {
                Health    = 3,
                Rectangle = new Rect(0, 2, 50, 14),
                Team      = Team.Player
            };

            result.AddComponent(new RenderComponent(MainAtlas.GetFrame("fighter0.png")));
            result.AddComponent(new MovementComponent(300d));
            result.AddComponent(new PlayerControls());
            result.AddComponent(new InvulnerableDamageHandler(1.5d));

            // Starting weapon
            result.AddComponent(new WeaponComponent(new WeaponConfig()
            {
                ProjectileCreator = CreateLaser,
                ShootSpeed        = 0.1,
                Damage            = 1,
            })
            {
                FireOffset          = new Distance(32, 9),
                ProjectileDirection = new Distance(1f, 0)
            });

            result.Destroyed += SpawnExplosionOnDeath;

            return(result);
        }
Beispiel #2
0
        public Entity CreateBeamEnemy()
        {
            var result = new Entity()
            {
                Health    = 10,
                Rectangle = new Rect(0, 0, 49, 33),
                Team      = Team.Enemy
            };

            var weapon = new WeaponConfig()
            {
                Damage            = 2,
                ProjectileCreator = CreateBeamShot,
                ShootSpeed        = 4
            };

            result.AddComponent(new RenderComponent(MainAtlas.GetFrame("beamship.png")));
            result.AddComponent(new MovementComponent(40)
            {
                MoveLeft = true
            });
            result.AddComponent(new CollisionDamageComponent(1));
            result.AddComponent(new WeaponComponent(weapon)
            {
                ProjectileDirection = new Distance(-1, 0),
                FireOffset          = new Distance(2, 12),
                TryFire             = true
            });

            result.Destroyed += SpawnExplosionOnDeath;

            return(result);
        }
Beispiel #3
0
        public Entity CreateBomb()
        {
            var result = new Entity()
            {
                Health          = 1,
                Rectangle       = new Rect(0, 0, 43, 9),
                IgnoreCollision = true
            };

            result.AddComponent(GetBurnerAnim(new Distance(0, 2)));
            result.AddComponent(new RenderComponent(MainAtlas.GetFrame("bomb.png")));
            result.AddComponent(new CollisionDamageComponent(0)
            {
                DestroyOnCollide = true
            });
            result.AddComponent(new ProjectileComponent()
            {
                Speed = 20
            });
            result.AddComponent(new AccelerationComponent(450, 1, Ease.Linear));

            result.Destroyed += SpawnMediumExplosionOnDeath;

            return(result);
        }
Beispiel #4
0
        public Entity CreateHovercraft()
        {
            var result = new Entity()
            {
                Health    = 1,
                Rectangle = new Rect(0, 8, 44, 11),
                Team      = Team.Player
            };

            result.AddComponent(new RenderComponent(MainAtlas.GetFrame("hovercraft.png")));
            result.AddComponent(new MovementComponent(250d));
            result.AddComponent(new PlayerControls());
            result.AddComponent(new InvulnerableDamageHandler(1.5d));

            // Starting weapon
            result.AddComponent(new WeaponComponent(new WeaponConfig()
            {
                ProjectileCreator = CreateRoundBullet,
                ShootSpeed        = 0.1,
                Damage            = 1,
            })
            {
                FireOffset          = new Distance(14, 1),
                ProjectileDirection = new Distance(1f, 0),
                PlayerAimed         = true
            });

            result.Destroyed += SpawnExplosionOnDeath;

            return(result);
        }
Beispiel #5
0
        public Entity CreateRocketLauncherEnemy()
        {
            var result = new Entity()
            {
                Health    = 3,
                Rectangle = new Rect(0, 0, 37, 26),
                Team      = Team.Enemy
            };

            var weapon = new WeaponConfig()
            {
                Damage            = 2,
                ProjectileCreator = CreateRocketShot,
                ShootSpeed        = 1
            };

            result.AddComponent(new RenderComponent(MainAtlas.GetFrame("rocketlauncher.png")));
            result.AddComponent(GetJetLongAnim(new Distance(35, 16)));
            result.AddComponent(new MovementComponent(75)
            {
                MoveLeft = true
            });
            result.AddComponent(new CollisionDamageComponent(1));
            result.AddComponent(new WeaponComponent(weapon)
            {
                ProjectileDirection = new Distance(-1, 0),
                FireOffset          = new Distance(-5, 2),
                TryFire             = true
            });

            result.Destroyed += SpawnMediumExplosionOnDeath;

            return(result);
        }
Beispiel #6
0
        public Entity CreateShuttleEnemy()
        {
            var result = new Entity()
            {
                Health    = 1,
                Rectangle = new Rect(0, 0, 35, 19),
                Team      = Team.Enemy
            };

            var weapon = new WeaponConfig()
            {
                Damage            = 1,
                ProjectileCreator = CreateEnemyShot,
                ShootSpeed        = 3
            };

            result.AddComponent(new RenderComponent(MainAtlas.GetFrame("shuttle.png")));
            result.AddComponent(GetJetAnim(new Distance(36, 1)));
            result.AddComponent(GetJetAnim(new Distance(36, 15)));
            result.AddComponent(new MovementComponent(150));
            result.AddComponent(new CollisionDamageComponent(1));
            result.AddComponent(new WeaponComponent(weapon)
            {
                ProjectileDirection = new Distance(-1, 0),
                FireOffset          = new Distance(0, 8),
                TryFire             = true
            });
            result.AddComponent(new SineMotorComponent(0.8f));

            result.Destroyed += SpawnExplosionOnDeath;

            return(result);
        }
Beispiel #7
0
        private Entity CreateBomberShield()
        {
            var result = new Entity()
            {
                Health    = 30,
                Rectangle = new Rect(0, 0, 123, 43),
            };

            result.AddComponent(new RenderComponent(MainAtlas.GetFrame("bombershield.png")));

            return(result);
        }
Beispiel #8
0
        private void CreateBaseUI()
        {
            var screen         = Vrax.Game.Screen;
            var chevronTexture = MainAtlas.GetFrame("chevron.png");

            var backImage = new Image(chevronTexture)
            {
                Parent   = Display,
                Scale    = new Distance(-1f, 1), // flip
                Position = new Point(10 + chevronTexture.Width, 10)
            };
            var backButton = new Button(
                new Button.State()
            {
            },
                new Button.State()
            {
            },
                new Button.State()
            {
                Scale = 0.95f
            });

            backButton.ClickEvent += OnExitHelp;
            backImage.Attach(backButton);

            LeftArrow = new Image(chevronTexture)
            {
                Parent   = Display,
                Scale    = new Distance(-1f, 1),
                Position = new Point(screen.Half.Width - chevronTexture.Width - 10, screen.Height - chevronTexture.Height - 10)
            };
            var leftButton = new Button(new Button.State(), new Button.State(), new Button.State()
            {
                Scale = 0.95f
            });

            leftButton.ClickEvent += OnLeftClicked;
            LeftArrow.Attach(leftButton);

            RightArrow = new Image(chevronTexture)
            {
                Parent   = Display,
                Position = new Point(screen.Half.Width + 10, screen.Height - chevronTexture.Height - 10)
            };
            var rightButton = new Button(new Button.State(), new Button.State(), new Button.State()
            {
                Scale = 0.95f
            });

            rightButton.ClickEvent += OnRightClicked;
            RightArrow.Attach(rightButton);
        }
Beispiel #9
0
        public Entity CreateDartEnemy()
        {
            var result = new Entity()
            {
                Health    = 1,
                Rectangle = new Rect(0, 0, 37, 26),
                Team      = Team.Enemy
            };

            var weapon = new WeaponConfig()
            {
                Damage            = 1,
                ProjectileCreator = CreateUpwardEnemyShot,
                ShootSpeed        = 0.8
            };

            result.AddComponent(new RenderComponent(MainAtlas.GetFrame("dart.png")));
            result.AddComponent(new MovementComponent(300)
            {
                MoveLeft = true
            });
            result.AddComponent(new CollisionDamageComponent(1)
            {
                DestroyOnCollide = true
            });
            // Top gun
            result.AddComponent(new WeaponComponent(weapon)
            {
                ProjectileDirection = new Distance(0, -1),
                FireOffset          = new Distance(21, 2),
                TryFire             = true
            });

            // Bottom gun
            result.AddComponent(new WeaponComponent(new WeaponConfig()
            {
                Damage            = 1,
                ProjectileCreator = CreateDownardEnemyShot,
                ShootSpeed        = 0.8,
            })
            {
                ProjectileDirection = new Distance(0, 1),
                FireOffset          = new Distance(21, 10),
                TryFire             = true
            });

            result.Destroyed += SpawnExplosionOnDeath;

            return(result);
        }
Beispiel #10
0
        public Entity CreateRank1Fighter()
        {
            var result = new Entity()
            {
                Health    = 3,
                Rectangle = new Rect(0, 2, 52, 20),
                Team      = Team.Player
            };

            result.AddComponent(new RenderComponent(MainAtlas.GetFrame("fighter1.png")));
            result.AddComponent(GetBurnerAnim(new Distance(0, 9)));
            result.AddComponent(new MovementComponent(200d));
            result.AddComponent(new PlayerControls());
            result.AddComponent(new InvulnerableDamageHandler(1.5d));

            // Starting weapon
            result.AddComponent(new WeaponComponent(new WeaponConfig()
            {
                ProjectileCreator = CreateLaser,
                ShootSpeed        = 0.3,
                Damage            = 1,
            })
            {
                FireOffset          = new Distance(28, 9),
                ProjectileDirection = new Distance(1f, 0)
            });
            // Wing weapon
            result.AddComponent(new WeaponComponent(new WeaponConfig()
            {
                ProjectileCreator = CreateLaser,
                ShootSpeed        = 0.3,
                Damage            = 1,
            })
            {
                TryFire             = true, // Autofire
                FireOffset          = new Distance(34, 21),
                ProjectileDirection = new Distance(1f, 0)
            });

            result.Destroyed += SpawnExplosionOnDeath;

            return(result);
        }
Beispiel #11
0
        public Entity CreateBeamShot()
        {
            var result = new Entity()
            {
                Health          = 1,
                Rectangle       = new Rect(0, 0, 10, 9),
                IgnoreCollision = true
            };

            result.AddComponent(new RenderSliceComponent(MainAtlas.GetFrame("beam.png")));
            result.AddComponent(new ProjectileComponent()
            {
                Speed = 0,
            });
            result.AddComponent(new CollisionDamageComponent(0));
            result.AddComponent(new GrowComponent(200, 0.8, 250));

            return(result);
        }
Beispiel #12
0
        public Entity CreateOrbShot()
        {
            var result = new Entity()
            {
                Health          = 1,
                Rectangle       = new Rect(0, 0, 8, 8),
                IgnoreCollision = true
            };

            result.AddComponent(new CollisionDamageComponent(0)
            {
                DestroyOnCollide = true
            });
            result.AddComponent(new RenderComponent(MainAtlas.GetFrame("orb.png")));
            result.AddComponent(new ProjectileComponent()
            {
                Speed = 400
            });

            return(result);
        }
Beispiel #13
0
        public Entity CreateUFOEnemy()
        {
            var result = new Entity()
            {
                Health    = 1,
                Rectangle = new Rect(0, 0, 18, 20),
                Team      = Team.Enemy
            };

            var weapon = new WeaponConfig()
            {
                Damage            = 1,
                ProjectileCreator = CreateOrbShot,
                ShootSpeed        = 1.5
            };

            result.AddComponent(new RenderComponent(MainAtlas.GetFrame("ufo.png")));
            result.AddComponent(new MovementComponent(75)
            {
                MoveLeft = true
            });
            result.AddComponent(new CollisionDamageComponent(1));
            result.AddComponent(new WeaponComponent(weapon)
            {
                ProjectileDirection = new Distance(-1, 0),
                FireOffset          = new Distance(6, 9),
                TryFire             = true,
                PlayerTracking      = true
            });
            result.AddComponent(new SineMotorComponent(1f));

            result.AddComponent(GetJetAnim(new Distance(6, 0), 90));
            result.AddComponent(GetJetAnim(new Distance(11, 20), 270));

            result.Destroyed += SpawnExplosionOnDeath;

            return(result);
        }
Beispiel #14
0
        public EntityFactory(AssetCache assetCache)
        {
            Rand      = new Random();
            Cache     = assetCache;
            MainAtlas = assetCache.Get <Atlas>("Atlas.json");
            if (MainAtlas == null)
            {
                MainAtlas = assetCache.LoadAtlas("Atlas.json");
            }

            LaserAsset         = MainAtlas.GetFrame("laser.png");
            LaserVerticalAsset = MainAtlas.GetFrame("laservertical.png");
            BulletAsset        = MainAtlas.GetFrame("bullet.png");
            EnemyShot          = MainAtlas.GetFrame("enemy_shot.png");

            LaserSound = assetCache.LoadSound("laserfire.wav");

            ExplodeSounds = new List <Sound>()
            {
                assetCache.Get <Sound>("explosion0.wav"),
                assetCache.Get <Sound>("explosion1.wav"),
                assetCache.Get <Sound>("explosion2.wav"),
            };
        }
Beispiel #15
0
        public Entity CreateRocketShot()
        {
            var result = new Entity()
            {
                Health          = 1,
                Rectangle       = new Rect(0, 0, 16, 8),
                IgnoreCollision = true
            };

            result.AddComponent(new RenderComponent(MainAtlas.GetFrame("rocket.png")));
            result.AddComponent(GetJetAnim(new Distance(14, 2)));
            result.AddComponent(new ProjectileComponent()
            {
                Speed = 50
            });
            result.AddComponent(new CollisionDamageComponent(0)
            {
                DestroyOnCollide = true
            });
            result.AddComponent(new AccelerationComponent(350, 1, Ease.Linear));
            result.Destroyed += SpawnExplosionOnDeath;

            return(result);
        }
Beispiel #16
0
        private void CreateUI()
        {
            UILayer = new DisplayContainer()
            {
                Parent = Display
            };

            var title = new Textfield(DefaultFont, "Begin!")
            {
                Parent   = UILayer,
                Position = new Point(Screen.Half.Width, -50),
                Anchor   = Distance.Center
            };

            Vrax.Game.Animator.AddSequence(new[]
            {
                title.MoveTo(new Point(Screen.Half.Width, Screen.Half.Height * 0.4f), 800, Ease.BounceOut),
                new DelayTween(1500),
                title.MoveRelative(new Distance(-Screen.Width, 0), 1500, Ease.CubicOut),
                new ActionTween(() => title.Parent = null)
            });

            HealthFrame     = MainAtlas.GetFrame("health.png");
            HealthOffset    = new Distance(DefaultFont.GetTextWidth("HP:") + 12, 9);
            TransformFrame  = MainAtlas.GetFrame("transform.png");
            TransformOffset = new Distance(DefaultFont.GetTextWidth("TX:") + 12, 35);

            MeterHolder = new Image(MainAtlas.GetFrame("meterholder.png"))
            {
                Parent    = UILayer,
                FixedSize = new Size(171, 40),
                Position  = new Point((Screen.Width - 171) * 0.5f, Screen.Height - 50)
            };
            Meter = new Image(MainAtlas.GetFrame("meter.png"))
            {
                Parent    = UILayer,
                Position  = MeterHolder.Position + new Distance(5, 5),
                FixedSize = new Size(0, MeterHeight)
            };
            KillCounterTextfield = new Textfield(DefaultFont, "0")
            {
                Parent   = UILayer,
                Position = new Point(Screen.Half.Width, MeterHolder.Position.Y + 5),
                Color    = Color.Black,
                Align    = TextAlign.Center,
                Anchor   = new Distance(0.5f, 0)
            };
            Spawner.KillCountChanged += OnKillCountChanged;

            var counterHolder = new Image(MainAtlas.GetFrame("meterholder.png"))
            {
                Parent    = UILayer,
                FixedSize = new Size(45, 40),
                Position  = MeterHolder.Position - new Distance(55, 0)
            };

            LevelCounterTextfield = new Textfield(DefaultFont, "0")
            {
                Parent   = UILayer,
                Position = counterHolder.Position + new Distance(22, 5),
                Color    = Color.Black,
                Align    = TextAlign.Center,
                Anchor   = new Distance(0.5f, 0)
            };

            // Shield counter
            ShieldImage = new Image(MainAtlas.GetFrame("shieldicon.png"))
            {
                Parent   = UILayer,
                Position = MeterHolder.Position + new Distance(MeterWidth + 40, 20),
                Anchor   = Distance.Center,
                Color    = Color.None
            };

            ShieldCounter = new Textfield(DefaultFont, "0")
            {
                Parent   = UILayer,
                Position = ShieldImage.Position,
                Anchor   = Distance.Center,
                Scale    = new Distance(0.5f, 0.5f),
                Color    = Color.None
            };
        }
Beispiel #17
0
        protected override void Start()
        {
            DefaultFont = AssetCache.LoadFont("DefaultFont.fnt");
            MainAtlas   = AssetCache.LoadAtlas("Atlas.json");
            AssetCache.LoadTexture("Title.png");

            Audio.PlayMusic(AssetCache.LoadMusic("song.mp3"));

            // Setup slices
            var beamTexture = MainAtlas.GetFrame("beam.png");

            beamTexture.Slice = new SliceSettings()
            {
                Left  = 2,
                Right = 2
            };

            var meterHolder = MainAtlas.GetFrame("meterholder.png");

            meterHolder.Slice = new SliceSettings()
            {
                Left  = 8,
                Right = 8
            };

            var meter = MainAtlas.GetFrame("meter.png");

            meter.Slice = new SliceSettings()
            {
                Left  = 2,
                Right = 2
            };

            Background.Add(new ParallaxLayer(MainAtlas.GetFrames("nebula{0}.png"), 50, (20, 45), (1f, 1f)));
            Background.Add(new ParallaxLayer(MainAtlas.GetFrames("star{0}.png"), 200, (100, 150), (1f, 1f)));

            // Load sounds
            AssetCache.LoadSound("hit0.wav");
            AssetCache.LoadSound("hit1.wav");
            AssetCache.LoadSound("hit2.wav");
            AssetCache.LoadSound("explosion0.wav");
            AssetCache.LoadSound("explosion1.wav");
            AssetCache.LoadSound("explosion2.wav");
            AssetCache.LoadSound("transform.wav");
            AssetCache.LoadSound("shieldup.wav");
            AssetCache.LoadSound("shielddown.wav");

            Factory = new EntityFactory(AssetCache);

            Input.Register(Controls.Cancel, Keycode.Escape);
            Input.Register(Controls.Up, Keycode.W, Keycode.Up);
            Input.Register(Controls.Left, Keycode.A, Keycode.Left);
            Input.Register(Controls.Down, Keycode.S, Keycode.Down);
            Input.Register(Controls.Right, Keycode.D, Keycode.Right);
            Input.Register(Controls.Fire, MouseButton.Left, MouseButtonState.Pressed);
            Input.Register(Controls.Fire, Keycode.Space);

            Input.Register(Controls.TransformSmaller, Keycode.Q);
            Input.Register(Controls.TransformSmaller, MouseButton.X1, MouseButtonState.Released);
            Input.Register(Controls.TransformBigger, Keycode.E);
            Input.Register(Controls.TransformBigger, MouseButton.X2, MouseButtonState.Released);

            var action = Input.Register(Controls.DisableMusic, Keycode.M);

            action.OnReleased += OnDisableMusic;

            action             = Input.Register(Controls.Debug, Keycode.F1);
            action.OnReleased += () => EnableDebug = !EnableDebug;

            State = new MenuState(Factory);
        }
Beispiel #18
0
        public Entity CreateBomber()
        {
            var result = new Entity()
            {
                Health    = 4,
                Rectangle = new Rect(2, 2, 98, 29),
                Team      = Team.Player
            };

            result.AddComponent(new MovementComponent(100d));
            result.AddComponent(new PlayerControls());
            result.AddComponent(new InvulnerableDamageHandler(2d));

            // upper weapon
            result.AddComponent(new WeaponComponent(new WeaponConfig()
            {
                ProjectileCreator = CreateLaser,
                ShootSpeed        = 0.2,
                Damage            = 1,
            })
            {
                FireOffset          = new Distance(88, 1),
                ProjectileDirection = new Distance(1f, 0)
            });
            // lower weapon
            result.AddComponent(new WeaponComponent(new WeaponConfig()
            {
                ProjectileCreator = CreateLaserVertical,
                ShootSpeed        = 0.3,
                Damage            = 1,
            })
            {
                FireOffset          = new Distance(80, 32),
                ProjectileDirection = new Distance(0, 1f)
            });

            // Bomb
            var bombWeapon = new WeaponComponent(new WeaponConfig()
            {
                ProjectileCreator = CreateBomb,
                ShootSpeed        = 1,
                Damage            = 20,
            })
            {
                FireOffset          = new Distance(37, 22),
                ProjectileDirection = new Distance(1f, 0)
            };

            result.AddComponent(bombWeapon);

            result.AddComponent(new RenderComponent(MainAtlas.GetFrame("bomb.png"))
            {
                Offset    = new Distance(37, 22),
                Condition = () => bombWeapon.FireTimer == 0
            });
            result.AddComponent(new RenderComponent(MainAtlas.GetFrame("bomber.png")));
            result.AddComponent(GetBurnerAnim(new Distance(0, 9)));
            result.AddComponent(GetBurnerAnim(new Distance(0, 21)));

            result.AddComponent(new ShieldComponent(CreateBomberShield())
            {
                Cooldown = 1f,
            });

            result.Destroyed += SpawnMediumExplosionOnDeath;

            return(result);
        }