1
0
Fork 0
Commit Graph

12 Commits (ba6bc593d6b28df2a1acc0de068d78e50df298a5)

Author SHA1 Message Date
Mike Gerwitz ba6bc593d6 Dynamic event target for ClassicGame
Decouple from Window.
2015-12-21 00:20:36 -05:00
Mike Gerwitz d856fbb957
Build combined lasertank.js
This does something that could not be done trivally back when this project
started: concatenate all files, which are written as CommonJS modules.  I
had to write custom code to do this with other projects; Browserify was but
an infant back in the day, and I remember SubStack talking about it on
freenode.
2015-12-20 22:39:05 -05:00
Mike Gerwitz f4a61bf28a
ease.js version update (0.1.1); using non-minified version for development
A build can use the minified version for distribution
2013-01-19 22:59:02 -05:00
Mike Gerwitz 8f3ce4f8c6
Initial concept for player (tank) movement; state-driven map
Rendering now relies on hooking MapState, which represents the current state of
the map, raising events as various game objects change position or state.

This is a simple proof-of-concept---the tank moves, but only upward, and the
tile redraw does need work. There is no collision detection.
2013-01-19 13:50:50 -05:00
Mike Gerwitz 2c018a94b5 Began refactoring game logic into ClassicGame 2012-03-27 21:34:33 -04:00
Mike Gerwitz 3d3bee68f6 Refactored menu bar logic into ui/MenuBar 2012-03-26 19:28:00 -04:00
Mike Gerwitz 2454739d75 Initial menu concept
One of the only remaining portions of the UI at this point (disregarding missing
functionality) was the menu bar. At this point, I had to make a number of
choices, among them:

  - Do I mimic the original Windows UI, or provide a more native experience?
  - Do I support pre-{CSS3,ES5,HTML5} environments, or take advantage of each?

The menu bar in this commit has the boxy style of the classic Windows theme --
not because I like it, but because it is representative of the original game,
which was available only for that operating system. The same style is applied to
the color of the "window" div in which the game is contained, as well as any
dialogs. However, the buttons displayed on the screen are in the style native to
the user's environment. With Gecko and Webkit offering the ability to style
elements (including menu bars, etc) in a way that looks native[1], the question
naturally arises -- do we provide more of a native port look, or a true clone
look? Should the latter be the case, it may be more appropriate to style the
buttons as boxes.

The next decision was whether or not to support environments that do not provide
many of the common CSS3, ES5 and HTML5 features. Initially, the project wished
to use CSS sprites in order to support older browsers, however with the move to
the canvas element, it seems unnecessary to provide such compatibility. Consider
also the push by organizations like Mozilla and Google to automatically upgrade
users' browsers, helping to ensure they have the newest available features. Also
consider that supporting older environments only discourages users to upgrade,
feeding the challenges that web developers already face in creating
cross-browser software. With all of that, the decision was made to simply use
the features provided by ECMAScript 5, CSS3 and HTML5, using browser extensions
where necessary (for unstandardized features, e.g. -prefix-foo in CSS).

It is rare that I get to work intimately with these newer features, as I find
myself most often having to maintain compatibility with older environments. This
will be an exciting chance to be able to explore these features and to showcase
them for others who wish to see them used in a complete piece of software. That
said, LaserTank is a fairly old game and, as such, is unlikely to take advantage
of features like CSS transitions (animations are handled by timers and rendered
to the canvas and there is not much else to transition), as that would take away
from the retro feel of the original game.

With the menu implementation, I attempted to limit myself to CSS as much as
possible in order to reduce the amount of code that had to be written for the
display of the menus and dialogs. The menus display using the :hover selector
and the dialogs with the new :target selector. JavaScript is used to to register
click events on the menu so that moving the mouse to another menu item will have
it automatically displayed, keeping each of the menus hidden until a click.
JavaScript is also used to determine when the menu should be hidden on mouseout.
The menu does not function exactly like the menu in Windows, but it will be
functional for now. I would like to worry about such issues after the bulk of
the game logic has been developed.

This commit's implementation is conceptual; it will be refactored shortly.

[1] https://developer.mozilla.org/en/CSS/-moz-appearance
2012-03-26 19:28:00 -04:00
Mike Gerwitz bbb718eb88 Added control buttons (not yet functional)
- Pixel precision for padding/margins, but button size left to window system
2012-03-26 19:28:00 -04:00
Mike Gerwitz 0736ce5867 Began adding opening image to game screen
- Note that this is stretched to fit the full size of the board
2012-03-26 19:28:00 -04:00
Mike Gerwitz 9465af62cb Began adding index.html, which will hold the actual game
This essentially is a simplified demo page, styled to begin looking like the
actual game.
2012-03-26 19:27:57 -04:00
Mike Gerwitz fe2dbcac19 Moved global var declarations to main.js to be shared with game 2012-03-21 00:38:25 -04:00
Mike Gerwitz 3ed7959434 Initial commit illustrating LTG loading and masking
This project -- creating a LaserTank clone in JavaScript -- deserves some
discussion before diving into the implementation details (you may skip to the
separator below for implementation details without the history). LaserTank is a
game that has a special place in my heart. Not only is it a witty and enjoyable
game, but it is in fact the reason I began programming as a young boy in the
first place. While it is likely that I would have eventually picked up a
programming book for some other reason, I owe that point in time entirely to
this game.

Allow me to explain. At the age of 10, I would spend much of my time on the
Internet downloading various games and demos that may satisfy my interests (the
old days of CNET's download.com showed me many of those, I believe). One of
those games that immediately captivated me was LaserTank, but not purely for
reasons of gameplay. It had this wonderful feature that added so much potential
(and replayability) to the game -- a map editor.

I found myself enthralled with the map editor to the point where I spent all my
time creating maps rather than playing the game. What fascinated me was the
ability to essentially create portions of the game -- to tell the game what to
do and how to function. I was not able to create my own game using this editor,
but I felt like I was creating portions of it. That said, I soon realized that
it wasn't enough; I needed to do more.

It was the limitations of the map editor and the enjoyment of creating the maps
that caused me to convince my parents to take me to Barnes and Noble to purchase
my first programming book - Learn to Program with Visual Basic 6 by John Smiley
(N.B. Visual Basic is proprietary and I cannot recommend using it. I had no
knowledge of the evils of proprietary software back at that point in time.) My
parents had their doubts, but that only pushed me even harder to learn.

Ironically, the book was about creating a business application. I found this
process very enjoyable and began focusing more on conventional desktop software
rather than gaming. I did create a couple games (bop-a-mole and breakout among
others), but my focus was never game development. Eventually, I moved on from
Visual Basic and got into web development. Following that, I discovered
GNU/Linux and began getting more and more into lower-level systems and languages
(such as C and ASM) and began adopting the hacker ethic. That brings us to where
I am today -- nearly 13 years later. It would only seem fitting to bring my
hobby-turned-career full circle by cloning the very game that started
everything.

When I say "clone", I mean nothing more; there will be no additional features
or modifications to the original gameplay, menus, graphics, etc. It will support
all original file formats (I will develop none of my own). The only differences
between the clone and the original game will arise from the obvious issues
introduced by cloning the game on a web platform. Specifically, the user will
have the option to load files from either their local box or a remote resource,
and I may provide pre-masked tile sets for browsers that do not support the
canvas element (a fallback mode, if you will). No matter what the change,
though, the gameplay will remain identical.

That said, the library resulting from the clone will be built with extensibility
in mind. If a user (or myself) wishes to create a derivative work by hooking or
extending the library (for example, to support larger maps, add additional
blocks/enemies, multiplayer support, etc), that should be fairly trivial to do.
However, those works will be entirely separate from the clone and clearly
distinguished. I think the original LaserTank is perfect the way it is.
Remember, it has a special place in my heart (aww) and I would like to preserve
the game as I remember it back then.

---

Alright; now that we have a great deal of unnecessary history out of the way,
let's get into the implementation details for this commit (if you're reading
this as a blog entry, see the first commit). This commit represents a
proof-of-concept showing that the LTG files (containing the LaserTank graphics)
can be properly loaded and their masks properly applied. This was the first
major concern for the project and, if a workaround were needed, would have
prevented me from creating a full clone (as it would not support loading LTG
files without having them first sent to the server, processed, and returned in a
different format).

The LTG file contains some metadata (including the name, author and description)
as well as two bitmaps (BMPs) -- the game tileset and the associated mask. The
game bitmap's position was static, but its length and the offset of the mask
bitmap were provided by the four bytes immediately preceding the game bitmap
(the TLTGREC struct in LTANK.H of the original sources represented this value as
a DWORD, which represents a 32-bit integer). The only challenge with converting
this value into an integer that we could use is its endianness -- is the most
significant byte at the beginning or end? Windows programs (of which LaserTank
is) generally write in little-endian format, but to be sure we can simply open
up the LTG file in your favorite HEX editor (I simply use `xxd`). In the case of
the original tileset, the four bytes immediately preceding the bitmap header (as
identified by 'BM', or `424d`) were `7a f5 00 00`, which on its own clearly
indicates little-endianness. We can verify by searching for 'BM' once again, and
finding that it begins at location `f5 7a` (if your HEX editor displays in
big-endian format). To convert into a number, we can simply add up each byte
individually, left-shifting by 8N bits, where N is the 0-indexed byte position.

Loading the BMP files was then fairly trivial; the file could be loaded into
memory (read from disk using FileReader) and we could cut the relevant portions
of the binary string out. The bitmaps could then be base64-encoded and the
"src" attribute of an Image object set to 'data:image/bmp;base64,B', where B
is the base64-encoded BMP. This could then be rendered however we please - CSS
sprites or to a canvas.

The problem with CSS sprites is that we need to apply the mask and there is no
reliable way to do this without a canvas; transparency in the browser is
normally handled using GIFs or PNGs. As it turns out, the canvas performs
masking using the alpha channel as well, so I would have to create my own
masking algorithm to manipulate the alpha channel of the tileset. To complicate
matters even more, certain tiles had no mask, and they did not consistently
represent the mask with all black (black is used in LT to indicate opacity),
meaning that the algorithm would have to understand what tiles should be skipped
entirely.

The solution was to simply loop through each tile and set the alpha byte of each
pixel relative to the respective pixel on the map. Because the images were
created out of data in memory, the canvas is not tainted when the image is
rendered before using getImageData(). To help speed up the process, since we
know that the mask can only contain black and white, we need only check one of
the channels; we do not need to calculate brightness. This process successfully
returns each individual tile, properly masked, which can be rendered to the
canvas using putImageData(). Crisis averted. With that major concern out of the
way, the clone should no longer be a problem.

I go into more detail in the comments within LtgLoader and TileMasker.

This is going to be an exciting process, both because of the LT clone itself and
because this is my first experience working with the canvas element. As
aforementioned, I seldom create games and I have had no use for the canvas
thus far.

Hopefully this project will be well-received by both those who have played
LaserTank in the past and the original developer of the game (Jim Kindley, JEK
Software). LaserTank is a fairly old game and is not likely to be well known
anymore, but the game itself is a blast (no pun intended) and bringing it to the
browser, where it can be used on any platform (including mobile devices), should
allow everyone to enjoy it.

The source code is released under the GNU AGPL to ensure that the users'
freedoms are preserved even if this game is rendered or in any way run
server-side.
2012-03-12 19:06:11 -04:00