public MainGameWindow()
            : base(800, 600, GraphicsMode.Default, "Sea battles")
        {
            Resize += delegate(object sender, EventArgs e)
            {
                // Note that we cannot call any OpenGL methods directly. What we can do is set
                // a flag and respond to it from the rendering thread.
                lock (update_lock)
                {
                    viewport_changed = true;
                    viewport_width = this.ClientRectangle.Width;
                    viewport_height = this.ClientRectangle.Height;
                }
            };

            handlers.Add(typeof(TraceText), WriteTitle);
            handlers.Add(typeof(ButtonUp), HandleButtonUp);
            mainCamera = new Camera(0, 0, 1, 800, 600);
            input = new InputLayer(this);

            ship = Ship.Create(new PointF(0, 0), 40, 10);
            ship2 = Ship.Create(new PointF(0, 0), 40, 1);

            ship.Name = "player";
            ship.Graphics.Name = "player graphics";
            ship2.Graphics.Name = "enemy graphics";
            //box = new TestBoundingObject(BoundShape.Ship, new PointF(0, 0), 10, 20, Color.Green, Color.Red, 0);
            //box2 = new TestBoundingObject(BoundShape.Circle, new PointF(0, 0), 20, 40, Color.White, Color.Black, -0.5f);

            //MessageDispatcher.RegisterHandler(typeof(ButtonDown), box);
            //MessageDispatcher.RegisterHandler(typeof(SetPosition), box);
            //MessageDispatcher.RegisterHandler(typeof(SetSpeed), box);
            //MessageDispatcher.RegisterHandler(typeof(GetOwnerPosition), box);
            //MessageDispatcher.RegisterHandler(typeof(InformPosition), box);
            //MessageDispatcher.RegisterHandler(typeof(BoundSetCollision), box);
            //MessageDispatcher.RegisterHandler(typeof(BoundSetNotCollision), box);

            //---------------------------------------------------
            //graphicsAspects.Add(ship.Graphics);

            //только корабль игрока подписывается на приём пользовательского ввода
            MessageDispatcher.RegisterHandler(typeof(ButtonDown), ship);
            MessageDispatcher.RegisterHandler(typeof(ButtonHold), ship);

            //MessageDispatcher.RegisterHandler(typeof(SetPosition), ship);
            //MessageDispatcher.RegisterHandler(typeof(SetSpeed), ship);
            //// нужно для определения координат и скорости корабля в момент выстрела
            //// в данном случае owner-ом является ship
            //MessageDispatcher.RegisterHandler(typeof(GetOwnerPosition), ship);
            //MessageDispatcher.RegisterHandler(typeof(InformPosition), ship);
            //MessageDispatcher.RegisterHandler(typeof(Shoot), ship);
            //MessageDispatcher.RegisterHandler(typeof(BoundSetCollision), ship);
            //MessageDispatcher.RegisterHandler(typeof(BoundSetNotCollision), ship);
            ////MessageDispatcher.RegisterHandler(typeof(SetPosition), anotherShip);

            MessageDispatcher.RegisterHandler(typeof(TraceText), this);
            MessageDispatcher.RegisterHandler(typeof(ButtonUp), this);

            //timer = new System.Threading.Timer(new TimerCallback(timer_Tick), null, 1000, 1000);
        }
Beispiel #2
0
        public static Ship Create(PointF position, float length, float width)
        {
            Ship aspect = new Ship(position, length, width);

            MessageDispatcher.RegisterHandler(typeof(SetPosition), aspect);
            MessageDispatcher.RegisterHandler(typeof(SetSpeed), aspect);
            MessageDispatcher.RegisterHandler(typeof(SetAcceleration), aspect);
            MessageDispatcher.RegisterHandler(typeof(AddForwardAcceleration), aspect);
            MessageDispatcher.RegisterHandler(typeof(ApplyForce), aspect);
            // нужно для определения координат и скорости корабля в момент выстрела
            // в данном случае owner-ом является ship
            MessageDispatcher.RegisterHandler(typeof(GetOwnerPosition), aspect);
            MessageDispatcher.RegisterHandler(typeof(InformPosition), aspect);
            MessageDispatcher.RegisterHandler(typeof(Shoot), aspect);
            MessageDispatcher.RegisterHandler(typeof(BoundSetCollision), aspect);
            MessageDispatcher.RegisterHandler(typeof(BoundSetNotCollision), aspect);
            MessageDispatcher.RegisterHandler(typeof(Ship), aspect);
            MessageDispatcher.RegisterHandler(typeof(Kill), aspect);

            aspect.RegisterAllStuff();

            return aspect;
        }