Commit Graph

41 Commits (a9231fc038db548b7734608f3a5aaecab96e4f4b)

Author SHA1 Message Date
Noah a9231fc038 SDL2 engine: DrawLine: Use actual SDL call instead of IterLine 2021-09-12 15:23:25 -07:00
Noah d77f5056b7 Texturer to hold raw Go image.Image 2021-06-13 19:59:54 -07:00
Noah b4a1979a8b Bugfix on space character 2021-01-03 17:04:42 -08:00
Noah 6e916169d6 Spacebar event 2021-01-03 15:26:03 -08:00
Noah e5f4c3a168 Maximize SDL2 window 2020-07-09 19:32:47 -07:00
Noah 0642b65e87 Text.IsZero to check more values 2020-06-04 21:59:19 -07:00
Noah e495ec6439 Add DarkGrey to the default color names 2020-04-08 17:31:37 -07:00
Noah bb84347294 Add Point Comparator Function and Tests 2020-04-06 22:59:40 -07:00
Noah 87fabf6a8d Make it a Go module + minor tweaks 2020-03-09 17:28:49 -07:00
Noah 4d008b5c46 Clear WindowResized event boolean at the start of each Poll 2020-01-01 17:44:11 -08:00
Noah e758c46d70 Change public API to use int instead of int32 everywhere 2019-12-27 17:35:42 -08:00
Noah 930bb3ac72 Add GoDoc link to README 2019-12-27 16:47:11 -08:00
Noah 124718d5a0 Fix WebAssembly demo font loading 2019-12-22 18:38:56 -08:00
Noah ad9d14bdab Add WebAssembly Hello World Example 2019-12-22 16:26:33 -08:00
Noah 6803170675 Clean up repository for stand-alone release 2019-12-22 15:53:52 -08:00
Noah 5c803f6a88 render: Refactor Events System to Make Module Standalone
* Refactor the events used in lib/render/sdl to be more general-purpose
  to make librender a stand-alone library separate from Doodle.
2019-12-22 14:11:01 -08:00
Noah 857e5ec098 Better Ellipse Drawing Algorithm 2019-07-16 18:27:00 -07:00
Noah 524ebebedb Lemon-shaped Ellipse Tool (WIP)
* Add initial Ellipse Tool to the Editor Mode. Currently there's
  something wrong with the algorithm and the ellipses have a sort of
  'lemon shape' to them.
* Refactor the IterLine/IterLine2 functions to be more consistent.
  IterLine used to be the raw algorithm that took a bunch of coordinate
  numbers and IterLine2 took two render.Point's and was the main one
  used throughout the app. Now, IterLine takes the two Points and the
  raw algorithm function removed.
2019-07-14 14:18:44 -07:00
Noah 53977f709f Eraser Tool, Brush Sizes
* Implement Brush Sizes for drawtool.Stroke and add a UI to the tools panel
  to control the brush size.
  * Brush sizes: 1, 2, 4, 8, 16, 24, 32, 48, 64
* Add the Eraser Tool to editor mode. It uses a default brush size of 16
  and a max size of 32 due to some performance issues.
* The Undo/Redo system now remembers the original color of pixels when
  you change them, so that Undo will set them back how they were instead
  of deleting the pixel entirely. Due to performance issues, this only
  happens when your Brush Size is 0 (drawing single-pixel shapes).
* UI: Add an IntVariable option to ui.Label to bind showing the value of
  an int reference.

Aforementioned performance issues:

* When we try to remember whole rects of pixels for drawing thick
  shapes, it requires a ton of scanning for each step of the shape. Even
  de-duplicating pixel checks, tons of extra reads are constantly
  checked.
* The Eraser is the only tool that absolutely needs to be able to
  remember wiped pixels AND have large brush sizes. The performance
  sucks and lags a bit if you erase a lot all at once, but it's a
  trade-off for now.
* So pixels aren't remembered when drawing lines in your level with
  thick brushes, so the Undo action will simply delete your pixels and not
  reset them. Only the Eraser can bring back pixels.
2019-07-11 19:07:46 -07:00
Noah 5f37193512 Doodad CLI Tool Features; Write Lock and Hidden
* The `doodad` CLI tool got a lot of new commands:
  * `doodad show` to verbosely print details about Levels and Doodads.
  * `edit-level` and `edit-doodad` to update details about Levels and
    Doodads, such as their Title, Author, page type and size, etc.
* Doodads gain a `Hidden bool` that hides them from the palette in
  Editor Mode. The player character (Blue Azulian) is Hidden.
* Add some boolProps to the balance/ package and made a dynamic system
  to easily configure these with the in-game dev console.
  * Command: `boolProp list` returns available balance.boolProps
  * `boolProp <name>` returns the current value.
  * `boolProp <name> <true or false>` sets the value.
* The new boolProps are:
  * showAllDoodads: enable Hidden doodads on the palette UI (NOTE:
    reload the editor to take effect)
  * writeLockOverride: edit files that are write locked anyway
  * prettyJSON: pretty-format the JSON files saved by the game.
2019-07-06 23:28:11 -07:00
Noah 7f4640b727 Add Switches, Fire/Water Collision and Play Menu
* New doodads: Switches.
  * They come in four varieties: wall switch (background element, with
    "ON/OFF" text) and three side-profile switches for the floor, left
    or right walls.
  * On collision with the player, they flip their state from "OFF" to
    "ON" or vice versa. If the player walks away and then collides
    again, the switch flips again.
  * Can be used to open/close Electric Doors when turned on/off. Their
    default state is "off"
  * If a switch receives a power signal from another linked switch, it
    sets its own state to match. So, two "on/off" switches that are
    connected to a door AND to each other will both flip on/off when one
    of them flips.
* Update the Level Collision logic to support Decoration, Fire and Water
  pixel collisions.
  * Previously, ALL pixels in the level were acting as though solid.
  * Non-solid pixels don't count for collision detection, but their
    attributes (fire and water) are collected and returned.
* Updated the MenuScene to support loading a map file in Play Mode
  instead of Edit Mode. Updated the title screen menu to add a button
  for playing levels instead of editing them.
* Wrote some documentation.
2019-07-06 18:30:03 -07:00
Noah 243514f848 Centralized Tick Counter, Fix Actor Dragging Bug
* The game's tick counter was moved from Doodle.ticks to shmem.Tick
  where it is more easily available from every corner of the code.
* Fix a bug in the Level Editor where dragging an already-existing actor
  from one part of your map to another, would cause it to lose all its
  data (especially its UUID), breaking links to other doodads. Now the
  existing Actor catches a ride on the drag object to be reinserted
  later.
* Animate the Link Line visualizers between actors. They now animate a
  blinking color between magenta and grey-ish.
2019-07-05 16:04:36 -07:00
Noah fb29d6a11c Editor Mode: Line Tool and Rectangle Tool
* Add support for the LineTool and RectTool while in the EditorMode to
  easily draw straight lines and rectangle outlines.
* Key bindings were added to toggle tools in lieu of a proper UI to
  select the tool from a toolbar.
  * "F" for Pencil (Freehand) Tool (since "P" is for "Playtest")
  * "L" for Line Tool
  * "R" for Rectangle Tool
2019-07-03 17:19:25 -07:00
Noah 8126888b5b Drawing Strokes and Undo/Redo Functionality
* Add new pkg/drawtool with utilities to abstract away drawing actions
  into Strokes and track undo/redo History for them.
* The freehand Pencil tool in EditorMode has been refactored to create a
  Stroke of Shape=Freehand and queue up its world pixels there instead
  of directly modifying the level chunker in real time. When the mouse
  button is released, the freehand Stroke is committed to the level
  chunker and added to the UndoHistory.
* UndoHistory is (temporarily) stored with the level.Level so it can
  survive trips to PlayScene and back, but is not stored as JSON on
  disk.
* Ctrl-Z and Ctrl-Y in EditorMode for undo and redo, respectively.
2019-07-03 16:25:23 -07:00
Noah e682bb27c0 Demo Running Level as Title Screen Wallpaper
* Load SDL2 fonts from go-bindata storage so we don't have to ship
  external font files on disk.
* Dedupe names of doodads so we don't show double on the front-end
  (go-bindata bundled doodads + those on local filesystem)
* Use go-bindata for accessing wallpaper images.
* Better flashed messages walking you through the Link Tool.
* Stylize the title screen (MainScene) by rendering a live example level
  as the background wallpaper, with mobile doodads in motion.
2019-06-27 22:59:36 -07:00
Noah 981b2b98e0 Refactor Render Texture-Cache Interface
Since SDL2 is using in-memory bitmaps the same as Canvas engine, the
function names of the render.Engine interface have been cleaned up:

* NewTexture(filename, image) -> StoreTexture(name, image)
  Create a new cached texture with a given name.
* NewBitmap(filename) -> LoadTexture(name)
  Recall a stored texture with a given name.
* level.Chunk.ToBitmap uses simpler names for the textures instead of
  userdir.CacheFilename file-like paths.
2019-06-27 13:01:01 -07:00
Noah 4ad32c6edf SDL2: Cache Bitmaps in Memory, Not on Disk
* Update the SDL2 engine's texture caching to use an sdl.RWops file
  buffer in memory instead of outputting bitmap images to the
  filesystem.
2019-06-27 12:46:35 -07:00
Noah 5893daba58 WASM Texture Caching
* Refactor texture caching in render.Engine:
  * New interface method: NewTexture(filename string, image.Image)
  * WASM immediately encodes the image to PNG and generates a JavaScript
    `Image()` object to load it with a data URI and keep it in memory.
  * SDL2 saves the bitmap to disk as it did before.
  * WASM: deprecate the sessionStorage for holding image data. Session
    storage methods panic if called. The image data is directly kept in
    Go memory as a js.Value holding an Image().
* Shared Memory workaround: the level.Chunk.ToBitmap() function is where
  chunk textures get cached, but it had no access to the render.Engine
  used in the game. The `pkg/shmem` package holds global pointers to
  common structures like the CurrentRenderEngine as a work-around.
  * Also shmem.Flash() so Doodle can make its d.Flash() function
    globally available, any sub-package can now flash text to the screen
    regardless of source code location.
  * JavaScript API for Doodads now has a global Flash() function
    available.
* WASM: Handle window resize so Doodle can recompute its dimensions
  instead of scaling/shrinking the view.
2019-06-27 12:03:52 -07:00
Noah 27b908e40a Texture Caching for WASM Canvas Engine
* Add RGBA color blending support in WASM build.
* Initial texture caching API for Canvas renderer engine. The WASM build
  writes the chunk caches as a "data:image/png" base64 URL on the
  browser's sessionStorage, for access to copy into the Canvas.
* Separated the ClickEvent from the MouseEvent (motion) in the WASM
  event queue system, to allow clicking and dragging.
* Added the EscapeKey handler, which will abruptly terminate the WASM
  application, same as it kills the window in the desktop build.
* Optimization fix: I discovered that if the user clicks and holds over
  a single pixel when drawing a level, repeated Set() operations were
  firing meaning multiple cache invalidations. Not noticeable on PC but
  on WebAssembly it crippled the browser. Now if the cursor isn't moving
  it doesn't do anything.
2019-06-26 22:44:08 -07:00
Noah 03b4441eaa WASM Event Queue
* Refactor the event system in the WASM render engine to serialize the
  async JavaScript events into a channel, so that queued events are read
  off serially in the main loop similar to SDL. This fixes keyboard
  input issues, altho if you type really fast some input keys get lost.
2019-06-26 20:33:24 -07:00
Noah ecffcc223d Initial WebAssembly Build Target
* Initial WebAssembly build target for Doodle in the wasm/ folder.
* Add a new render.Engine implementation, lib/render/canvas that uses
  the HTML 5 Canvas API instead of SDL2 for the WebAssembly target.
  * Ported the basic DrawLine(), DrawBox() etc. functions from SDL2 to
    Canvas context2d API.
  * Fonts are handled with CSS embedded fonts named after the font
    filename and defined in wasm/index.html
* `make wasm` builds the WASM program, and `make wasm-serve` runs a dev
  Go server that hosts the WASM file for development. The server also
  watches the dev tree for *.go files and rebuilds the WASM binary
  automatically on change.
* This build "basically" runs the game. UI and fonts all work and mouse
  movements and clicks are detected. No wallpaper support yet or texture
  caching (which will crash the game as soon as you click and draw a
  pixel in your map!)
2019-06-26 18:40:40 -07:00
Noah 5e9443bcff Add MenuScene with New Level UI
* Debug mode: no longer enables the DebugOverlay (F3) by default, but
  does now insert the current FPS counter into the window title bar.
* ui.Frame: set a default "mostly transparent" BG color so the frame
  background doesn't render as white.
* Add the MenuScene which will house the game's main menus.
* The "New Level" menu is first to be added.
  * UI lets you pick Page Type and Wallpaper using radio buttons.
  * Page Type: Unbounded, Bounded (default), No Negative Space, Bordered
  * Fix bugs in uix.Canvas to fully support all these page types.
2019-06-25 15:01:37 -07:00
Noah 7b264dffba Minor Tweaks 2019-06-08 17:02:28 -07:00
Noah d10f7d190c Return False: Solid Collision Between Actors
* Implement the handler code for `return false` when actors are
  colliding with each other and wish to act like solid walls.
* The locked doors will `return false` when they're closed and the
  colliding actor does not have the matching key.
* Add arbitrary key/value storage to Actors. The colored keys will set
  an actor value "key:%TITLE%" on the one who touched the key before
  destroying itself. The colored doors check that key when touched to
  decide whether to open.
* The trapdoor now only opens if you're touching it from the top (your
  overlap box Y value is 0), but if you touch it from below and the door
  is closed, it acts like a solid object.
2019-05-28 21:43:30 -07:00
Noah 58fae48a2a WIP: MsgPack stubs, Level Filesystem Module
* Add some encoding/decoding functions for binary msgpack format for
  levels and doodads. Currently it writes msgpack files that can be
  decoded and printed by Python (mp2json.py) but it can't re-read from
  the binary format. For now, levels will continue to write in JSON
  format.
* Add filesystem abstraction functions to the balance/ package to search
  multiple paths to find Levels and Doodads, to make way for
  system-level doodads.
2019-05-06 12:41:46 -07:00
Noah 6c5542673a Remove ScreenshotKey Event, Add F* Key Handlers
* The F3 key now toggles the Debug Overlay, which is now OFF by default.
* The F4 key now toggles the Debug Collision Boxes feature.
2019-04-19 16:21:04 -07:00
Noah 95ef079724 Remove pkg/log from lib/render package
This breaks the last ties from the lib/ folder of publicly open
sourceable code from the internals of Doodle in pkg/
2019-04-18 22:14:02 -07:00
Noah 8dfae5b8d8 Play Mode: Fix Level Collision w/ Scrolling
Fixes:
* Move the call to CollidesWithGrid() inside the Canvas instead of
  outside in the PlayScene.movePlayer() so it can apply to all Actors
  in motion.
* PlayScene.movePlayer() in turn just sets the player's Velocity so the
  Canvas.Loop() can move the actor itself.
* When keeping the player inside the level boundaries: previously it was
  assuming the player Position was relative to the window, and was
  checking the WorldIndexAt and getting wrong results.
* Canvas scrolling (loopFollowActor): check that the actor is getting
  close to the screen edge using the Viewport into the world, NOT the
  screen-relative coordinates of the Canvas bounding boxes.
2019-04-14 15:25:03 -07:00
Noah 2ae77a8c82 Port over code from old collision dev PR 2019-04-09 19:17:56 -07:00
Noah 31e01987e5 Clean up extra log modules 2019-04-09 17:47:03 -07:00
Noah cddc41465f Code Layout Refactor
* All private Doodle source code into the pkg/ folder.
* Potentially public code into the lib/ folder.
* Centralize the logger into a subpackage.
2019-04-09 17:35:44 -07:00