Fixed merge conflicts

This commit is contained in:
Noah Moroze 2014-05-17 18:55:03 -04:00
commit fee067ac51
5 changed files with 111 additions and 40 deletions

View file

@ -66,7 +66,9 @@ function consolidateBlocks(clock,side,index) {
deleted.push([]);
}
eraseBlocks(clock,deleted);
return
}
function eraseBlocks(clock,deleted) {
if(deleted[0].length>0){
side = deleted[0][0];
@ -90,4 +92,22 @@ function eraseBlocks(clock,deleted) {
consolidateBlocks(clock,side,index+vertical+i);
}
}
sidesChanged = [];
if(deleted[1].length>0){
if(deleted[1][0] != "false") {
sidesChanged.push(deleted[1][0]);
}
}
if(deleted[0].length>0){
for(var i=0;i<3;i++) {
if(deleted[0][2] != "false" ) {
sidesChanged.push(getIndex(clock.blocks,deleted[0][0]+deleted[0][2]+i));
}
}
}
sidesChanged.forEach(function(o){
MainClock.blocks[o].forEach(function(block) {
block.settled = 0;
})
});
}

View file

@ -1,5 +1,4 @@
//you can change these to sexier stuff
function Block(lane, color, distFromHex, settled) {
this.settled = (settled == undefined) ? 0 : 1;
this.height = 20;
@ -18,6 +17,7 @@ function Block(lane, color, distFromHex, settled) {
else {
this.distFromHex = 300;
}
this.draw = function() {
this.width = 2 * this.distFromHex / Math.sqrt(3);
this.widthswag = this.width + this.height + 3;
@ -43,7 +43,7 @@ function Block(lane, color, distFromHex, settled) {
}
var Clock = function(sideLength) {
function Clock(sideLength) {
this.fillColor = '#2c3e50';
this.position = 0;
this.sides = 6;
@ -71,7 +71,7 @@ var Clock = function(sideLength) {
consolidateBlocks(this,lane,this.blocks[lane].length-1);
};
this.doesBlockCollide = function(block, iter) {
this.doesBlockCollide = function(block, iter, position, tArr) {
if (block.settled) return;
var lane = this.sides - block.lane;// -this.position;
@ -81,21 +81,33 @@ var Clock = function(sideLength) {
lane += this.sides;
}
lane = lane % this.sides;
var arr = this.blocks[lane];
if (arr.length > 0) {
if (block.distFromHex + iter - arr[arr.length - 1].distFromHex - arr[arr.length - 1].height <= 0) {
this.addBlock(block);
if (position !== undefined) {
arr = tArr;
if (position <= 0) {
if (block.distFromHex - (this.sideLength/2) * Math.sqrt(3) <= 0) {
block.settled = 1;
}
}
else {
if (block.distFromHex + iter - arr[position - 1].distFromHex - arr[position - 1].height <= 0) {
block.settled = 1;
}
}
}
else {
if (block.distFromHex - (this.sideLength/2) * Math.sqrt(3) <= 0) {
this.addBlock(block);
if (arr.length > 0) {
if (block.distFromHex + iter - arr[arr.length - 1].distFromHex - arr[arr.length - 1].height <= 0) {
this.addBlock(block);
}
}
else {
if (block.distFromHex + iter - (this.sideLength/2) * Math.sqrt(3) <= 0) {
this.addBlock(block);
}
}
}
};
this.rotate = function(steps) {

View file

@ -3,22 +3,26 @@
<head>
<title>Wasted Time</title>
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Roboto">
<style>
body {
color: white;
font-family: 'Roboto', sans-serif;
font-size: 24px;
}
</style>
<style>
* {
padding: 0;
margin: 0;
}
body {
color: white;
font-family: 'Roboto', sans-serif;
font-size: 24px;
}
</style>
</head>
<body style="background-color:#2c3e50">
<center>
<div style='z-index:2;position:absolute;left:50%;margin-left:-70px;top:0px;'><h1 style='color:#ecf0f1;font-size:50px;'>Hextris</h1></div>
<canvas id="canvas" width = '700' height = '700' style='background-color:#2c3e50; position:absolute; margin-top:70px;left:50%;margin-left:-350px;'></canvas>
<div style="height:725px; width: 700px;"></div>
<div style="z-index:2; position:absolute;" id="score">0 (x1)</div>
</center>
<div style='margin: 0 auto; width: 100%;text-align: center; margin-top: 50px;'><h1 style='color:#ecf0f1; font-size:50px;'>Hextris</h1>
<span id="score">0 (x1)</span>
</div>
<canvas id="canvas" width = '700' height = '700' style='background-color:#2c3e50; position:absolute;left:50%;margin-left:-350px;'></canvas>
<script src="math.js"></script>
<script src="entities.js"></script>
<script src="math.js"></script>

View file

@ -8,3 +8,11 @@ keypress.register_combo({
on_keyup: function(){MainClock.rotate(-1)},
});
keypress.register_combo({
keys: "enter",
on_keyup: function(){
if (gameState != 1) {
init();
}
},
});

57
main.js
View file

@ -1,7 +1,7 @@
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var gameState = 1; // 0 - start, 1 - playing, 2 - end
var gameState = 0; // 0 - start, 1 - playing, 2 - end
var framerate = 60;
var score = 0;
@ -18,15 +18,27 @@ window.requestAnimFrame = (function(){
};
})();
var clock = new Clock(6);
var blocks = [];
var MainClock = new Clock(65);
var iter = 1;
var lastGen = Date.now();
var prevScore = Date.now();
var nextGen = 1000;
var MainClock;
var iter;
var lastGen;
var prevScore;
var nextGen;
function init() {
score = 0;
scoreScalar = 1;
gameState = 1;
ct = 0;
blocks = [];
MainClock = new Clock(65);
iter = 1;
lastGen = Date.now();
prevScore = Date.now();
nextGen = 1000;
}
var colors = ["#e74c3c", "#f1c40f","#3498db"];
var hexagonBackgroundColor = '#ecf0f1';
var swegBlue = '#2c3e50'; //tumblr?
@ -55,7 +67,10 @@ function render() {
for (i in MainClock.blocks) {
for (var j = 0; j < MainClock.blocks[i].length; j++) {
var block = MainClock.blocks[i][j];
MainClock.doesBlockCollide(block, iter);
MainClock.doesBlockCollide(block, iter, j, MainClock.blocks[i]);
if (!MainClock.blocks[i][j].settled) {
MainClock.blocks[i][j].distFromHex -= iter;
}
block.draw();
}
}
@ -79,13 +94,18 @@ function render() {
}
(function animloop(){
if (gameState == 1) {
requestAnimFrame(animloop);
requestAnimFrame(animloop);
if (gameState == 0) {
showModal('Start!', 'Press enter to start!');
}
else if (gameState == 1) {
render();
checkGameOver();
}
else if (gameState == 2) {
showModal('Game Over ' + score + ' pts');
showModal('Game over!', score + ' pts!');
}
})();
@ -125,10 +145,17 @@ function checkGameOver() { // fix font, fix size of hex
}
}
function showModal(text) {
function showModal(text, secondaryText) {
var buttonSize = 150;
var fontSizeLarge = 50;
var fontSizeSmall = 25;
drawPolygon(canvas.width / 2, canvas.height / 2, 6, canvas.width / 2, 30, hexagonBackgroundColor);
ctx.fillStyle = swegBlue;
ctx.font = '40pt "Helvetica Neue"';
// drawPolygon(canvas.width / 2, canvas.height / 2, 6, buttonSize, 30, swegBlue);
ctx.font = fontSizeLarge+'px "Roboto"';
ctx.textAlign = 'center';
ctx.fillText(text, canvas.width / 2, canvas.height / 2);
}
// ctx.fillStyle = hexagonBackgroundColor;
ctx.fillText(text, canvas.width / 2, canvas.height / 2 + (fontSizeLarge / 4));
ctx.font = fontSizeSmall+'px "Roboto"';
ctx.fillText(secondaryText, canvas.width/2, canvas.height/2 + fontSizeLarge / 4 + fontSizeSmall / 4 + 30);
}