1. 02 Jan, 2016 2 commits
    • Terence Martin's avatar
      Include simplistic preload progress · d6a6434a
      Terence Martin authored
      Just as a quick change, when preloading if you provide the preloader
      with a stage, as the progress of the update changes, it wll display
      that to the stage to let you know that something is happening.
      This is currently just a simple bit of text that says how many files
      are left.
    • Terence Martin's avatar
      Fix preloader event "bug" · d4b34050
      Terence Martin authored
      The code in the preload that handles the file being loaded or an
      error removes the event handlers added to the image/audio tag at load
      This code was erroneously always removing the event listener for
      "load" even though for the audio tag we actually were using a
      different event, "canplaythrough".
      This doesn't hurt anything, but if you're going to do something, you
      might as well do it right, right?
  2. 31 Dec, 2015 1 commit
    • Terence Martin's avatar
      Catch errors in the preloader code · 520bedb2
      Terence Martin authored
      We now catch errors in the preload using appropriate event handlers.
      In the case that an image or sound cannot be loaded, a version from a
      data URL embedded in the code is used instead, so that things
      continue to work.
      The replacement image is a red X in a box while the audio is just
      short silence.
  3. 30 Dec, 2015 3 commits
    • Terence Martin's avatar
      Demo game : mute audio when game stops · cea9e63d
      Terence Martin authored
      This is something I meant to push into a previous version of the
      engine but forgot; in the default game that demonstrates how things
      work, when the stop button is pressed on the page, music and sound is
      muted, and then un-muted when things are restarted.
    • Terence Martin's avatar
      Split Engine and Game into separate JS files · eaf24aba
      Terence Martin authored
      Phase one of this is now complete; there are two tsconfig.json files
      to compile each part to its own output file and both are included
      in the HTML file.
      I'm currently not doing anything with external build systems of any
      kind (maybe next?) so the .d.ts file falls out inside the JS output
      directory because the TypeScript compiler puts both in the same place
      no matter what.
      As a result, this means that the tsconfig file for the game has to
      reference the file in that location, which is a little bit of a drag,
      but oh well.
      In theory if one was to have the engine be its own project, this
      would be taken care of by not having the compiler generate those
      files anyway.
    • Terence Martin's avatar
      Starting to separate engine and game into separate builds · e7036a8f
      Terence Martin authored
      Today's plan is to separate the code from the engine from the "game"
      project and have them generate to separate files, with an eye towards
      possibly just using the compiled JS output and a type definition file
      in a project without requiring the engine source.
      For this exploration I'm shifting the main code into its own folder,
      which should maybe be done anyway.
      Even if I decide that I don't want to work with this having no
      typescript source for the engine in a prototype project (for example
      I don't know if documentation comments will work in this case) I *do*
      want to have the source build into two different source files to make
      merges nicer.
  4. 29 Dec, 2015 11 commits
    • Terence Martin's avatar
      Update the previous commits because I'm a boob · 04ee2dee
      Terence Martin authored
      So like, instead of using the loop state to determine if something is
      a music, why not just add a boolean property? That way recurring
      background sound effects (like a machine hum for example) can loop
      but still be considered a sound.
    • Terence Martin's avatar
      Use the new Stage sound API in the demo "game" · 40bcbdd7
      Terence Martin authored
      The demo now uses the new stage API's. It uses the stage to preload
      its audio files, and then uses the new API's to toggle the mute state
      of either music or sounds as appropriate.
    • Terence Martin's avatar
      Add sound API to the Stage class · 74398ccf
      Terence Martin authored
      The Stage class now allows you to preload sounds, music (and images
      for orthagonality) and also register sounds preloaded or created
      We include a new API that allows you to change the mute state and
      volume of all known sounds all in one shot, with the code treating
      sounds that are looping as music and other sounds as regular sound
    • Terence Martin's avatar
      Enhance sound API for muting · 4aa5e698
      Terence Martin authored
      The mute property of the sound element is now exposed as a property
      so that sounds can be muted if desired.
    • Terence Martin's avatar
      Change sound preload to not share tags · 10abf99d
      Terence Martin authored
      With the previous commit it seems important that unlike images,
      preloaded sounds don't short circuit and return back to you the
      previous tag that was returned when the same sound is loaded more
      than once.
      In doing this changing the volume on one would affect all (for
      example), which is not desirable.
    • Terence Martin's avatar
      Push the Sound class to its own file, redact Music class · c676deed
      Terence Martin authored
      The Sound class is shifted away from the Preload.ts file and into its
      own class file, and also has a bit of an enhanced API as opposed to
      Now you can specifically request that a sound restart when you play
      it or restart it, and the volume and loop can be adjusted.
      The Music class has been removed in favor of just creating a Sound
      instance that loops by default. It's a bit of a generalization, but
      for game prototyping it works just fine.
    • Terence Martin's avatar
      Allow for music and sound muting · 0064fcd0
      Terence Martin authored
      Let there be the ability to stop music from playing in the background so
      that it doesn't drive you bananas while you're busy tweaking code.
      This (kind of crudely) also mutes the sounds that play by adding a
      property to the dot objects that indicates if they should play their
      sound effect when they bounce or not, which is turned on by default
      but tweaked to track the playing state of the music.
      A better way to do this would be to have the Sound (and thus also
      Music) class have a static method that makes the play method do
      nothing when a flag is set (global mute), but this would require the
      class to track all of its own instances, or at least music instances,
      or toggling the state would not fully work.
      That's outside scope for right now.
      (Note: I guess it could also just exist and it's up to you to make
      sure that you pause any playing music and sounds would take care of
    • Terence Martin's avatar
      Start music properly in the test scene · 50f294f4
      Terence Martin authored
      Now that the code supports it properly, the music for the test scene
      is started when the scene activates instead of via a check in the
      update loop.
    • Terence Martin's avatar
      Enhance the Stage "currentScene" property · a3193c6d
      Terence Martin authored
      First, the code in the stage that schedules a scene change no longer
      immediately does the change if the game loop is not currently running.
      Secondly, the property for telling you what the current scene is has
      been modifed so that when the game loop is not running and you ask
      for the current scene, if there is a pending scene change, you get
      told that scene instead of what the "real" current scene is.
      This allows code that wants to check for the current scene during
      initialization to do so in a logically correct way while at the same
      time making sure that the activating() method on a scene will not get
      invoked before the preload (if any) is finished.
    • Terence Martin's avatar
      Enhance SceneManager to have a "next scene" property · c7b96849
      Terence Martin authored
      This allows us to ask the SceneManager class (used by Stage) what the
      next scene will be. This is always null unless there is a pending
      scene change scheduled; scenes don't change until we are told to
      check for one, so that the controller doesn't change in the midst of
      a frame update.
    • Terence Martin's avatar
      Remove some debug logs in the Preloaderr · 96323bca
      Terence Martin authored
      These accidentally snuck in while I was busy trying to figure out
      what the problem was with my update yesterday to preload music.
  5. 28 Dec, 2015 6 commits
    • Terence Martin's avatar
      Load music in the demo "game" · 59f3be7e
      Terence Martin authored
      We load the included music in the demo game and then start it playing
      when everything starts.
      There is currently an issue with this in that you can switch scenes
      while the game is not currently running, but doing so triggers the
      appropriate callbacks, which happen before the preload begins, so
      anything in those methods that rely on pre-loaded content will fail.
      This needs some looking into.
    • Terence Martin's avatar
      Include the ability to preload music (and simple wrapper classes) · 573e53b3
      Terence Martin authored
      The previous code for preloading sounds has been extended to also
      allow for loading music, which is just the same thing but in a
      different folder.
      There is now a Sound and Music class, which are just really simple
      wrappers around the audio tag in preparation for later API
      The Music class just extends the Sound class to turn on looping but
      otherwise does nothing (currently).
    • Terence Martin's avatar
      Fix up the stage code to avoid a bug in WebStorm (surprise!) · 981fa5d9
      Terence Martin authored
      I implemented the Scene.activating() and Scene.deactivating() methods
      to assume a null parameter if none is specified. Realistically this
      never actually happens but it was useful for some testing.
      In any case, as a result of this, every time you override one of
      those methods in WebStorm it generates invalid code that needs to be
      fixed up by hand, which is annoying as all get out.
      At some point I fixed the deactivating call but not the activating
      call; this is now fixed.
    • Terence Martin's avatar
      Include an attribution for the new music in the page · 86f82faa
      Terence Martin authored
      The attribution text shows up in the about part of the page.
    • Terence Martin's avatar
      Include some simple tools for working with songs · 0225363f
      Terence Martin authored
      I infrequently convert between different music formats so I always
      lose a couple of minutes looking up how it works. To that end I have
      included a couple of "tools", really just butt simple shell scripts,
      as a reminder.
      These are only useful to you if you run linux and also have oggenc,
      lame and ffmpeg installed. Sorry.
    • Terence Martin's avatar
      Include some music files · 29e1e8de
      Terence Martin authored
      An upcoming commit is going to include the ability to preload and play
      music, so it's added now.
      The song included:
      "Who Likes to Party" Kevin MacLeod (incompetech.com)
      Licensed under Creative Commons: By Attribution 3.0
      I pulled down the mp3 version, turned it into a wav and then
      converted the wav to an ogg file.
  6. 27 Dec, 2015 4 commits
    • Terence Martin's avatar
      Include (primitive) sound preloading as well · bf469a7a
      Terence Martin authored
      This uses the same pattern as the image loading does, but loads
      sounds instead of images.
      This still needs more work (for example, a Sound and Music class or
      something) because just invoking the .play() method will do nothing
      if the sound is already playing, so if multiple things have the same
      sound they can't all trigger at once.
      I'm not sure yet what the best solution is to that particular issue,
      but at least we can annoy people with bloops now!
    • Terence Martin's avatar
      Enhance image preload to allow image reuse · f03a73e8
      Terence Martin authored
      Now that the basic preload is working, the obvious extension to what
      it's doing is to allow for multiple requests for the same image to
      actually only load the same image once.
      The browser would reuse the underlying data anyway, but we can (I
      think?) save some object instances by just detecting when an attempt
      to preload something that someone already asked for a preload for and
      return the same image tag that the first one returned.
    • Terence Martin's avatar
      Fix a defect in the new Stage image preload and remove debug logs · f0f3701f
      Terence Martin authored
      With the previous commit image preloading worked, but stopping and
      starting the game from the page was still broken; as it turns out
      this was due to the oh so common error of using a boolean to guard
      things but never changing its value. Smoooth.
    • Terence Martin's avatar
      Fix bug in CanvasRenderer exposed by new image preloading · 2932dbe2
      Terence Martin authored
      Up until now I have not tested the image blitting portion of the new
      TypeScript engine, and so I was unaware that the code for blitting an
      image centered on a location was broken.
      Specifically it would translate the canvas to the drawing location,
      but then never restore the context. As a result all of the images
      render at the same location always. This is now fixed.
  7. 26 Dec, 2015 1 commit
    • Terence Martin's avatar
      Partial engine change for image preload · 1bf4da4a
      Terence Martin authored
      This adds in the ability to preload images and not start the game
      loop until all images have loaded (or not).
      This is not fully working as of yet. Images seem to load and render,
      but the dots don't move and I've run out of development time to
  8. 24 Dec, 2015 1 commit
  9. 23 Dec, 2015 2 commits
    • Terence Martin's avatar
      Make scene capture screenshots with F5 via default handling · 0f905fb0
      Terence Martin authored
      The key down handling picks up the F5 key by default and takes a screenshot
      using the default values.
      Subclasses can chain to the super to get this default handling or not if it
      needs to do that itself.
    • Terence Martin's avatar
      Shift the logic for taking a screenshot from Scene to Stage · 6b274f35
      Terence Martin authored
      This seems perhaps better placed here because the Stage is what owns the canvas,
      which is needed for screen shot capturing.
      As a part of this change, there are static variables in Stage for setting the
      default filename and window title used by the screen shot system, so that you
      can just call the screenshot method directly.
      The sample application sets the values to what the old defaults used to be.
  10. 16 Dec, 2015 2 commits
    • Terence Martin's avatar
      Ammend previous commit to allow stage to expose tick count · fb433a22
      Terence Martin authored
      For timing purposes, it is interesting to have the stage expose the
      current tick to anyone that has access to it. This can be used to get
      at the tick without having to pass it all over the place, for example.
    • Terence Martin's avatar
      Include global tick count in the engine · f5052970
      Terence Martin authored
      The stage now keeps a count of the number of update ticks that have
      happened, and this is passed to the scene class in its update method
      as well as to actors in their update method.
      This allows for a crude (and stupid) way for things to be timed out
      in the engine. It's stupid because it's tied to the update rate and
      not the frame rate, which seems wrong.
      I'll worry about this in the future; probably the actual delta since
      the last frame should be used instead, or the update loop should
      always run at a constant tick rate independent of the render loop
      rate or something.
  11. 14 Dec, 2015 2 commits
    • Terence Martin's avatar
      Enhance Renderer API · 03fade72
      Terence Martin authored
      The Rendering API in Renderer and CanvasRenderer has been enhanced a
      Firstly, the polygon API has been modified to allow for sub shapes.
      Now instead of a list of points, the points can optionally contain a
      coommand string to indicate that the point represents a lineTo,
      moveTo or closePath, so that a polygon cn be more complex.
      Secondly, all of the shape API's now have a stroke version as well,
      so that you can create outlines if desired and not just fills.
      C), the Actor now uses a strokeRect call instead of a fillRect() call
      for default debug rendering, which makes things less busy.
    • Terence Martin's avatar
      Fix an oversight in Actor API · ad811d61
      Terence Martin authored
      Somehow I managed to forget to include properties to get the width
      and height of actors. This is now fixed.
  12. 11 Dec, 2015 4 commits
    • Terence Martin's avatar
      Modify engine functions to return void · 4a519431
      Terence Martin authored
      My bad on this one, I guess. It would appear that the default return
      value for a function that doesn't have an explicit return type
      specified and for which the code doesn't return a value is undefined
      or something?
      I've been having problems with WebStorm where overriding methods
      would cause it to randomly decide if a method returns a value or not
      as far as the signature inserted and the call to super.
      It turns out that this is because the compiler doesn't know for sure
      that the methods are not supposed to return anything.
      As such, this is now fixed by explicitly declaring the return type
      for everything in the engine API.
    • Terence Martin's avatar
      Include key codes for number keys · 5d7bf219
      Terence Martin authored
      Include the JavaScript key code values for the number keys on the
      main part of the keyboard.
    • Terence Martin's avatar
      Implement a generic polygon renderer · 6c9babf5
      Terence Martin authored
      This adds an interface to the rendering infrastructure that takes a
      list of points (stored as arrays) and connects them together to plot
      arbitrary polygons.
      This represents points as arrays of numbers instead of actual Point
      instances primarily because it's easiest to construct a polygon in
      code with literal arrays as opposed to Point constructors.
    • Terence Martin's avatar
      Extend point API · 6ac9844b
      Terence Martin authored
      Include the ability in the Point API to convert the point to an array
      of two numbers and also to set a point from an array of (at least)
      two values.
      This is something that came up during the Rx prototyping during
      devember day 10 as an easier way to construct polygon points, so it
      might be useful elsewhere.
  13. 10 Dec, 2015 1 commit
    • Terence Martin's avatar
      Allow the Stage/Scene to stop mouse event bubbling · 4e59d100
      Terence Martin authored
      The keyboard event handling in Stage and the Scene class have always
      been set up so that the method has to return a boolean to indicate if
      the event was handled, with the Stage stopping the event from being
      further handled if yes.
      This has now been extended to mouse events as well, because clicking
      on things while debugging and having it select portions of the page
      was annoying and I can't believe I never noticed this happening before.