Пример #1
0
Файл: game.cs Проект: tpsa/pwsg
        public int Update(KBState kb, long LastTicks)
        {
            // zrób coś ;>
            if (kb.escape == KeyState.PRESSED)
            {
                kb.enter = KeyState.FREE;
                g.MenuActive = true;
                return 0;
            }

            sec.Run();

            foreach (Player p in b.opponents)
                p.PerformMove();

            b.player.PerformMove(kb);

            if (b.player == null)
                return -1;
            else
                return 0;
        }
Пример #2
0
        public bool PerformMove(KBState kb)
        {
            long NowTicks = DateTime.Now.Ticks;
            long Difference = NowTicks - g.LastTicks;
            if (Difference < 0)
                throw new Exception("WTF?");

            float ms = Difference / 10000.0f;
            ms = Math.Min(ms, 50.0f);
            ms = Math.Max(ms, 0.0f);

            g.LastTicks = NowTicks;

            float oldXf = LocXf;
            float oldYf = LocYf;

            int homex = LocX;
            int homey = LocY;

            if (leave)
            {
                if (!LocatedXY(bombx, bomby))
                    leave = false;
            }

            if (kb.space == KeyState.PRESSED)
            {
                if (!(g.b.GetField(homex, homey) is Bomba))
                {
                    // TODO poprawić, że na szczególnych przypadkach z bomby wchodzi na bombę
                    g.b.SetField(homex, homey, new Bomba(g));
                    bombx = homex;
                    bomby = homey;
                    leave = true;
                }
            }

            if (kb.right == KeyState.PRESSED)
            {
                LocXf += ms * 0.1f;
                LocXf = Math.Min(45 * g.b.Width - 45, LocXf);
                MovePlayer(oldXf, oldYf, true);
            }

            if (kb.left == KeyState.PRESSED)
            {
                LocXf -= ms * 0.1f;
                LocXf = Math.Max(0.0f, LocXf);
                MovePlayer(oldXf, oldYf, true);
            }

            if (kb.up == KeyState.PRESSED)
            {
                LocYf -= ms * 0.1f;
                LocYf = Math.Max(0.0f, LocYf);
                MovePlayer(oldXf, oldYf, false);
            }

            if (kb.down == KeyState.PRESSED)
            {
                LocYf += ms * 0.1f;
                LocYf = Math.Min(45 * g.b.Height - 45, LocYf);
                MovePlayer(oldXf, oldYf, false);
            }

            int newX = LocX;
            int newY = LocY;

            Material matOld = g.b.GetField(homex, homey);
            Material matNew = g.b.GetField(newX, newY);

            Bonus bonOld = g.b.GetBonus(homex, homey);
            Bonus bonNew = g.b.GetBonus(newX, newY);

            if (matOld != null)
                matOld.triggerOutHandler();
            if (bonOld != null)
                bonOld.triggerOutHandler();

            if (matNew != null)
                matNew.triggerInHandler();
            if (bonNew != null)
                bonNew.triggerInHandler();

            return true;
        }