Code Monkey home page Code Monkey logo

earthbound-battle-backgrounds-js's Introduction

Earthbound Battle Backgrounds JS

Earthbound Battle Background JS is exactly what its name implies: the battle backgrounds from the SNES RPG Earthbound/Mother 2, rendered entirely in client-side JavaScript.

If you like this project, you might also like the Earthbound Battle Backgrounds Live Wallpaper, which is a Java/Android implementation.

How it works

Every battle background is composed of two layers, each with 327 possible styles (including "blank"/zero). The layer styles can be interchanged, such that Layer 1: 50 and Layer 2: 300 is the same as Layer 1: 300 and Layer 2: 50. Thus, there are C(n,r) = 52,650 possible different background combinations. Obviously, this many don't exist in the game--the SNES's graphical capabilities only allow it to properly render 3,176 of these combinations, and of those, only 225 are ever used.

The data for each of the 327 styles is bundled within the SNES cartridge. Tiles are constructed from various memory addresses in Earthbound game data. To create the distortion effect, the following function is used:

Offset (y, t) = A sin ( F*y + S*t )

where:

  • y is the vertical coordinate being transformed
  • t is time that's elapsed
  • A is the amplitude
  • F is the frequency
  • S is the speed or frameskip of the transformation

Offest refers to the y direction of the shift at a given time t.

There are also three types of distortions that use the result of the Offset function:

  • Horizontal translations, where each line is shifted left by the given number of pixels
  • Horizontal interlaced translations, where every other line is shifted right by the given number of pixels
  • Vertical compression translations, where each line is shifted up or down by the given number of pixels

Different backgrounds use different distortion effects.

List of backgrounds

It's pretty damn hard to find out which battle backgrounds correspond to which enemies. You can review the list of enemies matched with known battle backgrounds to try and get your favorite on the Suggested Layers option. If you discover a new one, please, email me and I'll add it to the list, giving you full credit!

Running locally

Make sure you have Node.js and NPM on your system. Then:

npm install
npm run watch
npm start
open http://localhost:8888

Note that this code runs entirely in the browser! Node is only used to start an Express server.

License

This app is in no way endorsed or affiliated by Nintendo, Ape, HAL Laboratory, Shigesato Itoi, etc. It's licensed under MIT.

Credits

I am entirely indebted to Mr. Accident of forum.starmen.net for the original battle background generation code, which was a C# project that uses the battle backgrounds as Windows screensavers. He also provided me with help along the way, and as far as I'm aware, he discovered the math behind it all, including the entire Offset function calculation. This port would be nothing without him.

In 2016, @kdex rewrote much of my shitty JS into nice and clean ES2016 code, for which I am grateful. As of dc877f33, the entirety of his modifications have been brought over here.

Additionally, everyone who worked on PK Hack or was even associated with the project. It's incredible to witness such a powerful community of fans who have turned a wonderful game inside-out over and over again.

earthbound-battle-backgrounds-js's People

Contributors

dependabot[bot] avatar gjtorikian avatar rofish avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

earthbound-battle-backgrounds-js's Issues

Background data change issue

I am replicating this repo for the sake to change background.
The most interesting part is how you generated truncated_backgrounds.dat and where you use backgrounds.dat file.
I want to change the files with my own png files, but I cannot find proper documentary or method.

Layering Combination Possibilities

Hey there, first off let me say this is amazingly incredible!

Thought I would point out a minor possible inaccuracy: In your README.md, it says there are 52,650 combinations of backgrounds which potentially exist in EarthBound. As it turns out, the 327 background layers are divided into two groups:

  • 250 background layers which use a 16-color palette
  • 77 background layers which use a 4-color palette

EarthBound only ever displays backgrounds which are either composed of a single 16-color layer, or a combination of two 4-color layers. This is because combining a 16-color layer with anything else results in glitchiness, as the SNES's memory is not sufficiently large to handle it. So the EarthBound engine actually supports far fewer than 52,650 combinations. But your battle background renderer doesn't seem to have this same technical limitation, so I guess you could say your renderer is superior to the original one! ๐Ÿ˜„

Porting new version to Android/Java.

Hello! I'm a student who has been using the app version of this, Abstract Art, for close to 10 years at this point and I was interested in porting the JS versions with all of the improvements and bells and whistles and what not over to Android again (mainly for experience) and I was wondering if I could get in better contact with you somehow about tips on how the math behind the backgrounds work.

Certain Backgrounds Scale Incorrectly

Backgrounds using a certain kind of distorted scaling method continue in the same direction forever, causing the background to shrink indefinitely. The original game does not do this, of course. Three such examples are numbers 110, 86, and 43. This issue has been observed since well before 2016, but I do not know if it was there since the very beginning.

Tested on the website versions.

Mr. Batty (Suggested Layers)

From all the images and footage I've found where Mr. Batty is the only enemy type to be found, the background used is 73,0. It could be 72,0, admittedly but I don't think so: the footage I've seen has the BG moving too fast for it to be 72,0.

I have no idea who 89,0 is used for, but plain ol' Mr. Batty uses the same BG as Elder Batty and Arachnid!.

(I would have put this under Pull Requests, if I had any idea how. It kept redirecting me and kept talking about comparisons for some reason, so I just gave up on that.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.