コード例 #1
0
ファイル: SelectLevelView.cs プロジェクト: WebFreak001/LD-30
        public SelectLevelView(MainMenuView menu)
        {
            scene = new Scene(ScrollInputs.None);
            Font text = new Font("Content/font.ttf");
            (backButton = new FastButton(text, 22, "Content/button.png", "Content/button_hover.png", "Content/button_pressed.png")
            {
                Position = new Vector2f(500, 600),
                Size = new Vector2f(280, 49),
                Text = "Back to Menu",
                Anchor = AnchorPoints.Left | AnchorPoints.Top
            }).OnClick += BackToMenu;

            string[] files = Directory.GetFiles("Content/Levels/", "*.json");
            for (int i = 0; i < files.Length; i++)
            {
                string file = files[i];
                string name = JsonConvert.DeserializeObject<GameScene>(File.ReadAllText(file)).Name;
                FastButton level = new FastButton(text, 22, "Content/button.png", "Content/button_hover.png", "Content/button_pressed.png")
                {
                    Position = new Vector2f(300, 50 + i * 50),
                    Size = new Vector2f(680, 49),
                    Text = "Play " + name,
                    Anchor = AnchorPoints.Left | AnchorPoints.Top
                };
                level.OnClick += (s, e) =>
                {
                    Next(this, new InGameView(file, this));
                };

                scene.AddComponent(level);
            }

            scene.AddComponent(backButton);
            this.menu = menu;
        }
コード例 #2
0
ファイル: SettingsView.cs プロジェクト: WebFreak001/LD-30
        public SettingsView(MainMenuView menu)
        {
            if (File.Exists("settings.json"))
                settings = JsonConvert.DeserializeObject<GameSettings>(File.ReadAllText("settings.json"));
            else
            {
                settings = new GameSettings();
                settings.EnableClouds = true;
            }

            scene = new Scene(ScrollInputs.None);
            (cloudButton = new FastButton(new Font("Content/font.ttf"), 22, "Content/button.png", "Content/button_hover.png", "Content/button_pressed.png")
            {
                Position = new Vector2f(500, 200),
                Size = new Vector2f(280, 49),
                Text = (settings.EnableClouds ? "Disable" : "Enable") + " Clouds",
                Anchor = AnchorPoints.Left | AnchorPoints.Top
            }).OnClick += ToggleClouds;

            (volDownButton = new FastButton(new Font("Content/font.ttf"), 22, "Content/button.png", "Content/button_hover.png", "Content/button_pressed.png")
            {
                Position = new Vector2f(500, 300),
                Size = new Vector2f(40, 49),
                Text = "-",
                Anchor = AnchorPoints.Left | AnchorPoints.Top
            }).OnClick += VolumeDown;

            (volUpButton = new FastButton(new Font("Content/font.ttf"), 22, "Content/button.png", "Content/button_hover.png", "Content/button_pressed.png")
            {
                Position = new Vector2f(740, 300),
                Size = new Vector2f(40, 49),
                Text = "+",
                Anchor = AnchorPoints.Left | AnchorPoints.Top
            }).OnClick += VolumeUp;

            volumeIndicator = new FastText(new Font("Content/font.ttf"), 22)
            {
                Position = new Vector2f(550, 300),
                Size = new Vector2f(180, 49),
                TextAlignment = Alignment.MiddleCenter,
                Text = "Volume: " + settings.Volume + "%",
                Anchor = AnchorPoints.Left | AnchorPoints.Top
            };

            (menuButton = new FastButton(new Font("Content/font.ttf"), 22, "Content/button.png", "Content/button_hover.png", "Content/button_pressed.png")
            {
                Position = new Vector2f(500, 500),
                Size = new Vector2f(280, 49),
                Text = "Back",
                Anchor = AnchorPoints.Left | AnchorPoints.Bottom
            }).OnClick += MenuClick;

            scene.AddComponent(cloudButton);
            scene.AddComponent(menuButton);
            scene.AddComponent(volDownButton);
            scene.AddComponent(volUpButton);
            scene.AddComponent(volumeIndicator);
            this.menu = menu;
        }
コード例 #3
0
ファイル: MainMenuView.cs プロジェクト: WebFreak001/LD-30
        public MainMenuView()
        {
            scene = new Scene(ScrollInputs.None);

            (playButton = new FastButton(new Font("Content/font.ttf"), 22, "Content/button.png", "Content/button_hover.png", "Content/button_pressed.png")
            {
                Position = new Vector2f(500, 200),
                Size = new Vector2f(280, 49),
                Text = "Play",
                Anchor = AnchorPoints.Left | AnchorPoints.Top
            }).OnClick += PlayButton_OnClick;

            (settingsButton = new FastButton(new Font("Content/font.ttf"), 22, "Content/button.png", "Content/button_hover.png", "Content/button_pressed.png")
            {
                Position = new Vector2f(500, 260),
                Size = new Vector2f(280, 49),
                Text = "Settings",
                Anchor = AnchorPoints.Left | AnchorPoints.Top
            }).OnClick += SettingsButton_OnClick;

            (quitButton = new FastButton(new Font("Content/font.ttf"), 22, "Content/button.png", "Content/button_hover.png", "Content/button_pressed.png")
            {
                Position = new Vector2f(500, 320),
                Size = new Vector2f(280, 49),
                Text = "Quit",
                Anchor = AnchorPoints.Left | AnchorPoints.Top
            }).OnClick += QuitButton_OnClick;

            scene.AddComponent(playButton);
            scene.AddComponent(settingsButton);
            scene.AddComponent(quitButton);

            particles = new IndexedParticleSystem();
            particle = new Sprite(new Texture("Content/particle.png"));
            particle.Origin = new Vector2f(32, 32);

            particleEmitter = new Emitter();
            particleEmitter.Position = new Vector2f(50, 50);
            particleEmitter.ParticlesSpawnRate = 200;
            particleEmitter.Spread = 30;
            particleEmitter.Color = Color.Blue;
            particles.AddEmitter(particleEmitter);

            greenEmitter = new Emitter();
            greenEmitter.Position = new Vector2f(50, 50);
            greenEmitter.ParticlesSpawnRate = 150;
            greenEmitter.Spread = 30;
            greenEmitter.Color = Colors.Lime;
            particles.AddEmitter(greenEmitter);

            bg = new Sprite();
            particleTexture = new RenderTexture(1280, 720);
            particleTexture.Clear(Color.Blue);
        }
コード例 #4
0
    void Start()
    {
        SlowArrow   = SlowButton.GetComponent <Image> ();
        MediumArrow = MediumButton.GetComponent <Image> ();
        FastArrow   = FastButton.GetComponent <Image> ();

        if (OscarSpeed.Instance.Speed == OscarSpeed.Slow)
        {
            slowChanges();
        }
        else if (OscarSpeed.Instance.Speed == OscarSpeed.Medium)
        {
            mediumChanges();
        }
        else if (OscarSpeed.Instance.Speed == OscarSpeed.Fast)
        {
            fastChanges();
        }
    }
コード例 #5
0
ファイル: LevelEditor.cs プロジェクト: WebFreak001/LD-30
        public void Run()
        {
            window = new RenderWindow(new VideoMode(1280, 720), "DOX30 Editor", Styles.Titlebar | Styles.Close);
            window.Closed += window_Closed;
            window.Resized += window_Resized;
            window.MouseWheelMoved += window_MouseWheelMoved;
            window.MouseButtonPressed += window_MouseButtonPressed;
            window.MouseMoved += window_MouseMoved;
            window.MouseButtonReleased += window_MouseButtonReleased;
            window.KeyPressed += window_KeyPressed;
            window.KeyReleased += window_KeyReleased;

            world = new PhysicsWorld(true);

            ui = new UISceneManager();
            ui.Init(window);
            Scene scene = new Scene(ScrollInputs.None);
            RectControl bg = new RectControl() { Position = new Vector2f(0, 0), Size = new Vector2f(1280, 50), Anchor = AnchorPoints.Left | AnchorPoints.Top | AnchorPoints.Right, BackgroundColor = Colors.WhiteSmoke };

            FastButton runButton = new FastButton(new Font("Content/font.ttf"), 22, "Content/playButton.png", "Content/playButton.png", "Content/playButton.png") { Position = new Vector2f(0, 0), Size = new Vector2f(50, 48), Text = "", Anchor = AnchorPoints.Left | AnchorPoints.Top };
            runButton.OnClick += (s, e) => { enabled = true; };
            FastButton pauseButton = new FastButton(new Font("Content/font.ttf"), 22, "Content/pauseButton.png", "Content/pauseButton.png", "Content/pauseButton.png") { Position = new Vector2f(50, 0), Size = new Vector2f(50, 48), Text = "", Anchor = AnchorPoints.Left | AnchorPoints.Top };
            pauseButton.OnClick += (s, e) => { enabled = false; };
            FastButton saveButton = new FastButton(new Font("Content/font.ttf"), 22, "Content/saveButton.png", "Content/saveButton.png", "Content/saveButton.png") { Position = new Vector2f(125, 0), Size = new Vector2f(50, 48), Text = "", Anchor = AnchorPoints.Left | AnchorPoints.Top };
            saveButton.OnClick += (s, e) => { Export(); };
            FastButton loadButton = new FastButton(new Font("Content/font.ttf"), 22, "Content/loadButton.png", "Content/loadButton.png", "Content/loadButton.png") { Position = new Vector2f(175, 0), Size = new Vector2f(50, 48), Text = "", Anchor = AnchorPoints.Left | AnchorPoints.Top };
            loadButton.OnClick += (s, e) =>
            {
                var ofd = new System.Windows.Forms.OpenFileDialog();
                ofd.Filter = "Level Files (*.json)|*.json";
                ofd.InitialDirectory = Directory.GetCurrentDirectory();
                var r = ofd.ShowDialog();
                if (r == System.Windows.Forms.DialogResult.OK)
                {
                    Import(ofd.FileName);
                }
            };
            FastButton addBoxButton = new FastButton(new Font("Content/font.ttf"), 22, "Content/boxButton.png", "Content/boxButton.png", "Content/boxButton.png") { Position = new Vector2f(250, 0), Size = new Vector2f(50, 48), Text = "", Anchor = AnchorPoints.Left | AnchorPoints.Top };
            addBoxButton.OnClick += (s, e) => { world.CreateBox(new Vector2f(10, 10), 4, BodyType.Static).Position = new Vector2(offset.X, offset.Y) * -0.1f; world.Step(0); };
            FastButton addCircleButton = new FastButton(new Font("Content/font.ttf"), 22, "Content/circleButton.png", "Content/circleButton.png", "Content/circleButton.png") { Position = new Vector2f(300, 0), Size = new Vector2f(50, 48), Text = "", Anchor = AnchorPoints.Left | AnchorPoints.Top };
            addCircleButton.OnClick += (s, e) => { world.CreateCircle(5, 5, BodyType.Static).Position = new Vector2(offset.X, offset.Y) * -0.1f; world.Step(0); };

            scene.AddComponent(bg);
            scene.AddComponent(runButton);
            scene.AddComponent(pauseButton);
            scene.AddComponent(addBoxButton);
            scene.AddComponent(addCircleButton);
            scene.AddComponent(saveButton);
            scene.AddComponent(loadButton);
            // scene.AddComponent(new WorldHierachyRenderer(world) { Size = new Vector2f(300, 670), Position = new Vector2f(0, 50), BackgroundColor = Colors.Snow });
            // Does not update on change dynamic/static
            ui.CurrentScene = scene;

            grid = new Sprite(new Texture("Content/grid.png"));
            grid.Origin = new Vector2f(512, 512);

            contextMenu = new ContextMenu();
            contextMenu.Add(() =>
            {
                selected.BodyType = BodyType.Dynamic;
            }, "Set Dynamic");
            contextMenu.Add(() =>
            {
                selected.BodyType = BodyType.Static;
            }, "Set Static");
            contextMenu.Add(() =>
            {
                world.FindBody(selected).GameDimension = Dimension.None;
            }, "Set No Dimension");
            contextMenu.Add(() =>
            {
                world.FindBody(selected).GameDimension = world.FindBody(selected).GameDimension == Dimension.OneO ? Dimension.TwoX : Dimension.OneO;
            }, "Switch Dimension");
            contextMenu.Add(() =>
            {
                selected.Rotation += 0.0872664626f;
            }, "+5 Rotation");
            contextMenu.Add(() =>
            {
                selected.Rotation += 0.785398163f;
            }, "+45 Rotation");
            contextMenu.Add(() =>
            {
                selected.Rotation -= 0.0872664626f;
            }, "-5 Rotation");
            contextMenu.Add(() =>
            {
                selected.Rotation -= 0.785398163f;
            }, "-45 Rotation");
            contextMenu.Add(() =>
            {
                world.Copy(selected, new Vector2(offset.X, offset.Y) * -0.1f);
            }, "Duplicate");
            contextMenu.Add(() =>
            {
                world.Remove(selected);
            }, "Remove");

            messageScene = new Scene(ScrollInputs.None);

            Stopwatch sw = new Stopwatch();
            TimeSpan elapsed = TimeSpan.Zero;
            TimeSpan secondCounter = TimeSpan.Zero;
            int frames = 0;
            world.Step(0);

            View v;
            Console.WriteLine(window.GetView().Center);

            while (window.IsOpen())
            {
                sw.Start();
                window.DispatchEvents();
                window.Clear();

                if (enabled)
                    world.Step((float)elapsed.TotalSeconds);

                v = window.GetView();
                v.Zoom(zoom);
                v.Center = (world.CamLock == null ? -offset : new Vector2f(world.CamLock.Position.X * 10, world.CamLock.Position.Y * 10));
                if (world.CamLock != null) v.Rotation = world.CamLock.Rotation * 57.2957795f;
                else v.Rotation = 0;
                window.SetView(v);

                window.Draw(grid);

                world.Render(window);

                v = window.GetView();
                v.Size = new Vector2f(1280, 720);
                v.Rotation = 0;
                v.Center = new Vector2f(640, 360);
                window.SetView(v);

                ui.Render(window);
                ui.CurrentScene = messageScene;
                ui.Render(window);
                ui.CurrentScene = scene;
                contextMenu.Render(window);

                window.Display();
                sw.Stop();
                elapsed = sw.Elapsed;
                secondCounter += elapsed;
                frames++;
                if (secondCounter >= TimeSpan.FromSeconds(1))
                {
                    Console.WriteLine(frames / secondCounter.TotalSeconds);
                    secondCounter -= TimeSpan.FromSeconds(1);
                    frames = 0;
                }
                sw.Reset();
            }
        }