public void change(bEntity e)
 {
     active = !active;
     if (active)
         onActivate(e);
     else
         onDeactivate(e);
 }
 public virtual bool collides(bEntity e, string[] categories, Func<bEntity, bEntity, bool> condition = null)
 {
     foreach (string category in categories)
         if (entities[category] != null)
             foreach (bEntity ge in entities[category])
                 if (ge != e && ge.collidable && e.collides(ge) && (condition == null || condition(e, ge)))
                     return true;
     return false;
 }
Пример #3
0
        public override void init()
        {
            entities.Clear();
            entities.Add("solid", new List<bEntity>());

            aiPlayer = new AIPlayer();

            players = new Ringo[2];
            players[0] = new Ringo(50, 70);
            _add(players[0], "solid");
            players[0].controls = aiPlayer.controls;
            //players[0].controls.down = delegate
            //{
            //    //return GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y < -bGame.input.getJoystickDeadzone();
            //    return bGame.input.check(Keys.Up);
            //};
            //players[0].controls.up = delegate
            //{
            //    //return GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y > bGame.input.getJoystickDeadzone();
            //    return bGame.input.check(Keys.Down);
            //};

            players[1] = new Ringo(90, 70, Ringo.Dir.Left);
            players[1].controls.A = delegate { return bGame.input.pressed("A2"); };
            players[1].controls.B = delegate { return bGame.input.pressed("B2"); };
            players[1].controls.up = delegate {
                //return GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y < -bGame.input.getJoystickDeadzone();
                return bGame.input.check(Keys.Up);
            };
            players[1].controls.down = delegate
            {
                //return GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y > bGame.input.getJoystickDeadzone();
                return bGame.input.check(Keys.Down);
            };
            players[1].controls.left = delegate { return bGame.input.check(Keys.Left); };
            players[1].controls.right = delegate { return bGame.input.check(Keys.Right); };
            _add(players[1], "solid");

            players[1].life = 10;
            players[1].playerNo = 1;

            bg = new bStamp(game.Content.Load<Texture2D>("ring_bg"));
            fg = new bStamp(game.Content.Load<Texture2D>("ring_fg"));

            int wallw = 20;
            bEntity wall_1 = new bEntity(-wallw, 0);
            wall_1.mask.w = wallw;
            wall_1.mask.h = game.getHeight();
            bEntity wall_2 = new bEntity(game.getWith(), 0);
            wall_2.mask.w = wallw;
            wall_2.mask.h = game.getHeight();

            _add(wall_1, "solid");
            _add(wall_2, "solid");

            MediaPlayer.Play((game as Rin).bgSong);
        }
 public virtual void actuallyRemove(bEntity e)
 {
     String c = categories[e];
     if (c != null)
     {
         entities[c].Remove(e);
         categories.Remove(e);
     }
 }
 public virtual bEntity instanceCollision(bEntity e, string[] categories, string attr = null, Func<bEntity, bEntity, bool> condition = null)
 {
     foreach (string category in categories)
         if (entities[category] != null)
             foreach (bEntity ge in entities[category])
                 if (ge != e && ge.collidable && e.collides(ge) && (condition == null || condition(e, ge)))
                     if (attr == null || ge.hasAttribute(attr))
                         return ge;
     return null;
 }
 public virtual bool add(bEntity ge, String category)
 {
     birthRow.Add(new Pair<bEntity, String>(ge, category));
     return true;
 }
Пример #7
0
 // invalidate method to use body mask
 public override bool collides(bEntity other)
 {
     return true;
 }
 public virtual void onCollision(String type, bEntity other, Pair<bBody, bBody>[] collisionPairs)
 {
 }
Пример #9
0
        protected override bool _add(bEntity e, string category)
        {
            entities[category].Add(e);

            return base._add(e, category);
        }
 protected bool isPlayerEntity(bEntity self, bEntity other)
 {
     return (other is Player);
 }
 protected bool solidCheck(bEntity self, bEntity other)
 {
     if (other is Entity)
         return (other as Entity).solid;
     else
         return true;
 }
 public void onDeactivate(bEntity e)
 {
 }
 public bool onewaysolidCondition(bEntity me, bEntity other)
 {
     if (me is PickableBlock)
     {
         PickableBlock p = me as PickableBlock;
         return (p.initialPosition.Y + p.mask.offsety + me.mask.h <= other.mask.y);
     }
     else
         return true;
 }
 public void onActivate(bEntity e)
 {
 }
 public void deactivate(bEntity e)
 {
     active = false;
     onDeactivate(e);
 }
 public override void onEndCarry()
 {
     _graphic.play("walk");
     collidable = true;
     carrierEntity = null;
 }
 public void activate(bEntity e)
 {
     active = true;
     onActivate(e);
 }
 public override void onInitCarry(bEntity other)
 {
     _graphic.play("carried");
     collidable = false;
     if (other is ICarrier)
         carrierEntity = other;
 }
 public virtual void onInitCarry(bEntity other)
 {
     collidable = false;
 }
 public virtual List<bEntity> instancesCollision(bEntity e, string category, string attr = null, Func<bEntity, bEntity, bool> condition = null)
 {
     return instancesCollision(e, new string[] { category }, attr, condition);
 }
 protected bool activableCheck(bEntity self, bEntity other)
 {
     return (other is IActivable);
 }
        public virtual List<bEntity> instancesCollision(bEntity e, string[] categories, string attr = null, Func<bEntity, bEntity, bool> condition = null)
        {
            List<bEntity> result = new List<bEntity>();

            foreach (string category in categories)
                if (entities[category] != null)
                    foreach (bEntity ge in entities[category])
                        if (ge != e && ge.collidable && e.collides(ge) && (condition == null || condition(e, ge)))
                            if (attr == null || ge.hasAttribute(attr))
                                result.Add(ge);

            return result;
        }
Пример #23
0
 public virtual void onCollision(String type, bEntity other)
 {
 }
        public virtual bool isInstanceInView(bEntity e)
        {
            // TODO: Handle invisible and not managed by world entities

            return true;
        }
Пример #25
0
 public virtual bool collides(bEntity other)
 {
     return this.mask.collides(other.mask);
 }
 public virtual void remove(bEntity e)
 {
     deathRow.Add(e);
 }
        protected virtual bool _add(bEntity e, String category)
        {
            // Store container list
            categories[e] = category;

            e.world = this;
            e.game = this.game;
            e.init();
            return true;
        }
Пример #28
0
        public override void onCollision(string type, bEntity other, Pair<bBody, bBody>[] collisionPairs)
        {
            base.onCollision(type, other, collisionPairs);

            if (!type.Equals("fists") || actionState == ActionState.punchReturn)
                return;

            // Pairs are (other, me), always dealing with bodies
            bool hitHead = false;
            foreach (Pair<bBody, bBody> item in collisionPairs)
            {
                if (item.second.name.Equals("fists"))
                {
                    (other as Ringo).body.attached["fists"].bodyPart.currentAnim.speed *= -1;
                    (other as Ringo).actionState = ActionState.punchReturn;

                    SoundEffect soundEffect;
                    soundEffect = game.Content.Load<SoundEffect>("fist-fist");
                    soundEffect.Play();
                    return;
                }
                else if (item.second.name.Equals("head"))
                {
                    hitHead = true;
                }
            }

            if (collisionPairs.Count() >= 1 && (other as Ringo).myHit != hisHit)
            {
                SoundEffect soundEffect;
                soundEffect = game.Content.Load<SoundEffect>("fist-body");
                soundEffect.Play();

                // right punch is shorter but deals more damage
                // head hurts the most
                int damage = 1;
                if (hitHead)
                {
                    body.attached["head"].bodyPart.play("damage");
                    damage = 3;
                    headDamaged = true;
                }
                else
                {
                    if ((other as Ringo).myHit % 2 == 0)
                    {
                        // right punch
                        damage = 1;
                    }
                    else
                    {
                        // left punch
                        damage = 2;
                    }

                    bodyDamaged = true;
                    body.play("damage");
                }
                life = Math.Max(0, life - damage);

                if (life == 0)
                {
                    actionState = ActionState.dead;
                }

                hisHit = (other as Ringo).myHit;
            }
        }