示例#1
0
        void keyDowned(KeyboardState ks)
        {
            mainTheatre.Enable(scn);
            int     k           = 5;
            Vector2 curPos      = mainHero.position;
            float   rotateAngle = 0;

            if (mainHero.State == ActorState.Move)
            {
                return;
            }
            if (ks.IsKeyDown(Keys.W))
            {
                curPos.Y -= k; rotateAngle = (float)Math.PI * 3 / 2;
            }
            if (ks.IsKeyDown(Keys.A))
            {
                curPos.X -= k; rotateAngle = (float)Math.PI;
            }
            if (ks.IsKeyDown(Keys.S))
            {
                curPos.Y += k; rotateAngle = (float)Math.PI / 2;
            }
            if (ks.IsKeyDown(Keys.D))
            {
                curPos.X += k; rotateAngle = 0;
            }
            mainHero.Rotate(rotateAngle);
            if ((curPos != mainHero.position) && !(scn.TryCollision(mainHero, curPos)))
            {
                mainHero.Move(curPos);
            }
        }
示例#2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            uc = new UserControl();
            LuaInterfacer li = new LuaInterfacer();
            li.SetGlobal("UserControl", uc);
            li.DoFile("./Content/init.lua");
            scn = li.CreateStage(spriteBatch, "main");
            mainTheatre.AddStage(scn);
            scn.CalibrateCollisions();
            scn.Reindex();
            //ResourceLoader rsldr = new ResourceLoader("./Content/init.lua");
            mainHero = li.actorList["Hero"];
            //scn = rsldr.CreateStage(spriteBatch,"main");

            uc.onKeydown += keyDowned;
            uc.onMouseLeftDown += mouseMoved;

            IsMouseVisible = true;

            mainHero.onCollision += onCollision;
            mainHero.onMove += onActorMoved;
            mainHero.speed = 0.5f;
            mainHero.RotateSpeed = 100;
            scn.onMapOut += onSomebodyMapout;
            mainHero.Rotate((float)(Math.PI*2/3));
            //makeMoveTest(mainHero);
            systemFont = Content.Load<SpriteFont>("Courier New");
            Text t1 = new Text("main hero");
            t1.position.Y = -50;
            t1.position.X = -50;
            mainHero.AddText(t1);

            int middleDisplay = GraphicsDevice.Viewport.Width/2;
            menu = new Stage(this.spriteBatch, 1024, 768, new Rectangle(0,0,400, 400));

            Button newGameButton = new Button("New game", GraphicsDevice, spriteBatch);
            newGameButton.BackgroundImage = "Plit.png";
            newGameButton.onClick += NewGameFunc;

            Button exitButton = new Button("Exit", GraphicsDevice, spriteBatch);
            exitButton.BackgroundImage = "Plit.png";
            exitButton.onClick += ExitFunc;

            Panel p = new Panel(GraphicsDevice.Viewport.Width,GraphicsDevice.Viewport.Height);
            p.position.Y = 10;
            p.AddControl(newGameButton);
            p.AddControl(exitButton);

            menu.AddControl(p);

            mainTheatre.AddStage(menu);

            mainTheatre.Disable(scn);
            //mainTheatre.Disable(menu);
        }
示例#3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            uc          = new UserControl();
            LuaInterfacer li = new LuaInterfacer();

            li.SetGlobal("UserControl", uc);
            li.DoFile("./Content/init.lua");
            scn = li.CreateStage(spriteBatch, "main");
            mainTheatre.AddStage(scn);
            scn.CalibrateCollisions();
            scn.Reindex();
            //ResourceLoader rsldr = new ResourceLoader("./Content/init.lua");
            mainHero = li.actorList["Hero"];
            //scn = rsldr.CreateStage(spriteBatch,"main");


            uc.onKeydown       += keyDowned;
            uc.onMouseLeftDown += mouseMoved;

            IsMouseVisible = true;

            mainHero.onCollision += onCollision;
            mainHero.onMove      += onActorMoved;
            mainHero.speed        = 0.5f;
            mainHero.RotateSpeed  = 100;
            scn.onMapOut         += onSomebodyMapout;
            mainHero.Rotate((float)(Math.PI * 2 / 3));
            //makeMoveTest(mainHero);
            systemFont = Content.Load <SpriteFont>("Courier New");
            Text t1 = new Text("main hero");

            t1.position.Y = -50;
            t1.position.X = -50;
            mainHero.AddText(t1);

            int middleDisplay = GraphicsDevice.Viewport.Width / 2;

            menu = new Stage(this.spriteBatch, 1024, 768, new Rectangle(0, 0, 400, 400));

            Button newGameButton = new Button("New game", GraphicsDevice, spriteBatch);

            newGameButton.BackgroundImage = "Plit.png";
            newGameButton.onClick        += NewGameFunc;

            Button exitButton = new Button("Exit", GraphicsDevice, spriteBatch);

            exitButton.BackgroundImage = "Plit.png";
            exitButton.onClick        += ExitFunc;

            Panel p = new Panel(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);

            p.position.Y = 10;
            p.AddControl(newGameButton);
            p.AddControl(exitButton);

            menu.AddControl(p);

            mainTheatre.AddStage(menu);

            mainTheatre.Disable(scn);
            //mainTheatre.Disable(menu);
        }