Permalink
Browse files

Initial import.

  • Loading branch information...
stephank committed Jun 5, 2010
0 parents commit 719eac72282fd46773a31184a7b67c058de9e70e
@@ -0,0 +1,6 @@
+*.lint.js
+*.pyc
+*.pyo
+dist/arashi.js
+dist/arashi.css
+
339 COPYING

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,39 @@
+RHINO ?= js
+JSLINT ?= ../jslint.js
+
+JAVA ?= java
+YUICOMP ?= ../yuicompressor.jar
+
+
+JSFILES := $(shell find src -iname '*.js' | grep -v '.lint.js')
+
+usage:
+ @echo "The following make targets are defined:"
+ @echo " dist: Create compressed JavaScript and CSS."
+ @echo " lint: Run JSLint on all JavaScript source files."
+ @echo " clean: Remove any files created by the above."
+
+dist: dist/arashi.js dist/arashi.css
+
+clean:
+ -rm -f dist/arashi.js dist/arashi.css
+ -find src -iname '*.lint.js' | xargs rm -f
+
+lint:
+ for i in ${JSFILES}; do \
+ echo "Linting $$i..."; \
+ cat util/lint.head.js $$i > $$i.lint.js; \
+ ${RHINO} ${JSLINT} $$i.lint.js; \
+ rm -fr $$i.lint.js; \
+ echo; \
+ done
+
+dist/arashi.js:
+ cat util/dist.head.js ${JSFILES} \
+ | ${JAVA} -jar ${YUICOMP} --type js \
+ > dist/arashi.js
+
+dist/arashi.css:
+ ${JAVA} -jar ${YUICOMP} --type css -o dist/arashi.css stylesheet.css
+
+.PHONY: usage dist clean lint
@@ -0,0 +1,57 @@
+# ArashiJS
+
+ArashiJS is a (work-in-progress) Tempest-clone written in JavaScript and HTML5.
+
+ArashiJS is adapted from Project ARASHI for the Apple Macintosh.
+Project Arashi is available at: http://users.tkk.fi/jmunkki/cards/arashi.html
+
+## Playing
+
+The game is incomplete at the time of writing.
+
+To launch, simply open `arashi.html` in a browser.
+
+## License
+
+No license disclaimer was attached to Project ARASHI. I'm considering the GNU GPL v2 a safe bet
+while I contact the authors. A copy of the license is attached in the COPYING file.
+
+## Directory structure
+
+* `src` contains all the JavaScript source code.
+* `snd` contains the WAV PCM conversions of the original sounds.
+* `img` contains the SVG and PNG conversions of the original images.
+* `util` contains some utilities used in conversion and by the `Makefile`.
+* `dist` contains distributables created by `make`.
+
+## Hacking
+
+The game loop is found in `src/engine.js`. The engine basically keeps track of the game state, and
+calls the related handler method each frame. These methods in turn live in the source files
+underneath `src/gamestates/`.
+
+All other files are basically utilities for getting things done:
+
+* The `src/vakit/` directory contains drawing utilities (which stem from the `VAKit` library in the
+original Project ARASHI).
+
+* The `src/soundkit.js` library is a minimal abstraction for playing sound effects.
+
+* The `src/random.js` library contains a pseudo-random number generator. The most significant
+feature of this is that it is seedable. (This is necessary for playback of recordings.)
+
+* The `src/grid.js` library contains the code for reading and drawing the level's grid, and
+includes definitions for levels converted from the original.
+
+A `Makefile` is included, which fulfills some optional development tasks:
+
+* `make lint` runs JSLint on all source files. Before each source file is processed, the file
+`util/lint.head.js` is concatenated. This file contains the default JSLint options used throughout
+the source code. You can override the environment variables RHINO and JSLINT if the defaults don't
+work for your set-up.
+
+* `make dist` creates the compressed JavaScript and CSS distributables under `dist/`. The file
+`util/dist.head.js` is concatenated to the input of the compressor. You can override the
+environment variables JAVA and YUICOMP if the defaults don't work for your set-up.
+
+* `make clean` is your run-off-the-mill cleaning target for the above two.
@@ -0,0 +1,77 @@
+<!doctype html>
+<html>
+<head>
+
+<title>Project ARASHI</title>
+<link rel=stylesheet media=screen href="stylesheet.css">
+
+<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.js"></script>
+<script src="src/globals.js"></script>
+<script src="src/engine.js"></script>
+<script src="src/random.js"></script>
+<script src="src/soundkit.js"></script>
+<script src="src/grid.js"></script>
+<script src="src/vakit/7segment.js"></script>
+<script src="src/vakit/14segment.js"></script>
+<script src="src/vakit/starfield.js"></script>
+<script src="src/vakit/sizzling.js"></script>
+<script src="src/vakit/logo.js"></script>
+<script src="src/vakit/lightning.js"></script>
+<script src="src/gamestates/test.js"></script>
+<script src="src/gamestates/title.js"></script>
+<script src="src/gamestates/game.js"></script>
+
+<script>
+$(document).ready(function () {
+ $('#d').show();
+ $('#s a').focus();
+});
+function start() {
+ $('#d').hide();
+ Engine.start();
+}
+</script>
+
+</head>
+<body>
+
+<audio src="snd/blast.wav" autobuffer></audio>
+<audio src="snd/blow.wav" autobuffer></audio>
+<audio src="snd/bonk.wav" autobuffer></audio>
+<audio src="snd/dziuung.wav" autobuffer></audio>
+<audio src="snd/fadeinphazer.wav" autobuffer></audio>
+<audio src="snd/fadeoutphazer.wav" autobuffer></audio>
+<audio src="snd/fallyell.wav" autobuffer></audio>
+<audio src="snd/fallzap.wav" autobuffer></audio>
+<audio src="snd/flythru.wav" autobuffer></audio>
+<audio src="snd/phazer.wav" autobuffer></audio>
+<audio src="snd/splitter.wav" autobuffer></audio>
+<audio src="snd/springy.wav" autobuffer></audio>
+<audio src="snd/swish.wav" autobuffer></audio>
+<audio src="snd/swoosh.wav" autobuffer></audio>
+<audio src="snd/tadaum.wav" autobuffer></audio>
+<audio src="snd/whiz.wav" autobuffer></audio>
+<audio src="snd/zrooming.wav" autobuffer></audio>
+<audio src="snd/zzfreelife.wav" autobuffer></audio>
+<audio src="snd/zzsuperzap.wav" autobuffer></audio>
+
+<div id="h"></div>
+<div id="v"></div>
+<div id="c"><canvas id="game" width="800" height="600"></canvas></div>
+
+<div id="d" style="display: none">
+<p>
+ <strong>Heads-up:</strong> this page contains multimedia content;<br>
+ adjust your speaker volume!
+</p>
+<p>
+ Compatibility is limited. Best chances with Firefox 3.5+.<br>
+ Audio may be problematic on certain systems/browsers.
+</p>
+<p id="s">
+ <a href="javascript:start()">Continue</a>
+</p>
+</div>
+
+</body>
+</html>
@@ -0,0 +1 @@
+This directory holds compressed and post-processed distributables created by Makefile.
Binary file not shown.
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
+<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000303 Stylable//EN" "http://www.w3.org/TR/2000/03/WD-SVG-20000303/DTD/svg-20000303-stylable.dtd"><svg width="9.11111in" height="2.5in" viewBox="0 0 656 180"> <desc> A picture created by Pict2SVG </desc> <g><!-- Line({-100, -100}) --><line x1="-99" y1="-99" x2="-100" y2="-100" style="stroke:rgb(0%, 0%, 0%); stroke-width:1" /><!-- Line({0, 0}) --><line x1="1" y1="1" x2="0" y2="0" style="stroke:rgb(0%, 0%, 0%); stroke-width:0" /><!-- Line({656, 180}) --><line x1="655" y1="179" x2="656" y2="180" style="stroke:rgb(0%, 0%, 0%); stroke-width:0" /><!-- Line({-100, -100}) --><line x1="-99" y1="-99" x2="-100" y2="-100" style="stroke:rgb(0%, 0%, 0%); stroke-width:1" /><!-- Poly(kQDGrafVerbPaint, 0x3f5cc430) --><polygon style="fill:rgb(0%, 0%, 0%); stroke:rgb(0%, 0%, 0%); stroke-width:1" points="59,0 117,180 0,180 27,104 50,104 32,158 86,158 50,36 59,0 " /><!-- Poly(kQDGrafVerbPaint, 0x3f5cc430) --><polygon style="fill:rgb(0%, 0%, 0%); stroke:rgb(0%, 0%, 0%); stroke-width:1" points="109,45 176,45 194,54 208,77 208,95 194,117 208,140 208,180 194,180 181,171 181,140 172,126 131,126 122,117 122,108 127,104 176,104 185,95 185,81 172,68 113,68 104,59 104,54 109,45 " /><!-- Poly(kQDGrafVerbPaint, 0x3f5cc430) --><polygon style="fill:rgb(0%, 0%, 0%); stroke:rgb(0%, 0%, 0%); stroke-width:1" points="348,158 434,158 443,153 443,144 402,90 402,63 425,41 461,41 474,59 470,63 434,63 425,68 425,86 456,126 465,149 456,171 443,180 348,180 339,176 348,158 " /><!-- Poly(kQDGrafVerbPaint, 0x3f5cc430) --><polygon style="fill:rgb(0%, 0%, 0%); stroke:rgb(0%, 0%, 0%); stroke-width:1" points="277,0 335,180 218,180 245,104 268,104 250,158 304,158 268,36 277,0 " /><!-- Poly(kQDGrafVerbPaint, 0x3f5cc430) --><polygon style="fill:rgb(0%, 0%, 0%); stroke:rgb(0%, 0%, 0%); stroke-width:1" points="472,180 521,18 530,9 539,32 517,108 557,108 566,126 512,126 494,180 472,180 " /><!-- Poly(kQDGrafVerbPaint, 0x3f5cc430) --><polygon style="fill:rgb(0%, 0%, 0%); stroke:rgb(0%, 0%, 0%); stroke-width:1" points="557,180 607,18 616,9 625,32 580,180 557,180 " /><!-- Poly(kQDGrafVerbPaint, 0x3f5cc430) --><polygon style="fill:rgb(0%, 0%, 0%); stroke:rgb(0%, 0%, 0%); stroke-width:1" points="607,180 638,72 647,63 656,86 629,180 607,180 " /> </g></svg>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,117 @@
+Engine = {
+ machine: null,
+ state: null,
+ showFps: false
+};
+
+Engine.start = function() {
+ var canvas = $('#game')[0];
+
+ // Globals
+ frame = {
+ w: canvas.getAttribute('width'),
+ h: canvas.getAttribute('height'),
+ mouseX: 0,
+ mouseY: 0
+ };
+ c = canvas.getContext('2d');
+
+ // Track mouse position
+ $().mousemove(function(e) {
+ frame.mouseX = e.pageX - canvas.offsetLeft;
+ frame.mouseY = e.pageY - canvas.offsetTop;
+ });
+
+ // Init sound kit
+ Snd.init();
+
+ // All systems, go!
+ this.resume();
+ this.startMachine(TitleMachine);
+};
+
+// Start a game state machine
+Engine.startMachine = function(machine) {
+ this.machine = machine;
+ this.transition('start');
+};
+
+// Transition to a different state in the current state machine.
+// +delay+ is optional, and is a delay in milliseconds.
+Engine.transition = function(state, delay) {
+ if (delay) {
+ this.state = null;
+ this.pause(delay, function() {
+ Engine.transition(state);
+ });
+ }
+ else {
+ this.state = this.machine[state];
+ var enterMethod = this.machine['enter_' + state];
+ if (enterMethod) { enterMethod.apply(this.machine); }
+ }
+};
+
+// Pause the engine, duration is optional and in milliseconds.
+Engine.pause = function(duration, callback) {
+ if (this.frameTimer) {
+ clearInterval(this.frameTimer);
+ this.frameTimer = null;
+ }
+ if (duration) {
+ if (this.pauseTimer) {
+ clearTimeout(this.pauseTimer);
+ }
+ this.pauseTimer = setTimeout(function() {
+ Engine.pauseTimer = null;
+ Engine.resume();
+ if (callback) { callback(); }
+ }, duration);
+ }
+};
+
+Engine.resume = function() {
+ if (this.pauseTimer) {
+ clearTimeout(this.pauseTimer);
+ this.pauseTimer = null;
+ }
+ if (!this.frameTimer) {
+ this.frameTimer = setInterval(function() {
+ Engine.render();
+ }, 50);
+ }
+};
+
+// Blank the entire screen
+Engine.blank = function() {
+ c.globalAlpha = 1.0;
+ c.fillStyle = 'black';
+ c.fillRect(0, 0, frame.w, frame.h);
+};
+
+// Render a frame
+Engine.render = function() {
+ var s = new Date();
+
+ // Clear
+ this.blank();
+
+ // Do the game magic
+ if (this.machine && this.state) {
+ this.state.apply(this.machine);
+ }
+
+ // Draw frame render time in ms
+ if (this.showFps) {
+ var d = new Date() - s;
+ c.beginPath();
+ c.save();
+ c.translate(0.5, 0.5); // Pixel align
+ c.scale(3,3); c.translate(1,1);
+ Dig7Segment.drawNumber(d);
+ c.restore();
+ c.lineWidth = 1;
+ c.strokeStyle = 'white';
+ c.stroke();
+ }
+};
@@ -0,0 +1,44 @@
+var
+
+GameMachine = {
+ enter_start: function() {
+ this.grid = Grids.Circle16;
+ Starfield.color = this.grid.color = [0,0,255];
+ Engine.transition('flyInStars');
+ },
+
+ enter_flyInStars: function() {
+ setTimeout(function() { Starfield.twistFromGrid(GameMachine.grid); }, 1000);
+ setTimeout(function() { Engine.transition('flyInGrid'); }, 3000);
+ },
+ flyInStars: function() {
+ Starfield.feed();
+ Starfield.ride();
+ },
+
+ enter_flyInGrid: function() {
+ this.grid.distance = C.flyInStart;
+ },
+ flyInGrid: function() {
+ Starfield.ride();
+ this.grid.draw();
+ if (this.grid.distance <= 0) {
+ this.grid.distance = 0;
+ Engine.transition('main');
+ }
+ this.grid.distance -= C.flyInAdvance;
+ },
+
+ enter_main: function() {
+ // FIXME
+ Engine.pause();
+ },
+ main: function() {
+ },
+
+ enter_flyThru: function() {
+ // FIXME
+ },
+ flyThru: function() {
+ }
+};
Oops, something went wrong.

0 comments on commit 719eac7

Please sign in to comment.