示例#1
0
        public override void update(float time, int[,] tileMap, ref RenderWindow a, ref FieldMap h, Player1 ob1, Player2 ob2, GameHistory history)
        {
            Control(history);

            switch (dir)
            {
            case 0:
                dx = currentSpeed;
                dy = 0;
                break;

            case 1:
                dx = -currentSpeed;
                dy = 0;

                break;

            case 2:
                dx = 0;
                dy = currentSpeed;
                break;

            case 3:
                dx = 0;
                dy = -currentSpeed;
                break;

            default:
                break;
            }

            x += dx * time;
            y += dy * time;

            currentSpeed = 0;


            СorrectionPosition();

            sprite.Position = new Vector2f(x, y);

            if (PlayersCollisium(ob1, ob2))
            {
                if (dir == 1)
                {
                    sprite.Position = new Vector2f(x += 2, y);
                }
                else if (dir == 0)
                {
                    sprite.Position = new Vector2f(x -= 2, y);
                }

                if (dir == 3)
                {
                    sprite.Position = new Vector2f(x, y += 2);
                }
                else if (dir == 2)
                {
                    sprite.Position = new Vector2f(x, y -= 2);
                }
            }

            interactionWithMap(tileMap, ref a);
        }
示例#2
0
        //Основыне методы
        public virtual void update(float time, int[,] tileMap, ref RenderWindow a, ref FieldMap h, Player1 ob1, Player2 ob2, GameHistory history)
        {
            Control(history);

            switch (dir)
            {
            case (int)state.right:
                dx = currentSpeed;
                dy = 0;
                break;

            case (int)state.left:
                dx = -currentSpeed;
                dy = 0;
                break;

            case (int)state.down:
                dx = 0;
                dy = currentSpeed;
                break;

            case (int)state.up:
                dx = 0;
                dy = -currentSpeed;
                break;

            default:
                break;
            }

            x           += dx * time;
            y           += dy * time;
            currentSpeed = 0;


            //Тестируемый блок
            СorrectionPosition();

            sprite.Position = new Vector2f(x, y);

            if (PlayersCollisium(ob1, ob2))
            {
                if (dir == 1)
                {
                    sprite.Position = new Vector2f(x += 2, y);
                }
                else if (dir == 0)
                {
                    sprite.Position = new Vector2f(x -= 2, y);
                }

                if (dir == 3)
                {
                    sprite.Position = new Vector2f(x, y += 2);
                }
                else if (dir == 2)
                {
                    sprite.Position = new Vector2f(x, y -= 2);
                }
            }

            interactionWithMap(tileMap, ref a);
        }
示例#3
0
        static void Main(string[] args)
        {
            //------------------------------------------------Bound Code------------------------------------------------//
            window = new RenderWindow(new VideoMode(1280, 800), "Battle City");
            window.SetVerticalSyncEnabled(true);
            window.Closed += WinClosed;

            Image icon = new Image("..\\Source\\Textures\\panzer.png");

            window.SetIcon(64, 64, icon.Pixels);

            musicThemes = new [] { new Music("..\\Source\\Sounds\\theme1.ogg"), new Music("..\\Source\\Sounds\\theme2.ogg") };

            Thread musicThread = new Thread(new ThreadStart(SwitchMusic));

            musicThread.Start();

            GameHistory history = new GameHistory();


            //------------------------------------------------Game Code------------------------------------------------//

            FieldMap map = new FieldMap("map.png");

            Player1 player1 = new Player1("players1.png", "Vitaliy", true, Color.Green, 544, 732);

            Player2 player2 = new Player2("players1.png", "Davidiy", true, Color.Red, 672, 38);

            Clock clock = new Clock();

            Debug f = new Debug();


            while (window.IsOpen)
            {
                window.DispatchEvents();
                float time = clock.ElapsedTime.AsMicroseconds();
                clock.Restart();
                time = time / 800;


                player1.update(time, map.tileMap, ref window, ref map, player1, player2, history);
                player2.update(time, map.tileMap, ref window, ref map, player1, player2, history);
                if (player1.isShoot)
                {
                    player1.bullet.update(time, map.tileMap, ref window, player1, player2);
                }

                f.FConsole("P1 \n X - " + player1.X + " Y - " + player1.Y + "\n\nP2 \n X - " + player2.X + " Y - " + player2.Y);


                //window.Clear(Color.Black);
                //------------------------------------------------Draw Code------------------------------------------------//

                map.Draw(ref window);
                window.Draw(player1.Sprite);
                window.Draw(player2.Sprite);
                if (player1.isShoot)
                {
                    window.Draw(player1.bullet.Sprite);
                }
                f.Print();

                //------------------------------------------------Show Code------------------------------------------------//
                window.Display();
            }
        }