예제 #1
0
        public override void Update(World world)
        {
            var speed = this.Speed * (1 - ((world as RedMeansGoWorld).Player as Player).Health + 1);
            this.Y += (float)speed;
            this.X += (float)(Math.Cos(this.Y /
                ((Tileset.TILESET_PIXEL_HEIGHT - RedMeansGoGame.GAME_HEIGHT) / 2)
                * Math.PI * 2
            ) * speed);
            this.Rotation += 0.05f;

            if (this.Y > Tileset.TILESET_PIXEL_HEIGHT)
                world.Entities.Remove(this);

            this.Color = new Color(255, 255, 255);

            var w = world as RedMeansGoWorld;
            if ((w.Player as Entities.Player).Health > 0)
            {
                if (w.Player.X - this.X < 60 && w.Player.X - this.X > -60 &&
                    w.Player.Y - this.Y < 60 && w.Player.Y - this.Y > -60)
                {
                    if (Vector2.Distance(
                    new Vector2(this.X, this.Y),
                    new Vector2(w.Player.X, w.Player.Y)) < 8)
                        (world as RedMeansGoWorld).Restart();
                }
            }

            base.Update(world);
        }
예제 #2
0
 public Player(World world)
     : base(world)
 {
     this.Images = this.GetTexture("chars.player.player");
     this.Width = 16;
     this.Height = 16;
 }
예제 #3
0
        public override void Update(World world)
        {
            base.Update(world);

            // Movement handling.
            this.XSpeed = 0;
            this.YSpeed = 0;
        }
예제 #4
0
 public virtual void MoveRight(World world)
 {
     this.m_PlayerIsMoving = true;
     this.ImageFlipX = false;
     if (this.CollidesWithSolidAt(world, (int)(this.X + this.PlayerMovementSpeed), (int)this.Y - 1))
         this.MoveUntilContact(world, 1, 0, this.PlayerMovementSpeed);
     else
         this.X += this.PlayerMovementSpeed;
 }
예제 #5
0
        public override void Update(World rawWorld)
        {
            RedMeansGoWorld world = rawWorld as RedMeansGoWorld;

            if (!this.m_HasSpawned)
            {
                world.SpawnPlayer<Player>(this.X, this.Y);
                this.m_HasSpawned = true;
            }

            base.Update(world);
        }
예제 #6
0
 public override void Update(World rawWorld)
 {
     if (this.m_IsPlaying && this.m_Instance.State != SoundState.Playing)
     {
         this.m_Instance.Play();
         this.RaiseOnPlay();
         this.m_IsPlaying = false;
     }
     else if (!this.m_IsPlaying && !this.IsLooped && this.m_Instance.State == SoundState.Stopped && this.m_HasPlayed)
     {
         if (this.DeleteWhenFinished)
             this.m_World.Entities.Remove(this);
     }
 }
예제 #7
0
        public override void Draw(World world, XnaGraphics graphics)
        {
            this.m_World = world as RedMeansGoWorld;
            base.Draw(world, graphics);

            graphics.DrawSprite((int)this.X, (int)this.Y, this.Width - 8, this.Height - 8, "player.powerup", this.PowerupColor, false, this.Rotation,
                                new Vector2(54 / 2, 54 / 2));

            string msg;
            if (this.Health <= 0)
                msg = "You win.  They died.";
            else
                msg = "Distance to Heart: " + (this.Health * 150).ToString("F2") + "cm";
            graphics.DrawStringCentered((int)this.X, (int)this.Y + 40, msg);
            RedMeansGoGame.SetWindowTitle(msg);
        }
예제 #8
0
        public override void Update(World world)
        {
            this.X += (float)(Math.Cos(this.m_Direction) * this.m_Speed);
            this.Y += (float)(Math.Sin(this.m_Direction) * this.m_Speed);
            this.Rotation += this.m_RotationSpeed;

            if (this.Y < 0)
                world.Entities.Remove(this);

            double heartbeat = (world as RedMeansGoWorld).Heartbeats.Current;
            if (((world as ShmupWorld).Player as Player).Health <= 0) heartbeat = -0.4; // You're dead :(
            this.Width = (int)(8 * (heartbeat * 0.2 + 1));
            this.Height = (int)(8 * (heartbeat * 0.2 + 1));

            base.Update(world);
        }
예제 #9
0
        public override void Update(World rawWorld)
        {
            PlayerWorld world = rawWorld as PlayerWorld;

            // Check to see if player is null and we should center the pan.
            if (world.Player == null)
            {
                this.m_Instance.Pan = 0.0f;
                return;
            }

            // Calculate standard position.
            float v = Math.Abs(this.X - world.Player.X) / 300f;
            if (v > 1) v = 1;
            this.m_Instance.Pan = (this.X > world.Player.X) ? v : -v;
            this.m_Instance.Volume = (1 - v) * this.VolumeMax;

            // Calculate wrapped position if needed.
            if (1 - v == 0)
            {
                // Potentially needs to do some wrapping calculations, offset by
                // the room width.
                v = Math.Abs(this.X - (world.Player.X - Tileset.TILESET_PIXEL_WIDTH)) / 300f;
                if (v > 1)
                {
                    // Other side.
                    v = Math.Abs(this.X - (world.Player.X + Tileset.TILESET_PIXEL_WIDTH)) / 300f;
                    if (v > 1) v = 1;
                    this.m_Instance.Pan = -v;
                }
                else
                    this.m_Instance.Pan = v;
                this.m_Instance.Volume = (1 - v) * this.VolumeMax;
            }

            if (this.m_IsPlaying && this.m_Instance.State != SoundState.Playing)
            {
                this.m_Instance.Play();
                this.RaiseOnPlay();
                this.m_IsPlaying = false;
            }
            else if (!this.m_IsPlaying && !this.IsLooped && this.m_Instance.State == SoundState.Stopped && this.m_HasPlayed)
            {
                if (this.DeleteWhenFinished)
                    this.m_World.Entities.Remove(this);
            }
        }
예제 #10
0
        public override void Update(World world)
        {
            var speed = this.Speed * (1 - ((world as RedMeansGoWorld).Player as Player).Health + 1);
            if (((world as RedMeansGoWorld).Player as Entities.Player).Health <= 0)
                speed = 0.1f;
            this.Y += (float)speed;
            this.X += (float)(Math.Cos(this.Y /
                ((Tileset.TILESET_PIXEL_HEIGHT - RedMeansGoGame.GAME_HEIGHT) / 2)
                * Math.PI * 2) * speed);

            if (this.Y > Tileset.TILESET_PIXEL_HEIGHT)
                world.Entities.Remove(this);

            this.Color = new Color(127, 0, 0);

            base.Update(world);
        }
예제 #11
0
 public TitleWorld()
 {
     // TODO: Make buttons centered during update or w/e...
     int CX = 800;
     int OY = 300;
     this.m_Buttons.Add(new Button("Generate World", new Rectangle(CX - 100, OY, 200, 30), () =>
     {
         this.m_TargetWorld = new RPGWorld();
     }));
     this.m_Buttons.Add(new Button("Randomize Seed", new Rectangle(CX - 100, OY + 40, 200, 30), () =>
     {
         m_StaticSeed = m_Random.Next();
     }));
     this.m_Buttons.Add(new Button("Exit", new Rectangle(CX - 100, OY + 80, 200, 30), () =>
     {
         (this.Game as RuntimeGame).Exit();
     }));
 }
예제 #12
0
        public override void Update(World rawWorld)
        {
            RTSWorld world = rawWorld as RTSWorld;

            if (!this.m_HasSpawned)
            {
                // Set to neutral.
                Team teamInstance = world.Teams.DefaultIfEmpty(null).First(v => (v.Name == "Neutral"));
                if (teamInstance == null)
                    throw new ProtogameException("Unable to find neutral team instance.");

                // Find unit factory.
                foreach (Type t in AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes()))
                {
                    if (typeof(IUnitFactory).IsAssignableFrom(t) && !t.IsInterface)
                    {
                        IUnitFactory factory = t.GetConstructor(Type.EmptyTypes).Invoke(null) as IUnitFactory;
                        if (factory.CanCreate(this.m_UnitName))
                        {
                            this.m_Unit = factory.Create(world, this.Level, teamInstance, this.m_UnitName, this.m_Attributes);
                            this.m_Unit.X = this.X;
                            this.m_Unit.Y = this.Y;
                            this.Level.Entities.Add(this.m_Unit);
                            this.m_HasSpawned = true;
                            if (this.m_SynchronisationName != null)
                            {
                                this.m_Unit.SetSynchronisationName(this.m_SynchronisationName);
                                this.m_Unit.ForceSynchronisation();
                            }
                            return;
                        }
                    }
                }

                throw new ProtogameException("Unable to find unit factory that handles unit name '" + this.m_UnitName + "'.");
            }

            base.Update(world);
        }
예제 #13
0
        public override void MoveDown(World world)
        {
            this.Health += 0.0002;

            base.MoveDown(world);
        }
예제 #14
0
 public virtual void MoveUp(World world)
 {
     this.Y -= this.PlayerMovementSpeed;
 }
예제 #15
0
 public virtual void MoveRight(World world)
 {
     this.X += this.PlayerMovementSpeed;
 }
예제 #16
0
 public virtual void MoveLeft(World world)
 {
     this.X -= this.PlayerMovementSpeed;
 }
예제 #17
0
        public override void Update(World world)
        {
            base.Update(world);

            // Movement handling.
            this.XSpeed = 0;

            // Gravity.
            if (this.YSpeed > 12) this.YSpeed = 12;

            // Death.
            if (this.Y > Tileset.TILESET_PIXEL_HEIGHT)
                world.LoadLevel(world.CurrentLevel);

            if (!this.m_PlayerIsMoving)
                this.PerformAlignment(8, 4, () => { this.MoveLeft(world); }, () => { this.MoveRight(world); });
        }
예제 #18
0
 public PannedAudioEntity(World world, string name)
     : base(world, name)
 {
 }
예제 #19
0
 public void Fire(World world, Player player)
 {
     if ((world as RedMeansGoWorld).Heartbeats.Current > 0.3)
         world.Entities.Add(new StandardBullet { X = player.X, Y = player.Y });
 }
예제 #20
0
 public BackgroundAudioEntity(World world, string name)
     : base(world, name)
 {
 }
예제 #21
0
 /// <summary>
 /// Returns whether the default sprite should be rendered for this unit.
 /// </summary>
 /// <param name="world">The world that owns this entity.</param>
 /// <returns>Whether the default sprite should be rendered for this unit.</returns>
 public bool ShouldRender(World world)
 {
     return (world as MultiLevelWorld).ActiveLevel == this.Level;
 }
예제 #22
0
        public override void Draw(World world, XnaGraphics graphics)
        {
            base.Draw(world, graphics);

            if (this.Width == 16 && this.CurrentHealth > 0 && this.MaxHealth > 0)
                graphics.DrawSprite((int)this.X, (int)this.Y, this.Width, this.Height, "meters.health.i" + ((int)(16 - (this.CurrentHealth / this.MaxHealth * 15))).ToString(), Color.White, false);

            // You can override to show more meters in subclasses.
        }
예제 #23
0
        public override void Update(World world)
        {
            // Enter the movement clause if needed.
            if (this.m_CurrentPath != null && this.MoveSpeed > 0 && !this.Killed)
            {
                // Check to see if we can move to the desired location.
                //Unit u =
                this.CollidesAt<Unit>(world, this.m_CurrentPath.Peek().X * Tileset.TILESET_CELL_WIDTH, this.m_CurrentPath.Peek().Y * Tileset.TILESET_CELL_HEIGHT);
                if (true /*u == null || u == this*/) // FIXME: Units should path around obstacles.
                {
                    // Calculate relative vector to the target.
                    Vector2 max = new Vector2(
                        this.m_CurrentPath.Peek().X * Tileset.TILESET_CELL_WIDTH - this.X,
                        this.m_CurrentPath.Peek().Y * Tileset.TILESET_CELL_HEIGHT - this.Y
                    );

                    // Debugging information.
                    (world as RTSWorld).UiManager.Log("unit is moving to " + this.m_CurrentPath.Peek() + ".");

                    // If we are closer to the target than our move speed, jump directly to
                    // it and pop the target location.
                    if (max.Length() < this.MoveSpeed)
                    {
                        // Move direct.
                        this.X += max.X;
                        this.Y += max.Y;
                        this.m_CurrentPath.Pop();
                    } else
                    {
                        // Normalize the vector and multiply by the movement speed.
                        max.Normalize();
                        max *= this.MoveSpeed;
                        this.X += max.X;
                        this.Y += max.Y;
                    }
                }

                // Reset list if needed.
                if (this.m_CurrentPath.Count == 0)
                    this.m_CurrentPath = null;
            }

            base.Update(world);
        }
예제 #24
0
        public override void Update(World world)
        {
            this.m_World = world as RedMeansGoWorld;
            base.Update(world);

            // Game pace is set by player health...  reduce it very very slowly.
            this.Health -= 0.0001;

            //this.PowerupColor = new Color((float)m_Random.NextDouble(), (float)m_Random.NextDouble(), (float)m_Random.NextDouble());
            if (this.Health <= 0)
                this.PowerupColor = new Color(127, 127, 127);
            else
                this.Rotation += 0.1 * ((1 - this.Health) * 0.3 + 1);

            double heartbeat = (world as RedMeansGoWorld).Heartbeats.Current;
            if (this.Health <= 0)
                heartbeat = -0.4; // You're dead :(
            this.Width = (int)(WIDTH * (heartbeat * 0.15 + 1));
            this.Height = (int)(HEIGHT * (heartbeat * 0.15 + 1));
            //this.Origin = new Vector2(this.Width / 2, this.Height / 2);

            if (this.X < RedMeansGoGame.GAME_WIDTH / 2)
            {
                foreach (var e in world.Entities)
                    e.X += Tileset.TILESET_PIXEL_WIDTH - RedMeansGoGame.GAME_WIDTH;
            }
            if (this.X > Tileset.TILESET_PIXEL_WIDTH - RedMeansGoGame.GAME_WIDTH / 2)
            {
                foreach (var e in world.Entities)
                    e.X -= Tileset.TILESET_PIXEL_WIDTH - RedMeansGoGame.GAME_WIDTH;
            }
            if (this.Y > Tileset.TILESET_PIXEL_HEIGHT - RedMeansGoGame.GAME_HEIGHT / 2)
                this.Y = Tileset.TILESET_PIXEL_HEIGHT - RedMeansGoGame.GAME_HEIGHT / 2;
            if (this.Y < RedMeansGoGame.GAME_HEIGHT / 2)
            {
                foreach (var e in world.Entities)
                    e.Y += Tileset.TILESET_PIXEL_HEIGHT - RedMeansGoGame.GAME_HEIGHT;
            }
        }
예제 #25
0
        public override void Update(World world)
        {
            // Check to see if we're attacking anything,
            if (this.AttackTarget != null && this.AttackTarget.Team != this.Team && !this.Killed)
            {
                // Check to see if we need to move closer.
                if ((new Vector2(this.AttackTarget.X, this.AttackTarget.Y) - new Vector2(this.X, this.Y)).Length() > this.AttackRange)
                {
                    // Need to move closer, find a spot near the unit that
                    // is currently free.
                    if (this is MovableUnit)
                    {
                        // Check to make sure we're not already moving.
                        if (!(this as MovableUnit).MoveIsPathing)
                        {
                            (this.Level.World as RTSWorld).UiManager.Log("unit started pathing toward attack target.");
                            (this as MovableUnit).MoveTo(new Vector2(this.AttackTarget.X, this.AttackTarget.Y));
                        }
                        else
                            (this.Level.World as RTSWorld).UiManager.Log("unit attacking, out-of-range and pathing.");
                    }
                    else
                    {
                        (this.Level.World as RTSWorld).UiManager.Log("immovable unit attempting to attack unit outside range; cancelling.");
                        this.AttackTarget = null;
                    }
                }
                else
                {
                    // Otherwise, we are in range of the attack target, so we
                    // can kill it.
                    // TODO: Use a timer with attack speed here.
                    (this.Level.World as RTSWorld).UiManager.Log("unit damaging it's attack target.");
                    if (this is MovableUnit)
                        (this as MovableUnit).MoveCancel();
                    this.AttackTarget.Damage(this, this.AttackPower);
                }
            }

            base.Update(world);
        }
예제 #26
0
 public bool CollidesWithSolidAt(World world, int x, int y)
 {
     return Helpers.CollidesWithSolidAt(this, world, x, y);
 }
예제 #27
0
 public virtual void MoveDown(World world)
 {
     this.Y += this.PlayerMovementSpeed;
 }
예제 #28
0
 public virtual void Jump(World world)
 {
     if (this.TouchingGroundLastStep && !this.CollidesWithSolidAt(world, (int)this.X, (int)this.Y - 16))
         this.YSpeed = -this.PlayerJumpSpeed;
 }
예제 #29
0
 public void Fire(World world, Player player)
 {
     world.Entities.Add(new StrangeBullet { X = player.X, Y = player.Y });
 }
예제 #30
0
 public virtual void Action(World world)
 {
 }