diff --git a/fuTris.js b/fuTris.js index 71a47f9..f1a8f69 100644 --- a/fuTris.js +++ b/fuTris.js @@ -7,6 +7,8 @@ var field = []; var background = []; var game_running = true; +var subframe = 0; +var moved_steps = 0; var speed = 100; var points = 0; var level = 0; @@ -143,6 +145,12 @@ function draw() { // Level draw_text(level, 30, 420, 230); draw_text('Level', 13, 420, 250); + + // Game over? + if (!game_running) { + draw_text("Game over", 60, 40, 250); + draw_text("Press R for a new game", 20, 140, 270); + } } function noice(offset, level) { @@ -267,9 +275,10 @@ addEventListener('keydown', function(event) { if (game_running) loop(); } - // TODO: Back to the main menu - if (event.keyCode == 27 || event.keyCode == 121) - console.log('Implement me.'); + // Restart the game + if (event.keyCode == 82 && !game_running) { + init(); + } }); function init() { @@ -277,7 +286,48 @@ function init() { points = 0; level = 0; stones = 0; + game_running = true; + subframe = 0; + moved_steps = 0; + + for (var x=0; x<10; x++) + for (var y=0; y<16; y++) + field[x][y] = 0; + // Start the game + next_shape(); + loop(); +} + +function loop() { + // Move the next step + subframe++; + if (subframe-speed > 0.0) { + subframe = 0; + speed = 100-(level*15); + + // Check if we get blocked by the already dropped shapes + +function() { + if (will_collide(angle, pos)) { + freeze(); + clear_full_lines(); + next_shape(); + + // Game over? + if (moved_steps === 0 || will_collide(0, {left: 4, top: 0})) + game_running = false; + moved_steps = 0; + return true; + } + return false; + }() || (pos.top++ && moved_steps++); + draw(); + } + + if (game_running) setTimeout(loop, 5); +} + +function setup() { // Load the assets assets.rotate.load(); assets.drop.load(); @@ -302,41 +352,7 @@ function init() { field[x][y] = 0; } } - - // Start the game - next_shape(); -} - -var subframe = 0; -var moved_steps = 0; - -function loop() { - // Move the next step - subframe++; - if (subframe-speed > 0.0) { - subframe = 0; - speed = 100-(level*15); - - // Check if we get blocked by the already dropped shapes - +function() { - if (will_collide(angle, pos)) { - freeze(); - clear_full_lines(); - next_shape(); - - // Restart the game? - if (moved_steps === 0 || will_collide(0, {left: 4, top: 0})) - init(); - moved_steps = 0; - return true; - } - return false; - }() || (pos.top++ && moved_steps++); - draw(); - } - - if (game_running) setTimeout(loop, 5); } +setup(); init(); -loop(); diff --git a/index.html b/index.html index 16e92e4..cb7ad2e 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,17 @@
+A js13kGames 2014 entry (source) + by Aaron Fischer.
+ + +Use the arrow keys to move (←, →, rotate + (↑) and drop (↓) stones. Press P for + pause the game. If you messed up, restart with R. Vim-users + will also find a way to play :)
+ diff --git a/main.css b/main.css new file mode 100644 index 0000000..fdb0786 --- /dev/null +++ b/main.css @@ -0,0 +1,36 @@ +html { + background-color: #333; + color: #bbb; + font-family: Verdana, "DejaVu Sans"; +} + +body { + margin: auto; + width: 514px; +} + +canvas { + border: 2px solid #444; +} + +h1 { + color: white; + text-align: center; + font-size: 70px; + margin: 0; +} + +a { + color: #4f6c19; +} +a:hover { + color: #8fc32e; +} + +span { + background-color: #444; + border-radius: 3px; + padding: 2px 5px; + font-weight: bold; + color: white; +} \ No newline at end of file diff --git a/screenshot_big.png b/screenshot_big.png new file mode 100644 index 0000000..3cb945b Binary files /dev/null and b/screenshot_big.png differ diff --git a/screenshot_small.png b/screenshot_small.png new file mode 100644 index 0000000..de45dc7 Binary files /dev/null and b/screenshot_small.png differ diff --git a/submission/assets/drop.wav b/submission/assets/drop.wav new file mode 100644 index 0000000..e3aa0b2 Binary files /dev/null and b/submission/assets/drop.wav differ diff --git a/submission/assets/move.wav b/submission/assets/move.wav new file mode 100644 index 0000000..3a522b5 Binary files /dev/null and b/submission/assets/move.wav differ diff --git a/submission/assets/point.wav b/submission/assets/point.wav new file mode 100644 index 0000000..67064b3 Binary files /dev/null and b/submission/assets/point.wav differ diff --git a/submission/assets/rotate.wav b/submission/assets/rotate.wav new file mode 100644 index 0000000..b21d1af Binary files /dev/null and b/submission/assets/rotate.wav differ diff --git a/submission/fuTris.js b/submission/fuTris.js new file mode 100644 index 0000000..78f7a69 --- /dev/null +++ b/submission/fuTris.js @@ -0,0 +1 @@ +function shape(a,b){var c=shapes[a];switch(c.length){case 1:return c[0];case 2:return c[b%2];case 4:return c[b]}}function rect(a,b,c,d,e,f){context.fillStyle="#"+f,context.fillRect(a*e,b*e,c*e,d*e)}function draw_shape(a,b,c,d,e){for(var f=0;fA js13kGames 2014 entry (source) + by Aaron Fischer.
+ +Use the arrow keys to move (←, →, rotate + (↑) and drop (↓) stones. Press P for + pause the game. If you messed up, restart with R. Vim-users + will also find a way to play :)
+ + + + + + + diff --git a/submission/js13kgames-aaronfischer.zip b/submission/js13kgames-aaronfischer.zip new file mode 100644 index 0000000..5943c76 Binary files /dev/null and b/submission/js13kgames-aaronfischer.zip differ diff --git a/submission/main.css b/submission/main.css new file mode 100644 index 0000000..fdb0786 --- /dev/null +++ b/submission/main.css @@ -0,0 +1,36 @@ +html { + background-color: #333; + color: #bbb; + font-family: Verdana, "DejaVu Sans"; +} + +body { + margin: auto; + width: 514px; +} + +canvas { + border: 2px solid #444; +} + +h1 { + color: white; + text-align: center; + font-size: 70px; + margin: 0; +} + +a { + color: #4f6c19; +} +a:hover { + color: #8fc32e; +} + +span { + background-color: #444; + border-radius: 3px; + padding: 2px 5px; + font-weight: bold; + color: white; +} \ No newline at end of file