Tuesday, August 16, 2022

Inventaverse New Players Guide

A brief guide to the various systems of character progression and enhancement in Inventaverse.

A reasonably large gap in Inventaverse exists between the new player and the extremely deep tool set laid before them.  Inventaverse contains a massive customization feature set, but currently there aren't very many resources of information on how to utilize that feature set.  With this article I'm going to attempt to bridge that gap by giving a summary and how-to for each of the main customization tools in Inventaverse:

  • The Character System
  • The Artifact System
  • The Skill Matrix System
  • The Incantation System

Each of these systems are highly detailed, and the player certainly deserves a how-to guide to maximizing your character in Inventaverse.  Spoiler alert, this guide starts out very simple, but eventually gets extremely deep, please feel free to skip ahead to the stuff that matters to you.

The Character System

As an Inventaverse player you have the option of choosing from any one of 18(!) unique playable characters.  Each one provides various advantages and disadvantages.  As a new player only 10 of the characters are unlocked.  If you're looking for a quick answer on which characters are easiest to pick up and play as a new player, here's a short list: Secret Agent, Ninja, Spaceman, Inventor.

 

 * Selecting a character is your first choice in Inventaverse, make the most of it.

Every character has a unique set of strengths and weaknesses, and depending on what you want to do, one character may be better suited than the rest for the task at hand.  Here's a breakdown of how each one performs and how their attack and special move are used

Secret Agent - medium speed and jump, but his retracting grappling hook give him great mobility.  his bouncing bullets make him highly deadly in enclosed spaces.

Cowboy - medium speed and low jump, his dynamite special can destroy anyone or give him a boost to reach high areas.  his bouncing bullets hit a little harder and move a little faster than the secret agent's.

Wizard - slow speed, low jump, the wizard can materialize a block at a target location.  his slowfall allows him to float across far gaps, and his main attack ignores walls.

Karate Fighter - high speed and high jump, the karate fighter has excellent mobility, an area of effect healing special, throwing kamas, a great spinning kick slowfall with knockback, and a sai for a melee weapon.

Knight - slow when walking, but fast when he uses his dash special.  he's immune to environmental traps like spikes and has extra health.  his throwing axe hits hard, and he carries a battle axe as a melee weapon.

Witch Doctor - he's fast, and his projectile weapon is very fast.  his special allows you to heal yourself and any nearby allies, and he also has wallgrab.

Miner - not particularly fast and he doesn't jump high, but his special allows him to burrow into the ground or walls.  his explosives are highly destructive.

Inventor - medium speed normally, but when he uses his rocket boots, he's quite fast.  they allow him to hover, jump higher, and fly.  his death ray is very fast and does high damage.

Spaceman - medium speed, but his special provides excellent mobility by allowing him to reverse gravity.  his main attack is a hypertronic beam with a knockback effect.

Ninja - high speed, jump, and wall grab, the Ninja uses a grappling hook and throwing stars to move to difficult places and defeat enemies, additionally he carries a katana for a melee weapon.

Psychopath - relatively slow and with low jump, the psychopath may seem like he has poor mobility but his special allows him to sacrifice a little health to teleport to any ground location.  he's also immune to environmental hazards like spikes and carries a chainsaw for a melee weapon.

Warlock - not a fast character, but a versatile one.  the warlock's teleport special ability can be used to quickly escape danger, fool would-be adversaries, or use it as a boost to reach higher places, in addition his fireball is a powerful attack, and like other magic users he has a slowfall.

Shadow Beast - even though the shadow beast's primary attack is relatively weak, the ability to become invisible is exceptionally useful in a lot of scenarios.  combine that with high speed, high jump and wall grab.

Sniper - in terms of mobility the sniper isn't high on the list, he moves fairly quickly, jumps pretty high and has wall grab and a slowfall, but his real strength comes from being able to see the entire map and eliminate enemies from afar.  Weapon upgrades increase the frequency that he can fire his primary weapon.

Vampire - the vampire has excellent mobility.  holding the jump button will allow him to change into a bat and fly.  with every direct hit, his primary attack allows him to drain health from the enemy.  his special is an AOE damage over time.

Swashbuckler - fast, with great offense and defense.  his special allows him to ignore almost all damage coming in, and his primary attack is extremely powerful.  add to that wallgrab and great speed and jump, and a cutlass for a melee weapon.

Exiled One - while mobility may not be his strong suit, the exiled one excels at self-healing, deception, and he rounds out with a good primary attack, slowfall, and a black sword for melee weapon.

Witch - besides the shadow beast, the only other character who can become invisible is the witch.  however, the witch cannot move while invisible.  the witch's primary attack is VERY powerful, and like other magic users, the witch is able to slowfall.  also, poison potions heal the witch the same way healing potions do.

Decisions, Decisions...

It's a lot to choose from, but as I said earlier, new players are limited to only 10 of the 18 characters.  In order to unlock the rest of them, you must discover them in the game.  Specifically in the procedural world you can access by entering this door in your home world:

* Every home world contains a doorway that allows you to enter one or more procedurally generated worlds.  these worlds are different every day.


The Artifact System

There are 25 unique artifacts that you can use to improve your character's abilities.  Artifacts are items that you are able to equip in your home world prior to entering a level.  You are able to equip a maximum of 3 artifacts at one time.  As a new player, you have access to 6 of them. 

Your First 6 Artifacts

After you log into Inventaverse for the very first time, you'll notice that upon visiting the basement of your home world, you have certain objects waiting for you there.  They look like this:


* You may only notice 5 artifacts in your basement, an additional artifact is hidden in the bedroom of your first homeworld.


Compass - allows the user to teleport to a random location every 25 seconds.  

Gravitronic Nullifier - ignore the effects of gravity for 6 seconds once every 20 seconds.

Trama Kit - heal yourself to full health once every minute.

Laser AP - more fire power!

Refractive Field Generator - reduces most incoming beam damage.

Can of Zapo Cola - passively increases run speed and jump, and every 30 seconds allows the player to heal 6 health.

Since you're able to equip 3 artifacts simultaneously, your objective should be able to achieve a combined effect that synergizes with your overall character strategy.  You may notice that a mixture of artifacts from the list above can improve survivability.  When you combine the abilities of your artifacts with your character selection, some very interesting combinations emerge.  For instance, you can compensate for the poor mobility of the cowboy by equipping the Gravitronic Nullifier.  Or you can make the knight even harder to kill by equipping multiple healing artifacts.  If you're getting hit by a lot of beam attacks, perhaps from a sniper, be sure to pick up the Refractive Field Generator.

Active Effects

Pressing the number key associated with each of your artifacts will activate the "active effect" of the artifact.  These effects are often have a reset period associated with them.  For example, with the Trama Kit artifact, you can heal your character to full health once every 60 seconds.

Passive Effects

In addition to the active effect of an artifact, all artifacts also have a variety of passive effects.  These are typically a mix of the following complementary secondary stat buffs.

  1. Slowly regenerate health over time
  2. Maximum health increased
  3. Poison potions behave the same as healing potions when collected.
  4. Increase the area of effect of your incantations on all sides.
  5. Initial weapon rank increased
  6. Increase speed
  7. Increase jump
  8. Personal rebounding shield
  9. Reduces all damage

These secondary effects are revealed when you inspect each artifact by pressing the 'e' key.  Be sure to select artifacts that feature primary and secondary effects that align with your overall character strategy.

The Skills Matrix System

Beyond your character selection and choice of artifacts, the skill matrix system can provide a massive enhancement to your gameplay.  However, before you can access the skills matrix you need to choose a mentor.  Each of the 3 mentors offers a different skills matrix.  Once you have discovered a mentor, simply return to your homeworld and talk to your mentor by pressing the 'E' key.  Once you've spoken to your mentor, you can access your skills matrix by pressing the 'T' key.  This is what it looks like:


* Each hexagon on the skills matrix gives a bonus, advantage or buff.

In Inventaverse, each skills matrix is based on one of the three philosophical disciplines.

  • Cosmology
  • The Occult
  • Magic

The Cosmology Skills Matrix - the cosmology matrix focuses on improving technology artifacts, AP weapons, beam weapons.  The three major skills (red hexagons) in the Cosmology matrix are as follows:

  1. Equips the player with a fourth artifact, the Nanonova AP
  2. Reduce the cooldown of all technology artifacts by 50%
  3. Every 12 direct hits will generate a force field at the player's target

The Occult Skills Matrix - the occult matrix is focused mainly on improving eldritch artifacts, increasing direct damage, and durability.  The three major skills in the Occult matrix:

  1. Every 12 direct hits will generate a blackhole at the player's target.
  2. Reduce the cooldown of all Eldritch artifacts by 50%.
  3. Every 12 direct hits will fire a powerful antiversal energy bolt at the enemy target.

The Magic Skills Matrix - the magic skill matrix concentrates heavily on catastrophic explosive damage, inceptium based artifacts, situational awareness, and adventuring.  The major skills of the Magic matrix:

  1. Completing a world rewards you with twice the gold collected in that world.
  2. The cooldown of all Inceptium artifacts is reduced by 50%, and your map screen shows the fully explored world and all items and treasure.
  3. Your weapon ranks each reduce the cooldown of Wizard's Fire by 30 seconds.

In addition to the major and minor skill traits, the Skills Matrix also features 2 other sets of skill traits.  The top row of rainbow-colored traits are reserved for special achievement-based skills that are unlocked when the player completes various objectives.  List below are the achievements and various skill trait rewards:

  1. 10 Treasure chests looted to unlock this trait. -> When you die, you are resurrected where you died, but limbo is quadrupled.
  2. 25 Worlds completed to unlock this trait. -> All Characters have wall-grab.
  3. 50 Survivors rescued to unlock this trait. -> You can now see the spirit of deceased enemies
  4. 75 Deaths to unlock this trait. -> When your health reaches zero, instead of dying, you are healed to 5. (This will only happen once a minute)
  5. 100 Red stars collected to unlock this trait. -> Collecting a red star grants the maximum number of weapon ranks.
  6. 200 Enemies killed to unlock this trait. -> You enter a blood frenzy.  Your health is gradually reduced over time, but your damage is increased by 50%.

You'll also notice 3 more hexagons in the middle.  Those hexagons are reserved for the 3 books of magic related to Incantations, see the next section for more info on Incantations.

The Incantation System

The Incantation system is a reasonably limited API aimed at giving players the ability to write custom scripts of their own into Inventaverse.  These scripts are automatically bound to the R, F, and V keys.  Accessing the Incantations screen is as easy as hitting the 'I' key while your character is located at their homeworld.


* Your code is on the left; the incantations API documentation is on the right.

To unlock the Incantations API, you just need to buy one of the three magic books in the shop. The shop is located in any proc world, and all three books are for sale.

The interface for writing Incantations is relatively straight forward.  Simply select R, F, or V, type your custom script into the UI, and then test it in your homeworld.  The homeworld is a fine place to test your scripts, however, in the event that you manage to break the game engine with your script, simply refresh your browser.  If you've written a script that breaks it beyond that, there's a way to clear your incantations in the player profile menu on the community site.

Incantations are a complicated and interesting part of Inventaverse.  Even if you've got your character perfectly configured, with artifacts and a completed skills matrix, there's still room to squeeze that last tiny bit of performance out of the Incantations system.  And that last tiny bit of performance, can be decisive.

For more information on how to write Incantations, see Psionic Logic: How to write an Incantation in Inventaverse



Friday, February 18, 2022

Inventaverse From a New Angle

As other side projects have relented as of late, I've decided to tackle a few things in Inventaverse that I've always thought would be interesting additions.  Before, Inventaverse was only about character advancement, adventuring, and death match style PVP.  There's a reasonably large set of features designed to help the player customize and strengthen their favorite characters.  Things like artifacts, skill trees, achievement-based skills, and incantations that allow the player to write their own custom spells and abilities.

Despite all the bells and whistles I've added to the game, I've seen little to no traction with the game community.  I've had a few game play testers come through and try it out and while they seem genuinely entertained for a few weeks, after that, they drop off.  Maybe I've created too little content I thought.  Maybe character advancement is too grindy.  Eventually it dawned on me that people become bored when they lose interest.  To paraphrase: they lose interest because the problem isn't interesting enough to keep them from getting bored. 

With that in mind, and with a little consideration, I ultimately decided to add a Capture the Flag style game mode to Inventaverse.  After all, there was no 2D retro online CTF game and it made sense that from a new perspective, various details about the game morphed into something entirely different.  Characters that seemed purposeless suddenly were very powerful in this new context.  Speed now became an important consideration.  Various artifact combinations that made no sense in the past, were now synergizing quite well together when considering this new and interesting problem.

I got to work right away, fixing a few bugs and implementing the new game mode.

 Along the way I'd have short thought experiments where I'd ask myself questions from the point of view of a CTF player.  Questions like: How would I configure my character if I were responsible for protecting the flag?  What about as a sniper?  Or even a capper, or flag runner?  I logged into the game and suddenly various puzzle pieces started falling into place as I experimented with the various parameters of the game characters.

Grabbin' some flag with the pirate.

Take character selection for example.   I know that being able to zip from one side of the map to the other is going to be critically important in a CTF game, but I hadn't yet tested to see just how fast I could make a character go.  So, I picked the obvious choice at first, the Ninja.  I grabbed two artifacts that add a speed boost (the Zapo Cola, and Pocket Watch), and configured an incantation to sacrifice some health for more speed. This proved useful for building up the ninja's running speed.  Next, I timed him to see how fast I could run from one side of a map to the other.  23 seconds.  Pretty good, but nothing compared to the speed of the Inventor (12 seconds).  And while the Inventor was fast, he wasn't nearly as fast as the Psychopath equipped with the spy glass(2 seconds).  

You see, the Psychopath can teleport to a location, and the spyglass allows you to see the entire map.  The combination of teleportation and the spyglass results in being able to travel anywhere on the map with the small cost of some health.  It was at this moment I decided that using special abilities would be prohibited while carrying the flag.  It just makes it too easy to capture the flag.  So, use anything you want to use on the way to picking it up, but after you have it in your hands, you're limited to walking it back to your flag base.

I was interested to see what kind of meta could evolve from this design choice.  Would players stick to the instant grab but slow return of the Psychopath?  Or would a more heavily armored flag carrier be the better option?  

And what about defending the flag?  It seemed like an obvious choice to pick the Gunslinger.  Drop a stick of dynamite on the flag and wait for the enemy flag carrier to hop along and grab it up only to find himself insta-gibbed upon detonation.  Or would the best choice be to go with force fields?  I loved the idea of sitting near the flag base as the Witch, in stealth, casting a force field around the flag, then attacking as the enemy got close enough to grab.  This seemed like too powerful of a combination to ignore, but for now I'd have to ignore it.  The likelihood of someone easily countering that strategy in Inventaverse was high considering the massive tool set at the player's disposal.

In the darkness, the Witch carefully watches the red flag base.

I continued working to implement the flag capturing game mechanic, which didn't take long considering what I already had to work with in terms of game assets and code.  I think I nailed it in a night or two.  After that, I put a little time into making a fairly easy and small Capture the Flag map.

The many years I had spent playing various Tribes franchise games have taught me that small levels are thrilling, with a small set of players, while large levels with lots of nooks and crannies are harder to build but ultimately provide an epic experience as long as enough people are online to play them.  I decided to go with a small sized map at first.  100x60 should be plenty of room to test out CTF game play with a few friends.

I spend about a week on development and level design, and I think I've got something that will at least give me an idea of what CTF in Inventaverse is like.

I'm excited to see how the first few matches go.

Until next time...

Wednesday, May 20, 2020

Writing Console Quality Javascript Games in the ES6+ Era: Part 1

When I tell other game development enthusiasts that I write video games for the web in JavaScript, I get a variety of interesting and stigmatized responses back.
  • Why wouldn't you just use a game engine like GODOT, Unity, GMS, or Unreal?
  • Don't you run into performance issues?
  • As your game grows, how does it scale?
  • Isn't coding your own game engine super hard?

These responses typically follow the same underlying theme: JavaScript isn't well suited for writing video games.  Well, please have an open mind, grab your favorite beverage, and allow me to dispel many of these myths about developing high performance, high quality games that run on the web.

JavaScript, not an inferior tool, it's a tool with a totally different set of strengths and weaknesses


While it's nice to be able to use a one stop solution like GODOT or Unity, I propose that writing a video game in JavaScript isn't just easy, it's also beneficial to you as a developer.  It's especially beneficial if your day job is writing enterprise code as a software engineer.  In addition to that, JavaScript brings a ton of great features to the table that you miss out on with other solutions.  In some ways it's certainly less convenient, but for every drawback, there's a benefit.

A great example of where JavaScript shines is the NPM ecosystem.  NPM is the world's largest software registry.  With almost a million packages, you have a massive number of resources you can put to use in your indie game project.  Installing NPM packages is as easy as running a console command, and with the standardization of the ES6 module system, making use of the features of each package is relatively straight forward.

At this point, you might be asking: "But... aren't you limited to the web as your platform?".  The short answer is No.  There are number of products out there dedicated to shipping web based games to your alternative platform(s) of choice.  The most popular among them is Apache Cordova.

But, what about Performance?  JavaScript is everywhere.  Because of this, a huge effort has been placed on performance enhancements over the years.  With optimization advances to the most popular JavaScript engines(like v8), you're looking at near native performance out of the gate.  This is without even using Web Assembly(which I do like, by the way).  In fact, in my boiler plate JavaScript game framework project, I'm getting frame draws and engine updates happening at sub-millisecond speeds, 60 frames/second in 2D on a very old machine(AMD FX 8350).  This is PLENTY fast enough for almost all 2D games on the latest hardware.


Okay, it's fast, but why choose it over other game engines that are also fast?  In many cases, choosing a turn key game engine solution(like Godot or Unity) is a good choice.  However, for those of us that know JavaScript and are interested in the control and flexibility it provides, there's a strong case to be made to use an ES6+ project as a platform for your game.  For instance, if you use JavaScript professionally, the skills you'd use to create a game using JavaScript translate well to your other projects.  Conversely, the tricks you've picked up along the way as an enterprise programmer translate directly to your game project.  Not to mention, JavaScript has recently become the most popular language choice for programmers, worldwide.  Perhaps not for game development, but I consider it a great stepping off point to introduce enterprise developers to the world of indie game development.

In addition to good performance, the popularity of JavaScript has spurred almost every database, communication and framework shop to write interface implementations for JavaScript. 

The reasons are numerous(more than I've mentioned here), and the capabilities are more than adequate.  If anything, don't rule it out as being a viable option, because in my experience it can certainly hold it's own against the giants in the industry.

In my next blog post, I'll start to go over my boiler plate ES6+ game dev framework project, and how you can use it to write high performance video games for the web!


Tuesday, February 25, 2020

Character Builds in Inventaverse

As I was creating the plethora of character types in Inventaverse, I wanted to keep in mind that flexibility is important to the player. Not yoga flexibility, play style flexibility.  The player should be able to play the way they want to play, and by playing they should be able to reward themselves with a more capable character in their chosen play style.

It was in this line of thinking that I came up with a rough list consisting of the basic styles of game play in Inventaverse.

  1. The Sniper
  2. The Brawler
  3. The Assassin
  4. The Adventurer

Each of these play styles features a unique mindset that defines it.  The Sniper is wholly concerned with eliminating targets from a distance.  The Brawler is designed to perform well in close quarters combat situations.  The Assassin is stealthy and relies on surprise ambush attacks.  The Adventurer isn't primarily concerned with battle and instead is focused on things like collecting treasure and progression.

Let's look at these in detail and explore the subtle variations of each.

Sniper Build

Since the goal of the sniper is to kill targets at long range, it makes sense for a good sniper build to be one that can elliminate an enemy with a single, very powerful shot.  Consider the following basic sniper build:

Character: Aetherian Sniper
Artifacts: Singularity Beam, Inceptium Ring, Antiverse AP
Mentor: Cosmologist, Astromancer variant build
  1. Nanonova AP
  2. Beam damage increase
  3. Passive healing
Incantations:
  1. Convert health to weapon ranks
  2. Convert health to magic and Dissolve block at target location
  3. Ward: Auto attack nearby enemy, with alert
How it works:
Two important things to consider when playing a sniper are: fire power, and cover.  It's vital to be able to destroy a target as quickly as possibly so they have little time to activate any countermeasures, and its also important to avoid being located while you do it.  All three of the equipped artifacts add damage, and the selected skill traits either add damage or supply passive healing to counteract the health conversion incantations.  The incantations in this build are key.  Maxing out weapon ranks is important, because it increases firing frequency of the Aetherian Sniper, making the conversion from health to weapon ranks useful.  Health -> magic -> dissolve blocks is important because it makes the sniper difficult to get to.  Simply tuck yourself away somewhere remote.  The ward incantations is the most important.  Not only does it warn you when someone is close to your location, it pops them out of stealth with a minor damaging attack.

Brawler Build


The brawler is a character build that's awesome in combat.  It must be able to come out on top in a battle and take out multiple enemies.  Hard to kill, and extremely dangerous.

Character: Warlock
Artifacts: Inceptium Ring, Blast Amulet, Refractive Field Generator
Mentor: Conjurer, Archmagus variant build
  1. Wizard's Fire
  2. Weapon ranks reduce Cd of Wizard's Fire
  3. Double shot
  4. +2 Weapon rank traits
Incantations:
  1. Convert weapon rank to health
  2. Spend gold to cast Annihilate at target location
  3. Ward: Auto attack nearby enemy with blast
How it works:
The combination of the Warlock's exploding fire balls(2 at a time with doubleshot trait) and the Wizard's Fire trait make this a very destructive build.  The blast amulet gives the warlock immunity to the Wizard's Fire explosive damage and also reduces 50% of incoming damage from enemies.  The combination of the inceptium ring and +2 weapon rank trait ensure that Wizard's Fire can be cast as often as possible. The optional refractive field generator keeps the Warlock safe from snipers and beam damage from other players.  Being able to use those weapon ranks to heal on demand is a helpful incantation and in coordination with the auto blast incantation for maximum proximity protection.  This build rounds out nicely with a gold to damage conversion in the form of annihilate.

Assassin Build


If stealthily destroying the enemy is your forte, this basic assassin build is exactly what you're looking for.  Sneak up on the enemy and instantly destroy them, and if they get wise to your tricks, instantly teleport away.

Character: Shadow Beast
Artifacts: Higgs Field Amplifier, Compass, Inceptium AP
Mentor: Occultist, Oracle variant build
  1. Special abilities that cost health take 50% less health trait
  2. Quadshot
  3. Reduce cooldown of all eldritch artifacts by 50%
  4. Causing damage now heals you trait
  5. + 25% health
  6. Healing effects increased by 25%
Incantations:
  1. Convert health to weapon rank
  2. Spend weapon ranks to cast Annihilate at target location
  3. Spend x to create a physical block at target location
How it works:
The shadow beast is a powerful assassin but, he is limited by his health pool in that he spends a small amount of health for every second he's in stealth.  A great way to counteract this is to spec into the many self healing traits of the occultist tree.  In addition to that, we can over spec into those healing traits and use health as an incantation resource, since we know we'll get it back from those traits and the self heal applied by the Inceptium AP.  So, we'll sneak up on our prey, use the Higgs Field(on a reduced cooldown) to lock it into place and nuke it with quadshot, the annihilate incantation and the Inceptium AP.  If they are alive to counter attack, simply teleport to safety using the Compass on a reduced cooldown.  Rinse and repeat.  This build rounds out with a little mobility from physical block incantation and a weapon upgrade incantation, that we can bank magic into for later use.

Adventurer Build


Character: Spaceman
Artifacts:Skeleton Key, The Antidote, The Blast Amulet
Mentor: Conjurer, Alchemist variant build
  1. Completing a world rewards you with twice the gold collected in that world.
  2. Wizard's Fire
  3. Damage taken from explosions is reduced by 50%
Incantations:
  1. Convert health to weapon rank
  2. Convert weapon rank to health
  3. Spend weapon ranks to improve visibility
How it works:
This build is great for progressing your character, you collect double gold, because you have the skeleton key, you don't have to waste time finding the key to open the treasure chest, and the mobility of the spaceman is exceptionally good. The only problem is that the spaceman has fairly weak damage, but this is helped by using the Wizard's Fire trait when needed.  The antidote allows you to use poison to heal and the blast amulet will nullify the explosive damage of the Wizard's fire and provide a nice 50% passive damage reduction.  Incantations can be used to add weapon ranks, health or to improve visibility, in darkened areas.

These builds are just a few I came up with off the top of my head, the potential for variety is enormous!  Experiment, mix and match, and find the best builds that work for you!  In my next post, I'll show you how we can expand on these themes to create some really interesting advanced hybrid builds.  Until next time...

Friday, January 31, 2020

How to write an Incantation in Inventaverse


Inventaverse is pretty big.  It's got a ton of features, mountains of code and lots of artwork.  In the midst of all that creation is one feature that I'm particularly fond of.

The Incantations API

"What's the Incantations API Precious?", you ask?  Close your eyes and imagine three (not one, not two, but three), unimaginably powerful books, that when found in game, grant the player access to a toolkit for building their own custom spells.  That's right, you can write your own spells and further customize your play style in Inventaverse using PLAIN OLD JAVASCRIPT. 




"Why would I ever want to do that?", you calmly ask?  Well, allow me to explain to you, my naive reader, why you would want to wield such an incredibly powerful force in a video game.  (by way of list)

1. Because it gives you an advantage over the game, and other players.
2. By writing incantations the skills available to you are massively increased.
3. The incantations you write complement your favorite skills and your artifacts.
4. Because learning and understanding the three books of magic and the Incantations API, is very interesting.

Each of the three books contains a set of abilities related to one of the three types of magic in Inventaverse.
  • The Compendium of Physical Magics will allow you to spend your collected weapon ranks to add or remove physical matter from the game world.
  • The Grimoire of Eldritch Forces allows you to sacrifice your health to teleport or deal damage to enemies.
  • The Tome of Unifying and Dividing Energies lets you spend your gold to heal wounds, or improve your speed and jump capabilities.
 In addition to these books, a set of fundamental abilities are available to you through the "Common API".  These are abilities that don't require any particular spell book in order to use them.

Spells and Wards

When any of the three spell books are combined with each other and the common API, some very complex and interesting custom spells are able to be created.

For example, the following Ward:


if(API.Affectable(API.Target())) { API.Reveal(API.Target()); }

let row = API.Environment.Physical.length;
let cells = [];

while(row --> 0) {
  let col = API.Environment.Physical[row].length;
  while(col --> 0) {
    if(API.Environment.Physical[row][col] != 0) cells.push(new Point(col, row));
    }
  }
API.Reveal(cells);


This Ward makes use of the Common API, and the methods exposed by The Compendium of Physical Magics, to reveal blocks that are physical to the player, and to highlight the block under the mouse cursor, only if it is within the area of effect of the player's incantations.  Simply put, it shows you what is physical and the areas that your custom spells can affect.  Because it's ward, it will run continuously after the player presses the key it's bound to (either the R, F or V keys).

A ward is an incantation that continues running all the time, a spell is an incantation that runs only once, have a look at this Spell:



API.Self.Sacrifice(5);

let loc = API.Target();

API.Self.Teleport(loc);
API.Finish(0); 



Let's break this one down.  The first line sacrifices 5 health in exchange for enough magic to do something interesting.

Next, we create a variable with the let statement, called loc.  After the = sign, we're getting the result of a function called API.Target(), this gives us the location under the mouse cursor.

After that we run the function API.Self.Teleport(loc).  This function relocates our player to the location in the loc variable.

Take note of the API.Finish(0) command on the last line.  This is the command that instructs the API to only run the incantation one time.  If this line were missing, the incantation would continue to run, sacrificing 5 health every time the game cycle updates.  In addition to that, the 0 in parenthesis is specific to which incantation should be finished.  0, 1, or 2, the index for each of the incantations bound to the player's R, F and V keys.

And there you have it.  Some sample incantations, a little background on potentially the most powerful feature in Inventaverse.  Use it wisely.

Until next time...

Tuesday, January 8, 2019

From Lasers to Lightning - By Josh Hollis

Prerequisite knowledge - Fundamental understanding of Canvas, some HTML5 and Javascript familiarity.
Disclaimer - Do not expect this code to magically work in your application.  The code in this post is meant to explain the concepts behind how beams and bolts are rendered in Inventaverse, not as a copy paste resource.


1.21 Gigawatts!

There comes a time in one's life when it becomes necessary to obliterate the enemy with more than just beams.  If we want to ensure that every atom of matter has been thoroughly and properly destroyed, we want to use 1.21 Gigawatts of power to do it!

In this article I'll go over the concepts behind creating a simple laser beam in Javascript.  Then I'll show you how we can spice up our laser beam by segmenting it and turning it into an awesome lightning bolt!


Lasers... an elegant weapon for a more civilized age

That's right, lasers!  Or, in our case, a couple of lines that alternate colors rapidly so as to give the impression of being a laser.  Here's how we do it:

With the grace of the great drawing artist Escher, we'll begin with a single line.

Our renderLaser function takes starting point, slope and distance.  We'll describe our line using it's slope as a parameter instead of supplying the start x,y and end x,y because we're going to do something with that later.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
function renderLaser(start, slope, distance) {
  // first, we'll calculate the endpoint.
  let end = {
    X : start.X * slope * distance,
    Y : start.Y * slope * distance
  }

  context.beginPath();
  context.moveTo(start.X, start.Y);
  context.lineTo(end.X, end.Y);
  context.stroke();
}

Nothing to it, if you've wired up your canvas correctly, and you've correctly called this function then you should have a nice solid line that looks something like this line from Inventaverse:




Now, add one megajoule of pulsating laser power.  We'll alter our renderLaser function slightly by alternating it's color every frame between two colors supplied as a parameter, by using the modulus operator % (secretly the most useful operator for sprite animation, in the universe).


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
function renderLaser(start, slope, distance, colors) {
  // first, we'll calculate the endpoint.
  let end = {
    X : start.X * slope * distance,
    Y : start.Y * slope * distance
  }

  context.beginPath();
  context.strokeStyle = window.frameCounter % 2 === 0 ? colors[0] : colors[1];
  context.moveTo(start.X, start.Y);
  context.lineTo(end.X, end.Y);
  context.stroke();
}

You may have noticed an additional variable hanging off the window object here (which is generally a bad practice, but for the sake of this exercise, it's fine), frameCounter.  This is just a count of the total number of frame drawn since the script was loaded.  Simply increment this every time requestAnimationFrame calls your drawing function and your laser will alternate between two supplied colors quite nicely.

Let's animate one more property of our line, the width.  


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
function renderLaser(start, slope, distance, colors, widths) {
  // first, we'll calculate the endpoint.
  let end = {
    X : start.X * slope * distance,
    Y : start.Y * slope * distance
  }

  context.beginPath();
  context.strokeStyle = window.frameCounter % 2 === 0 ? colors[0] : colors[1];
  context.lineWidth = window.frameCounter %2 === 0 ? widths[0] : widths[1];
  context.moveTo(start.X, start.Y);
  context.lineTo(end.X, end.Y);
  context.stroke();
}

Now that we're all on the same page...

At this point, you're right about where I was at when I decided I wanted some of the weapons in Inventaverse to do more than just fire a beam.  I wanted a little more sizzle, and some variety.  

So, how do we turn lasers into lightning bolts?

Well, there's more than one way to discharge a massive bolt of electricity, and the way that made the most sense to me was this:

  • break our beam up into lots of little line segments.
  • at each of the points where the line segments touch, jitter the x and y coordinates such that the line is no longer straight.
  • season to taste.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function renderLightning(start, slope, distance, colors, widths) {
  const nodes = 500;
  const cracle = 16;
  let bn = [];
  let scalar = 0;

  // pick a bunch of points on our line and jitter them up!
  for(let n = 0; n < nodes; n++) {
    scalar += (Math.random() * ((distance-scalar)/nodes));
    let r = {
      X : (Math.random() * crackle) - crackle/2, // jitter the x a little
      Y : (Math.random() * crackle) - crackle/2  // jitter the y a little
    };
    bn.push({ X : slope * scalar + r.X, Y : slope * scalar + r.Y });
  }

  context.beginPath();
  context.strokeStyle = window.frameCounter % 2 === 0 ? colors[0] : colors[1];
  context.lineWidth = window.frameCounter %2 === 0 ? widths[0] : widths[1];
  context.moveTo(start.X, start.Y);

  bn.forEach((v, i) => {
    context.lineTo(v.X, v.Y);
  });

  context.stroke();
}

Here's what it ends up looking like!  Not too shabby eh?




Lightning Speed

Alright, we have lightning, but it's... slow lightning...  Let's see what we can do to speed this up.

Obviously the slowest part is the iteration.  Javascript is perfectly capable of executing 500 iterations in far less than a millisecond, so expecting it to do it in under 16.67 ms is perfectly reasonable.  However, there is certainly room for improvement.  Generating a random number is slow. 

Back in the day, when we wanted to avoid doing expensive computations at run time, we would generate a pool of results ahead of time, and then perform a quick lookup.  This is faster than generating individual random numbers inline by a degree of magnitude. 

Also, a basic for loop executes about 10 times faster than a forEach.  Sorry hipsters!  Save your fancy ES6 array functions for one-time situations, not real time graphics scenarios.

Make these minor modifications to your lightning bolt and you'll shave the render time down to practically nothing!

One final note: you could make your renderLaser function a little easier to call into by wrapping all it's parameters into one laser configuration json object, and adding a default parameter object.  Sometimes when you end up with 4+ parameters, things start looking a little crazy.

Using the techniques I've covered in this article, we can create some pretty amazing lightning effects, see for yourself:







At this point, the only question remaining is: How do you create a creature that is so awesome that it would necessitate using our badass new lightning bolt to destroy it?  

But that my friends, is a story for anther day.

Until next time...