Exemplo n.º 1
0
 public bool Play()
 {
     if (!IsPlaying)
     {
         lasttime = CurrentTime;
         _audio.Play();
         _hasPlayed = true;
         return(true);
     }
     return(false);
 }
Exemplo n.º 2
0
 public Opening()
 {
     _music = new HTMLAudioElement()
     {
         Src = Resource.Audio.Theme
     };
     _music.Play();
     _music.AddEventListener(EventType.Ended, ev =>
     {
         _musicPlayed = true;
         _timePassed  = 0;
     });
 }
Exemplo n.º 3
0
        public static void OnReady()
        {
            // If we're hosted in a page with a start button, hook it up. Otherwise, start.
            var startButton = Document.GetElementById <HTMLButtonElement>("start-dachip8js-game");

            if (startButton != null)
            {
                startButton.OnClick = delegate(MouseEvent <HTMLButtonElement> e) { startButton.Style.Display = Display.None; StartGame(); beep.Play(); }
            }
            ;
            else
            {
                StartGame();
            }
        }
Exemplo n.º 4
0
        public void Blast(float volume = 1f)
        {
            var T = App.totalTime;

            if (T - lasttime < 150)
            {
                return;//prevent audio spam.
            }
            if (!IsPlaying)
            {
                Volume = volume;
                Play();
                lasttime = T;
            }
            else
            {
                //((AudioElement)_audio.CloneNode()).Play();
                int i = 0;
                while (i < _blast.Count)
                {
                    HTMLAudioElement A = _blast[i];
                    //if (A.Paused || A.CurrentTime<0.15f || A.Played.Length==0)
                    if (A.Paused || A.CurrentTime < 0.10f || A.Played.Length == 0)
                    {
                        if (A.Paused || A.CurrentTime == 0.0 || A.Played.Length == 0)
                        {
                            A.Volume = volume;
                            A.Play();
                            i        = _blast.Count;
                            lasttime = T;
                        }
                    }
                    i++;
                }
            }
        }
Exemplo n.º 5
0
        public void Draw()
        {
            if (_message == "")
            {
                return;
            }

            int brightness   = 0;
            var levelContext = _core.Layers.GetStageLayer(0).GetContext();
            var resolution   = _core.Resolution;

            if (!_resourcePool.Loaded)
            {
                levelContext.FillStyle = "rgb(" + (brightness) + "," + (brightness) + "," + (brightness) + ")";
                levelContext.FillRect(0, 0, resolution.Width, resolution.Height);                 // Clear
                levelContext.FillStyle = "white";
                levelContext.Font      = resolution.MultiplyClamp(10) + "px Consolas, monospace";
                levelContext.FillText("Loading...", resolution.MultiplyClamp(4), resolution.MultiplyClamp(12));
                return;
            }

            var data = Data.Instance;

            _image = _resourcePool.Images[Image.Background];
            _audio = _resourcePool.Audio[Audio.Theme];

            if (!_musicPlayed)
            {
                _musicPlayed = true;
                _audio.Play();
            }

            levelContext.DrawImage(_image, 0, 0);

            levelContext.FillStyle = "white";

            levelContext.Font = resolution.MultiplyClamp(10) + "px Consolas, monospace";
            levelContext.FillText("Playing Game", resolution.MultiplyClamp(4), resolution.MultiplyClamp(12));

            levelContext.Font = resolution.MultiplyClamp(20) + "px Consolas, monospace";
            levelContext.FillText("Score: " + data.Score, resolution.MultiplyClamp(4), resolution.MultiplyClamp(42));

            levelContext.Font = resolution.MultiplyClamp(4) + "px Consolas, monospace";
            levelContext.FillText("Press [UP] to win :)", resolution.MultiplyClamp(115), resolution.MultiplyClamp(36.5));

            levelContext.Font = resolution.MultiplyClamp(20) + "px Consolas, monospace";
            levelContext.FillText("Lives: " + data.Lives, resolution.MultiplyClamp(4), resolution.MultiplyClamp(72));

            levelContext.Font = resolution.MultiplyClamp(4) + "px Consolas, monospace";
            levelContext.FillText("Press [DOWN] to lose :(", resolution.MultiplyClamp(107), resolution.MultiplyClamp(67));

            levelContext.Font = resolution.MultiplyClamp(4) + "px Consolas, monospace";
            levelContext.FillText($"'{_image.Width}x{_image.Height}'", resolution.MultiplyClamp(10), resolution.MultiplyClamp(20));

            levelContext.Font = resolution.MultiplyClamp(4) + "px Consolas, monospace";
            levelContext.FillText($"'{_audio.Duration}'", resolution.MultiplyClamp(10), resolution.MultiplyClamp(25));

            levelContext.Font = resolution.MultiplyClamp(6) + "px Consolas, monospace";
            levelContext.FillText(_message, resolution.MultiplyClamp(4), resolution.MultiplyClamp(96));

            if (!_renderedControls)
            {
                _core.RenderActions();
                _renderedControls = true;
            }
        }