コード例 #1
0
ファイル: Owliver.cs プロジェクト: lab132/owlicity
        public Owliver()
        {
            BodyComponent = new BodyComponent(this)
            {
                InitMode = BodyComponentInitMode.Manual,
            };
            RootComponent = BodyComponent;

            Movement = new MovementComponent(this)
            {
                BodyComponent         = BodyComponent,
                ManualInputProcessing = true,
                MaxMovementSpeed      = 3.5f,
            };

            Animation = new SpriteAnimationComponent(this)
            {
                AnimationTypes = new List <SpriteAnimationType>
                {
                    SpriteAnimationType.Owliver_Idle_Stick_Left,
                    SpriteAnimationType.Owliver_Idle_Stick_Right,
                    SpriteAnimationType.Owliver_Walk_Stick_Left,
                    SpriteAnimationType.Owliver_Walk_Stick_Right,
                    SpriteAnimationType.Owliver_Attack_Stick_Left,
                    SpriteAnimationType.Owliver_Attack_Stick_Right,
                    SpriteAnimationType.Owliver_Idle_FishingRod_Left,
                    SpriteAnimationType.Owliver_Idle_FishingRod_Right,
                    SpriteAnimationType.Owliver_Walk_FishingRod_Left,
                    SpriteAnimationType.Owliver_Walk_FishingRod_Right,
                    SpriteAnimationType.Owliver_Attack_FishingRod_Left,
                    SpriteAnimationType.Owliver_Attack_FishingRod_Right,
                },
            };
            Animation.AttachTo(BodyComponent);

            Health = new HealthComponent(this)
            {
                MaxHealth = 5,
            };
            Health.OnHit += OnHit;

            GameObjectFactory.CreateOnHitSquasher(this, Health, Animation).SetDefaultCurves(HitDuration);

            GameObjectFactory.CreateOnHitBlinkingSequence(this, Health, Animation).SetDefaultCurves(HitDuration);

            MoneyBag = new MoneyBagComponent(this)
            {
                InitialAmount = 0,
            };

            KeyRing = new KeyRingComponent(this);
        }
コード例 #2
0
        public static void SpawnGameObjectsInRingFormation(Vector2 center, float radius, int numToSpawn, Random rand,
                                                           params KnownGameObject[] types)
        {
            Vector2 localPosition = new Vector2(radius, 0.0f);
            Angle   angle         = new Angle {
                Radians = MathHelper.TwoPi / numToSpawn
            };

            for (int bonbonIndex = 0; bonbonIndex < numToSpawn; bonbonIndex++)
            {
                KnownGameObject type = rand.Choose(types);
                GameObject      go   = GameObjectFactory.CreateKnown(type);
                go.SetWorldPosition(center + localPosition);
                Game.AddGameObject(go);

                localPosition = localPosition.GetRotated(angle);
            }
        }
コード例 #3
0
ファイル: Screen.cs プロジェクト: lab132/owlicity
        public void LoadContent(Level level)
        {
            string groundTextureName    = string.Format(level.ContentNameFormat_Ground, GridPosition.Y, GridPosition.X);
            string collisionContentName = string.Format(level.ContentNameFormat_Collision, GridPosition.Y, GridPosition.X);
            string layoutContentName    = string.Format(level.ContentNameFormat_Layout, GridPosition.Y, GridPosition.X);

            //
            // Screen game object
            //
            {
                _screenGameObject = new BackgroundScreen();
                _screenGameObject.Spatial.Position        += WorldPosition;
                _screenGameObject.ShapeContentName         = collisionContentName;
                _screenGameObject.Sprite.SpriteContentName = groundTextureName;

                Global.Game.AddGameObject(_screenGameObject);
            }

            List <ScreenLayoutInfo> layoutInfos = Global.Game.Content.Load <List <ScreenLayoutInfo> >(layoutContentName);

            foreach (ScreenLayoutInfo layout in layoutInfos)
            {
                var deco = GameObjectFactory.CreateKnown(layout.ObjectType);

#if false
                SpriteAnimationComponent sa = deco.GetComponent <SpriteAnimationComponent>();
                // Choose random initial frame
                sa.OnPostInitialize += delegate()
                {
                    int startFrame = level.Random.Next(3);
                    for (int frameIndex = 0; frameIndex < startFrame; frameIndex++)
                    {
                        sa.ActiveAnimation.AdvanceFrameIndex();
                    }
                };
#endif
                deco.Spatial.Position += layout.OffsetInMeters;
                deco.AttachTo(_screenGameObject);

                Global.Game.AddGameObject(deco);

                _decorationObjects.Add(deco);
            }
        }
コード例 #4
0
        public Tankton()
        {
            BodyComponent = new BodyComponent(this)
            {
                InitMode = BodyComponentInitMode.Manual,
            };
            RootComponent = BodyComponent;

            Animation = new SpriteAnimationComponent(this)
            {
                AnimationTypes = new List <SpriteAnimationType>
                {
                    SpriteAnimationType.Tankton_Idle_Left,
                    SpriteAnimationType.Tankton_Idle_Right,
                },
            };
            Animation.Spatial.Position.Y += Conversion.ToMeters(100);
            Animation.AttachTo(BodyComponent);

            Health = new HealthComponent(this)
            {
                MaxHealth = 20,
            };
            Health.OnHit   += OnHit;
            Health.OnDeath += OnDeath;

            HealthDisplay = new HealthDisplayComponent(this)
            {
                Health               = Health,
                HealthIcon           = SpriteAnimationFactory.CreateAnimationInstance(SpriteAnimationType.Cross),
                InitialDisplayOrigin = HealthDisplayComponent.DisplayOrigin.Bottom,
                NumIconsPerRow       = 5,
            };
            HealthDisplay.AttachTo(Animation);

            GameObjectFactory.CreateOnHitSquasher(this, Health, Animation).SetDefaultCurves(
                duration: HitDuration,
                extremeScale: new Vector2(0.9f, 1.1f));

            GameObjectFactory.CreateOnHitBlinkingSequence(this, Health, Animation).SetDefaultCurves(HitDuration);
        }
コード例 #5
0
ファイル: Game.cs プロジェクト: lab132/owlicity
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            Perf.Initialize((int)PerformanceSlots.COUNT, 120);

            SpriteAnimationFactory.Initialize(Content);
            GameObjectFactory.Initialize();

            World = new World(gravity: Vector2.Zero);

            PhysicsDebugView = new DebugView(World)
            {
                Flags   = (DebugViewFlags)int.MaxValue,
                Enabled = false,
            };

            base.Initialize();

#if DEBUG
            Window.AllowUserResizing = true;
#endif
        }
コード例 #6
0
ファイル: Slurp.cs プロジェクト: lab132/owlicity
        public Slurp()
        {
            BodyComponent = new BodyComponent(this)
            {
                InitMode = BodyComponentInitMode.Manual,
            };
            RootComponent = BodyComponent;

            Animation = new SpriteAnimationComponent(this)
            {
                AnimationTypes = new List <SpriteAnimationType>
                {
                    SpriteAnimationType.Slurp_Idle_Left,
                    SpriteAnimationType.Slurp_Idle_Right,
                },
            };
            Animation.AttachTo(BodyComponent);

            Health = GameObjectFactory.CreateDefaultHealth(this,
                                                           maxHealth: 3,
                                                           hitDuration: HitDuration,
                                                           deathParticleTimeToLive: TimeSpan.FromSeconds(1));

            HealthDisplay = new HealthDisplayComponent(this)
            {
                Health = Health,
                InitialDisplayOrigin = HealthDisplayComponent.DisplayOrigin.Bottom,
                HealthIcon           = SpriteAnimationFactory.CreateAnimationInstance(SpriteAnimationType.Cross),
            };
            HealthDisplay.AttachTo(Animation);

            GameObjectFactory.CreateOnHitSquasher(this, Health, Animation).SetDefaultCurves(HitDuration);

            GameObjectFactory.CreateOnHitBlinkingSequence(this, Health, Animation).SetDefaultCurves(HitDuration);

            Homing = GameObjectFactory.CreateDefaultHomingCircle(this, BodyComponent,
                                                                 sensorRadius: 3.0f,
                                                                 homingType: HomingType.ConstantSpeed,
                                                                 homingSpeed: 0.5f);
        }
コード例 #7
0
ファイル: Singer.cs プロジェクト: lab132/owlicity
        public Singer()
        {
            BodyComponent = new BodyComponent(this)
            {
                InitMode = BodyComponentInitMode.Manual,
            };
            RootComponent = BodyComponent;

            TargetSensor = new TargetSensorComponent(this)
            {
                SensorType                = TargetSensorType.Circle,
                CircleSensorRadius        = SensorReach,
                TargetCollisionCategories = CollisionCategory.Friendly,
            };
            TargetSensor.AttachTo(RootComponent);

            Animation = new SpriteAnimationComponent(this)
            {
                AnimationTypes = new List <SpriteAnimationType>
                {
                    SpriteAnimationType.Singer_Idle_Left,
                    SpriteAnimationType.Singer_Idle_Right,
                },
            };
            Animation.AttachTo(RootComponent);

            Health = GameObjectFactory.CreateDefaultHealth(this,
                                                           maxHealth: 3,
                                                           hitDuration: HitDuration,
                                                           deathParticleTimeToLive: TimeSpan.FromSeconds(1));

            HealthDisplay = new HealthDisplayComponent(this)
            {
                Health     = Health,
                HealthIcon = SpriteAnimationFactory.CreateAnimationInstance(SpriteAnimationType.Cross),
            };
            HealthDisplay.AttachTo(Animation);
        }
コード例 #8
0
ファイル: Owliver.cs プロジェクト: lab132/owlicity
        public override void Update(float deltaSeconds)
        {
            base.Update(deltaSeconds);

            Vector2 dp            = MyBody.LinearVelocity;
            float   movementSpeed = dp.Length();

            OwliverState newState = CurrentState;

            const float movementChangeThreshold = 0.01f;

            switch (CurrentState.MovementMode)
            {
            case OwliverMovementMode.Idle:
            {
                if (movementSpeed >= movementChangeThreshold)
                {
                    newState.MovementMode = OwliverMovementMode.Walking;
                }
            }
            break;

            case OwliverMovementMode.Walking:
            {
                if (movementSpeed < movementChangeThreshold)
                {
                    newState.MovementMode = OwliverMovementMode.Idle;
                }
            }
            break;
            }

            const float facingChangeThreshold = 0.01f;

            if (CurrentState.FacingDirection == OwliverFacingDirection.Left && dp.X > facingChangeThreshold)
            {
                newState.FacingDirection = OwliverFacingDirection.Right;
            }
            else if (CurrentState.FacingDirection == OwliverFacingDirection.Right && dp.X < -facingChangeThreshold)
            {
                newState.FacingDirection = OwliverFacingDirection.Left;
            }

            GameInput input = ConsumeInput();

            if (input.WantsAttack)
            {
                newState.MovementMode = OwliverMovementMode.Attacking;
            }

            if (input.WantsInteraction)
            {
                foreach (ShopItem shopItem in ConnectedShopItems)
                {
                    bool purchase          = false;
                    bool removeIfPurchased = true;

                    int price = shopItem.PriceValue;
                    if (MoneyBag.CurrentAmount >= price)
                    {
                        switch (shopItem.ItemType)
                        {
                        case ShopItemType.FruitBowl:
                        {
                            purchase          = true;
                            removeIfPurchased = false;
                            Health.Heal(int.MaxValue);
                        }
                        break;

                        case ShopItemType.FishingRod:
                        {
                            if (CurrentState.WeaponType != OwliverWeaponType.FishingRod)
                            {
                                purchase            = true;
                                newState.WeaponType = OwliverWeaponType.FishingRod;
                                ChangeState(ref newState);

                                var newGo = GameObjectFactory.CreateKnown(KnownGameObject.ShopItem_Stick);
                                newGo.Spatial.CopyFrom(shopItem.Spatial);
                                Global.Game.AddGameObject(newGo);
                            }
                        }
                        break;

                        case ShopItemType.Stick:
                        {
                            if (CurrentState.WeaponType != OwliverWeaponType.Stick)
                            {
                                purchase            = true;
                                newState.WeaponType = OwliverWeaponType.Stick;
                                ChangeState(ref newState);

                                var newGo = GameObjectFactory.CreateKnown(KnownGameObject.ShopItem_FishingRod);
                                newGo.Spatial.CopyFrom(shopItem.Spatial);
                                Global.Game.AddGameObject(newGo);
                            }
                        }
                        break;

                        default: throw new InvalidProgramException("Invalid item type.");
                        }
                    }

                    if (purchase)
                    {
                        MoneyBag.CurrentAmount -= price;
                        if (removeIfPurchased)
                        {
                            Global.Game.RemoveGameObject(shopItem);
                        }
                    }
                }

                foreach (ShopItem shopItem in ConnectedShopItems)
                {
                    shopItem.IsAffordable = MoneyBag.CurrentAmount >= shopItem.PriceValue;
                }
            }

            ChangeState(ref newState);

            AABB weaponAABB = WeaponAABB;

            if (input.WantsAttack && CurrentState.MovementMode == OwliverMovementMode.Attacking)
            {
                int            damage   = Damage;
                float          force    = 0.1f * damage;
                List <Fixture> fixtures = Global.Game.World.QueryAABB(ref weaponAABB);
                foreach (Body hitBody in fixtures.Where(f => f.CollisionCategories.HasFlag(CollisionCategory.Enemy))
                         .Select(f => f.Body)
                         .Distinct())
                {
                    Global.HandleDefaultHit(hitBody, MyBody.Position, damage, force);
                }

                bool throwProjectiles = true;
                if (throwProjectiles)
                {
                    float sign  = CurrentState.FacingDirection == OwliverFacingDirection.Left ? -1.0f : 1.0f;
                    float speed = 8.0f;

                    Projectile projectile = new Projectile()
                    {
                        MaxSpeed            = speed,
                        CollisionCategories = CollisionCategory.FriendlyWeapon,
                        CollidesWith        = CollisionCategory.World | CollisionCategory.AnyEnemy,
                    };
                    projectile.Spatial.CopyFrom(new SpatialData {
                        Position = WeaponAABB.Center
                    });
                    projectile.Spatial.Position.X           += sign * 0.1f;
                    projectile.AutoDestruct.DestructionDelay = TimeSpan.FromSeconds(2.0f);

                    Vector2 velocity = sign * new Vector2(speed, 0.0f);

#if false
                    var hoc = new HomingComponent(projectile)
                    {
                        Target      = Global.Game.GameObjects.Where(go => go.GetComponent <TanktonComponent>() != null).FirstOrDefault(),
                        HomingType  = HomingType.ConstantAcceleration,
                        TargetRange = 1.0f,
                        Speed       = velocity.Length() * 10,
                    };
                    hoc.AttachTo(projectile);
#endif

                    projectile.BodyComponent.BeforePostInitialize += () =>
                    {
                        Body    body    = projectile.BodyComponent.Body;
                        Vector2 impulse = body.Mass * velocity;
                        body.ApplyLinearImpulse(ref impulse);
                    };
                    Global.Game.AddGameObject(projectile);
                }
            }
            else
            {
                if (!Health.IsInvincible)
                {
                    Vector2 movementVector = Movement.ConsumeMovementVector();
                    Movement.PerformMovement(movementVector, deltaSeconds);
                }
            }

            // Debug drawing.
            {
                Color color = CurrentState.MovementMode == OwliverMovementMode.Attacking ? Color.Navy : Color.Gray;
                Global.Game.DebugDrawCommands.Add(view =>
                {
                    view.DrawAABB(ref weaponAABB, color);
                });
            }
        }
コード例 #9
0
ファイル: Singer.cs プロジェクト: lab132/owlicity
        public override void Update(float deltaSeconds)
        {
            if (CurrentProjectile == null && CurrentProjectileLaunchCooldown > 0)
            {
                CurrentProjectileLaunchCooldown -= deltaSeconds;
                if (CurrentProjectileLaunchCooldown < 0)
                {
                    CurrentProjectileLaunchCooldown = 0.0f;
                }
            }

            Body target = TargetSensor.CurrentMainTarget;

            if (CanLaunchProjectile && target != null)
            {
                if (CurrentProjectile == null)
                {
                    Vector2 myPosition = this.GetWorldSpatialData().Position;
                    (target.Position - myPosition).GetDirectionAndLength(out Vector2 targetDir, out float targetDistance);

                    const float speed      = 1.8f;
                    Projectile  projectile = new Projectile
                    {
                        MaxSpeed            = speed,
                        CollisionCategories = CollisionCategory.EnemyWeapon,
                        CollidesWith        = CollisionCategory.World | CollisionCategory.AnyFriendly,
                    };
                    projectile.Animation.AnimationTypes = new List <SpriteAnimationType> {
                        SpriteAnimationType.Bonbon_Gold
                    };
                    float relativeSpawnOffset = 0.5f; // meters
                    projectile.Spatial.Position = myPosition + targetDir * relativeSpawnOffset;

                    projectile.BodyComponent.BeforePostInitialize += () =>
                    {
                        projectile.BodyComponent.Body.LinearVelocity = targetDir * speed;
                    };

                    GameObjectFactory.CreateDefaultHomingCircle(projectile, projectile.BodyComponent,
                                                                sensorRadius: 1.1f * SensorReach,
                                                                homingType: HomingType.ConstantAcceleration,
                                                                homingSpeed: 0.05f * speed);

                    projectile.AutoDestruct.DestructionDelay = ProjectileTimeToLive;


                    CurrentProjectile = projectile;
                    projectile.AutoDestruct.BeforeDestroy += () =>
                    {
                        CurrentProjectile = null;
                    };

                    CurrentProjectileLaunchCooldown = (float)ProjectileLaunchCooldown.TotalSeconds;

                    Global.Game.AddGameObject(projectile);
                }

                Global.Game.DebugDrawCommands.Add(view =>
                {
                    view.DrawCircle(target.Position, 1.0f, Color.Red);
                });
            }
            base.Update(deltaSeconds);
        }
コード例 #10
0
ファイル: Game.cs プロジェクト: lab132/owlicity
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            WorldRenderer.Initialize(GraphicsDevice);
            UIRenderer.Initialize(GraphicsDevice);

            PhysicsDebugView.LoadContent(GraphicsDevice, Content);

            CurrentLevel = new Level(Content)
            {
                ContentNameFormat_Ground    = "level01/level1_ground_{0}{1}",
                ContentNameFormat_Collision = "level01/static_collision/static_collision_{0}{1}",
                ContentNameFormat_Layout    = "level01/layout/layout_{0}{1}",
            };

            for (int x = 0; x < 4; x++)
            {
                for (int y = 0; y < 7; y++)
                {
                    CurrentLevel.CreateScreen(x, y);
                }
            }

            {
                Owliver = new Owliver();
                Owliver.Spatial.Position += Conversion.ToMeters(450, 600);
                AddGameObject(Owliver);

                CurrentLevel.CullingCenter = Owliver;
            }

            CurrentLevel.LoadContent();

            {
                ActiveCamera = new CameraObject();

                ActiveCamera.CameraComponent.VisibilityBounds = CurrentLevel.LevelBounds;
                ActiveCamera.CameraComponent.OnGraphicsDeviceReset(GraphicsDevice);
                Window.ClientSizeChanged += (o, e) =>
                {
                    ActiveCamera.CameraComponent.OnGraphicsDeviceReset(GraphicsDevice);
                };

                ActiveCamera.SpringArm.BeforeInitialize += () =>
                {
                    ActiveCamera.SpringArm.Target = Owliver;
                };

                AddGameObject(ActiveCamera);
            }

#if true
            {
                var testSlurp = GameObjectFactory.CreateKnown(KnownGameObject.Slurp);
                testSlurp.Spatial.Position += Conversion.ToMeters(300, 250);
                AddGameObject(testSlurp);
            }

            {
                var testTankton = new Tankton();
                testTankton.Spatial.Position += Conversion.ToMeters(900, 350);
                AddGameObject(testTankton);
            }

            {
                Random rand = new Random();

                Global.SpawnGameObjectsInRingFormation(
                    center: Conversion.ToMeters(2400, 500),
                    radius: 2.5f,
                    numToSpawn: 15,
                    rand: rand,
                    types: new[] { KnownGameObject.Bonbon_Gold, KnownGameObject.Bonbon_Red });

                Global.SpawnGameObjectsInRingFormation(
                    center: Conversion.ToMeters(2400, 500),
                    radius: 1.0f,
                    numToSpawn: 5,
                    rand: rand,
                    types: new[] { KnownGameObject.Bonbon_Gold, KnownGameObject.Bonbon_Red });
            }

            {
                var testKey = new KeyPickup()
                {
                    KeyType = KeyType.Gold
                };
                testKey.Spatial.Position += Conversion.ToMeters(700, 720);
                AddGameObject(testKey);
            }

            {
                var testGate = new Gate();
                testGate.Spatial.Position += Conversion.ToMeters(2300, 1100);
                AddGameObject(testGate);
            }

            {
                var testShop = new Shop();
                testShop.Spatial.Position += Conversion.ToMeters(1300, 500);
                AddGameObject(testShop);

                var testFruitBowl = new ShopItem()
                {
                    ItemType = ShopItemType.FruitBowl
                };
                testFruitBowl.Price = ShopItemPriceType._20;
                testFruitBowl.AttachTo(testShop);
                testFruitBowl.Spatial.Position += Conversion.ToMeters(-110.0f, -90.0f);
                AddGameObject(testFruitBowl);

                var testRod = new ShopItem()
                {
                    ItemType = ShopItemType.FishingRod
                };
                testRod.Price = ShopItemPriceType._100;
                testRod.AttachTo(testShop);
                testRod.Spatial.Position += Conversion.ToMeters(128.0f, -80.0f);
                AddGameObject(testRod);
            }

            {
                var testSinger = new Singer();
                testSinger.Spatial.Position += Conversion.ToMeters(2600, 300);
                AddGameObject(testSinger);
            }

            {
                var testTrap = new SpikeTrap()
                {
                    Orientation = SpikeTrapOrientation.Vertical,
                    SensorReach = 4.0f,
                };
                testTrap.Spatial.Position += Conversion.ToMeters(1600, 500);
                AddGameObject(testTrap);
            }
#endif

            {
                var BackgroundMusic = Content.Load <Song>("snd/FiluAndDina_-_Video_Game_Background_-_Edit");
                MediaPlayer.IsRepeating = true;
#if false
                MediaPlayer.Play(BackgroundMusic);
#endif
            }

            Hud.Initialize();
            Hud.ResetLayout(GraphicsDevice.Viewport.Bounds);
            Window.ClientSizeChanged += (o, e) =>
            {
                Hud.ResetLayout(GraphicsDevice.Viewport.Bounds);
            };
        }