From 58b1de8857388ddea8b5c6f80b709ffded79fad9 Mon Sep 17 00:00:00 2001 From: Peter Nolan Date: Sat, 31 Mar 2018 14:38:17 -0400 Subject: [PATCH 1/4] Added 3 Click Limit to game. Also some messages on the status line. --- game.js | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/game.js b/game.js index 5e955b9..f97a3fa 100644 --- a/game.js +++ b/game.js @@ -46,6 +46,7 @@ var G = (function() { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 ]; + var energyLife = 3; var WIDTH = 17; // width of grid var HEIGHT = 17; // height of grid @@ -292,6 +293,22 @@ var G = (function() { }, + + energyLifeManip : function () { + if (energyLife > 0) { + energyLife--; + return true; + } + else return false; + + }, + + energyLifePrint : function () { + return energyLife; + + }, + + // G.init() // Initializes the game @@ -299,6 +316,8 @@ var G = (function() { PS.gridSize( WIDTH, HEIGHT ); // init grid PS.border( PS.ALL, PS.ALL, 0 ); // no borders + energyLife = 3; + for ( var x = 0; x < 17; x += 1 ) { for ( var y = 0; y < 17; y += 1 ) { if ( board1[(y*17) + x] === 1) { @@ -336,6 +355,7 @@ var G = (function() { PS.audioLoad( "xylo_db6" );//14 PS.audioLoad( "xylo_d6" );//15 PS.audioLoad( "xylo_eb6" );//16 + PS.audioLoad( "fx_squawk");//Duck Squak on failure } @@ -370,12 +390,20 @@ PS.touch = function( x, y, data, options ) { var r, g, b; // Uncomment the following code line to inspect x/y parameters: - // Add code here for mouse clicks/touches over a bead. - r = PS.random(256) - 1; // random red 0-255 - g = PS.random(256) - 1; // random green - b = PS.random(256) - 1; // random blue - - G.start( x, y, r, g, b); + if (G.energyLifeManip()) { + PS.statusColor(PS.COLOR_BLUE); + PS.statusText("Energy is : " + G.energyLifePrint()); + // Add code here for mouse clicks/touches over a bead. + r = PS.random(256) - 1; // random red 0-255 + g = PS.random(256) - 1; // random green + b= PS.random(256) - 1; // random blue + G.start( x, y, r, g, b); + } + else { + PS.statusColor(PS.COLOR_RED); + PS.statusText("OUT OF ENERGY"); + PS.audioPlay("fx_squawk"); + } }; From 74d117d71e27118358e7a38bd885193b4884efe8 Mon Sep 17 00:00:00 2001 From: Peter Nolan Date: Sat, 31 Mar 2018 16:46:57 -0400 Subject: [PATCH 2/4] Implemented Controls. Implemented Retical. Implemented Delete walls and goal. Combined Master with Peter Branch --- game.js | 403 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 282 insertions(+), 121 deletions(-) diff --git a/game.js b/game.js index f97a3fa..91fdd73 100644 --- a/game.js +++ b/game.js @@ -32,36 +32,108 @@ var G = (function() { 1,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,1, 1,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, - 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, - 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, - 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, - 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, - 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, - 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, - 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, - 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, - 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, - 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, - 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1, + 1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1, + 1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1, + 1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1, + 1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1, + 1,3,3,3,3,3,3,3,3,3,3,3,3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,3,3,3,3,3,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 + ]; + + + var lastSeed; + lastSeed = 0; + + var energyLife = 3; var WIDTH = 17; // width of grid var HEIGHT = 17; // height of grid + var colorG = 0; var musicTrack = 0; var xglobe = 0; var yglobe = 0; + var xLift = 0; + var yLift = 0; + + var firstClick = true; + var COLOR_FLOOR = PS.COLOR_WHITE; // floor color var COLOR_WALL = PS.COLOR_BLACK; // wall color var COLOR_DEF = PS.COLOR_GRAY; // def color - var COLOR_AREA = PS.COLOR_GREEN; // def color - var COLOR_GOAL = PS.COLOR_YELLOW; // def color + var COLOR_AREA = 0x45FFA8; // Area color + var COLOR_GOAL = PS.COLOR_YELLOW; // Goal color + var COLOR_RETICAL = 0xA1A7FF;//Retical color var timer = null; // timer id, null if none @@ -83,6 +155,8 @@ var G = (function() { var exports = { + + endMove : function (x, y, h, v) { @@ -105,14 +179,14 @@ var G = (function() { } else if (PS.color(xglobe, yglobe) === COLOR_DEF) { PS.audioPlay(musicOST[musicTrack]); - musicTrack++; + musicTrack--; PS.color(xglobe, yglobe, COLOR_FLOOR); PS.timerStop(timer); timer = null; } else if (PS.color(xglobe, yglobe) === COLOR_GOAL) { PS.audioPlay(musicOST[musicTrack]); - musicTrack++; + musicTrack--; PS.color(xglobe, yglobe, COLOR_FLOOR); PS.timerStop(timer); timer = null; @@ -120,7 +194,7 @@ var G = (function() { else { PS.debug( "In ELSE \n") PS.audioPlay(musicOST[musicTrack]); - musicTrack++; + musicTrack--; PS.color(xglobe, yglobe, COLOR_FLOOR); } @@ -128,67 +202,76 @@ var G = (function() { }, - end : function ( x, y, rand) { + end : function (x, y) { - PS.debug("END"); + PS.debug("END\n"); xglobe = x; yglobe = y; + PS.debug("xglobe " + xglobe + "\n"); + PS.debug("yglobe " + yglobe + "\n"); + PS.debug("xLift " + xLift + "\n"); + PS.debug("xLift " + yLift + "\n"); + + PS.audioPlay(musicOST[musicTrack]); musicTrack--; PS.color( xglobe, yglobe, COLOR_FLOOR); // set bead color if (!timer) { - switch (rand) { - case 0: - //North - timer = PS.timerStart(60, G.endMove, xglobe, yglobe, 0, 1); - break; - - case 1: - //East - timer = PS.timerStart(60, G.endMove, xglobe, yglobe, 1, 0); - break; - - case 2: - //NorthEast - timer = PS.timerStart(60, G.endMove, xglobe, yglobe, 1, 1); - break; - - case 3: - //NorthWest - timer = PS.timerStart(60, G.endMove, xglobe, yglobe, -1, 1); - break; - - case 4: - //SouthWest - timer = PS.timerStart(60, G.endMove, xglobe, yglobe, -1, -1); - break; - - case 5: - //South - timer = PS.timerStart(60, G.endMove, xglobe, yglobe, 0, -1); - break; - - case 6: - //West - timer = PS.timerStart(60, G.endMove, xglobe, yglobe, -1, 0); - break; - - case 7: - //SouthEast - timer = PS.timerStart(60, G.endMove, xglobe, yglobe, 1, -1); - break; + PS.debug("Timer Check\n"); + + //WEast + if (xglobe < xLift && yglobe === yLift) { + PS.debug("East\n"); + timer = PS.timerStart(60, G.endMove, xglobe, yglobe, 1, 0); + } + //NorthEast + else if (xglobe < xLift && yglobe < yLift) { + PS.debug("NorthEast\n"); + timer = PS.timerStart(60, G.endMove, xglobe, yglobe, 1, 1); + } + //North + else if (xglobe === xLift && yglobe < yLift) { + PS.debug("North\n"); + timer = PS.timerStart(60, G.endMove, xglobe, yglobe, 0, 1); + } + //NorthWest + else if (xglobe > xLift && yglobe < yLift) { + PS.debug("NorthWest\n"); + timer = PS.timerStart(60, G.endMove, xglobe, yglobe, -1, 1); + } + //West + else if (xglobe > xLift && yglobe === yLift) { + PS.debug("West\n"); + timer = PS.timerStart(60, G.endMove, xglobe, yglobe, -1, 0); + } + //SouthWest + else if (xglobe > xLift && yglobe > yLift) { + PS.debug("SouthWest\n"); + timer = PS.timerStart(60, G.endMove, xglobe, yglobe, -1, -1); } + //South + else if (xglobe === xLift && yglobe > yLift) { + PS.debug("South\n"); + timer = PS.timerStart(60, G.endMove, xglobe, yglobe, 0, -1); + } + //SouthEast + else if (xglobe < xLift && yglobe > yLift) { + PS.debug("SouthEest\n"); + timer = PS.timerStart(60, G.endMove, xglobe, yglobe, 1, -1); + } + } + }, - move : function ( x, y, h, v, r, g, b, rand) { + move : function ( x, y, h, v) { PS.debug("x, y b4 " + x + " " + y + "\n"); PS.debug("h, v" + h + " " + v + "\n"); @@ -206,90 +289,112 @@ var G = (function() { if (PS.color(xglobe, yglobe) === COLOR_WALL) { PS.timerStop(timer); timer = null; - G.end(x, y, rand); + G.end(x, y); } else if (PS.color(xglobe, yglobe) === COLOR_DEF) { PS.timerStop(timer); timer = null; - G.end(x, y, rand); + G.end(x, y); } else if (PS.color(xglobe, yglobe) === COLOR_GOAL) { PS.timerStop(timer); timer = null; - G.end(x, y, rand); + G.end(x, y); } else { PS.debug( "In ELSE \n") PS.audioPlay(musicOST[musicTrack]); musicTrack++; - PS.color(xglobe, yglobe, r, g, b); + PS.color(xglobe, yglobe, colorG); } }, - start : function (x, y, r, g, b) { + start : function (x, y) { + + xLift = x; + yLift = y; + + G.firstClickEnd(xglobe, yglobe) if (!timer) { - xglobe = x; - yglobe = y; + //West + if (xglobe < x && yglobe === y) { + timer = PS.timerStart(60, G.move, xglobe, yglobe, 1, 0); + } + //NorthEast + else if (xglobe < x && yglobe < y) { + timer = PS.timerStart(60, G.move, xglobe, yglobe, 1, 1); + } + //North + else if (xglobe === x && yglobe < y) { + timer = PS.timerStart(60, G.move, xglobe, yglobe, 0, 1); + } + //NorthWest + else if (xglobe > x && yglobe < y) { + timer = PS.timerStart(60, G.move, xglobe, yglobe, -1, 1); + } + //West + else if (xglobe > x && yglobe === y) { + timer = PS.timerStart(60, G.move, xglobe, yglobe, -1, 0); + } + //SouthWest + else if (xglobe > x && yglobe > y) { + timer = PS.timerStart(60, G.move, xglobe, yglobe, -1, -1); + } + //South + else if (xglobe === x && yglobe > y) { + timer = PS.timerStart(60, G.move, xglobe, yglobe, 0, -1); + } + //SouthEast + else if (xglobe < x && yglobe > y) { + timer = PS.timerStart(60, G.move, xglobe, yglobe, 1, -1); + } + else { + energyLife++; + } + musicTrack = 0; musicTrack++; - PS.color( xglobe, yglobe, r, g, b ); // set bead color - - var rand = PS.random(7); - - switch (rand) { - case 0: - //North - timer = PS.timerStart(60, G.move, x, y, 0, 1, r, g, b, rand); - break; + PS.audioPlay( "fx_ding" ); - case 1: - //East - timer = PS.timerStart(60, G.move, x, y, 1, 0, r, g, b, rand); - break; + } - case 2: - //NorthEast - timer = PS.timerStart(60, G.move, x, y, 1, 1, r, g, b, rand); - break; + }, - case 3: - //NorthWest - timer = PS.timerStart(60, G.move, x, y, -1, 1, r, g, b, rand); - break; - case 4: - //SouthWest - timer = PS.timerStart(60, G.move, x, y, -1, -1, r, g, b, rand); - break; + firstClickSetup : function (x, y) { - case 5: - //South - timer = PS.timerStart(60, G.move, x, y, 0, -1, r, g, b, rand); - break; + xglobe = x; + yglobe = y; - case 6: - //West - timer = PS.timerStart(60, G.move, x, y, -1, 0, r, g, b, rand); - break; + PS.color( x+1, y, COLOR_RETICAL ); + PS.color( x, y+1, COLOR_RETICAL ); + PS.color( x+1, y+1, COLOR_RETICAL ); + PS.color( x-1, y-1, COLOR_RETICAL ); + PS.color( x-1, y, COLOR_RETICAL ); + PS.color( x, y-1, COLOR_RETICAL ); + PS.color( x+1, y-1, COLOR_RETICAL ); + PS.color( x-1, y+1, COLOR_RETICAL ); - case 7: - //SouthEast - timer = PS.timerStart(60, G.move, x, y, 1, -1, r, g, b, rand); - break; - } + }, - PS.audioPlay( "fx_ding" ); + firstClickEnd : function (x, y) { - } + PS.color( x+1, y, COLOR_FLOOR ); + PS.color( x, y+1, COLOR_FLOOR ); + PS.color( x+1, y+1, COLOR_FLOOR ); + PS.color( x-1, y-1, COLOR_FLOOR ); + PS.color( x-1, y, COLOR_FLOOR ); + PS.color( x, y-1, COLOR_FLOOR ); + PS.color( x+1, y-1, COLOR_FLOOR ); + PS.color( x-1, y+1, COLOR_FLOOR ); - return rand; }, @@ -309,6 +414,11 @@ var G = (function() { }, + colorSet (colorVar) { + colorG = colorVar; + + }, + // G.init() // Initializes the game @@ -318,18 +428,54 @@ var G = (function() { energyLife = 3; + + + PS.seed(PS.date().time); + var selectedBoard; + var boardSeed; + boardSeed = PS.random(4); + + + if(boardSeed === 1 && lastSeed != 1) + { + selectedBoard = board1; + lastSeed = 1; + } + if(boardSeed === 2 && lastSeed != 2) + { + selectedBoard = board2; + lastSeed = 2; + } + if(boardSeed === 3 && lastSeed != 3) + { + selectedBoard = board3; + lastSeed = 3; + } + if(boardSeed === 4 && lastSeed != 4) + { + selectedBoard = board4; + lastSeed = 4; + } + + if(lastSeed === 0) + { + lastSeed = boardSeed; + } + + + for ( var x = 0; x < 17; x += 1 ) { for ( var y = 0; y < 17; y += 1 ) { - if ( board1[(y*17) + x] === 1) { + if ( selectedBoard[(y*17) + x] === 1) { PS.color( x, y, COLOR_WALL ); } - else if ( board1[(y*17) + x] === 2) { + else if ( selectedBoard[(y*17) + x] === 2) { PS.color( x, y, COLOR_DEF ); } - else if ( board1[(y*17) + x] === 3) { + else if ( selectedBoard[(y*17) + x] === 3) { PS.color( x, y, COLOR_AREA ); } - else if ( board1[(y*17) + x] === 4) { + else if ( selectedBoard[(y*17) + x] === 4) { PS.color( x, y, COLOR_GOAL ); } else { @@ -390,14 +536,15 @@ PS.touch = function( x, y, data, options ) { var r, g, b; // Uncomment the following code line to inspect x/y parameters: - if (G.energyLifeManip()) { - PS.statusColor(PS.COLOR_BLUE); - PS.statusText("Energy is : " + G.energyLifePrint()); - // Add code here for mouse clicks/touches over a bead. - r = PS.random(256) - 1; // random red 0-255 - g = PS.random(256) - 1; // random green - b= PS.random(256) - 1; // random blue - G.start( x, y, r, g, b); + r = PS.random(256) - 1; // random red 0-255 + g = PS.random(256) - 1; // random green + b = PS.random(256) - 1; // random blue + + if (G.energyLifePrint() > 0) { + var color = PS.color( x, y, r, g, b ); // set bead color + G.firstClickSetup(x, y); + G.colorSet(color); + } else { PS.statusColor(PS.COLOR_RED); @@ -421,7 +568,7 @@ It doesn't have to do anything // Uncomment the following BLOCK to expose PS.release() event handler: -/* + PS.release = function( x, y, data, options ) { // Uncomment the following code line to inspect x/y parameters: @@ -429,9 +576,23 @@ PS.release = function( x, y, data, options ) { // PS.debug( "PS.release() @ " + x + ", " + y + "\n" ); // Add code here for when the mouse button/touch is released over a bead. + + if (G.energyLifeManip()) { + + PS.statusColor(PS.COLOR_BLUE); + PS.statusText("Energy is : " + G.energyLifePrint()); + + // Add code here for mouse clicks/touches over a bead. + + G.start(x, y); + + + } + + }; -*/ + /* PS.enter ( x, y, button, data, options ) From bfc5023073198ff91cc1cfe4b3eeadbe5318a021 Mon Sep 17 00:00:00 2001 From: Peter Nolan Date: Sat, 31 Mar 2018 17:02:10 -0400 Subject: [PATCH 3/4] Put in some comments --- game.js | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/game.js b/game.js index 91fdd73..974c174 100644 --- a/game.js +++ b/game.js @@ -26,6 +26,8 @@ Called once after engine is initialized but before event-polling begins. var G = (function() { + //Board Configurations + var board1 = [ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,1, @@ -107,27 +109,29 @@ var G = (function() { ]; + //For Board Configuration Choosing var lastSeed; lastSeed = 0; + //Amount of Attempts Player has left. var energyLife = 3; + var WIDTH = 17; // width of grid var HEIGHT = 17; // height of grid - var colorG = 0; + var colorG = 0;//Color of Vector on creation. - var musicTrack = 0; + var musicTrack = 0;//Current note being played on vector creation. - var xglobe = 0; + var xglobe = 0;//Current Position of edge of vector var yglobe = 0; + // Position where the cursor is lifted up from var xLift = 0; var yLift = 0; - var firstClick = true; - var COLOR_FLOOR = PS.COLOR_WHITE; // floor color var COLOR_WALL = PS.COLOR_BLACK; // wall color var COLOR_DEF = PS.COLOR_GRAY; // def color @@ -155,8 +159,10 @@ var G = (function() { var exports = { - - + //Function that erases vector. Is put through a timer in "end" + //x: original x position of starting point + //y: original y position of starting point + //h, v: horiz and verticle direction that the vector is moving in each cycle. endMove : function (x, y, h, v) { @@ -202,6 +208,9 @@ var G = (function() { }, + //Function that erases vector. Is put through a timer in "end" + //x: original x position of starting point + //y: original y position of starting point end : function (x, y) { @@ -271,6 +280,10 @@ var G = (function() { }, + //Function that erases vector. Is put through a timer in "end" + //x: original x position of starting point + //y: original y position of starting point + //h, v: horiz and verticle direction that the vector is moving in each cycle. move : function ( x, y, h, v) { PS.debug("x, y b4 " + x + " " + y + "\n"); @@ -312,6 +325,9 @@ var G = (function() { + //Function that erases vector. Is put through a timer in "end" + //x: original x position of starting point + //y: original y position of starting point start : function (x, y) { xLift = x; @@ -367,6 +383,7 @@ var G = (function() { }, + //Function that creates the reticle for the player to use. firstClickSetup : function (x, y) { xglobe = x; @@ -384,6 +401,7 @@ var G = (function() { }, + //Function that gets rid of the reticle. firstClickEnd : function (x, y) { PS.color( x+1, y, COLOR_FLOOR ); @@ -398,7 +416,7 @@ var G = (function() { }, - + //Reduces energy for each touch. energyLifeManip : function () { if (energyLife > 0) { energyLife--; @@ -408,12 +426,14 @@ var G = (function() { }, + //Sends the energy function. energyLifePrint : function () { return energyLife; }, + //Sets the global color variable to establish the color of the vector colorSet (colorVar) { colorG = colorVar; From 0ddd76a248276b996fb6ca6a31ccabee0714c431 Mon Sep 17 00:00:00 2001 From: aaaonful <15grahama@gmail.com> Date: Sun, 1 Apr 2018 17:20:45 -0400 Subject: [PATCH 4/4] Finished Prototype. Implemented Layers --- game.js | 185 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 128 insertions(+), 57 deletions(-) diff --git a/game.js b/game.js index 974c174..b0e13f5 100644 --- a/game.js +++ b/game.js @@ -90,9 +90,9 @@ var G = (function() { var board4 = [ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,3,3,3,2,2,2,0,3,3,3,3,3,3,3,3,1, - 1,4,3,2,2,2,0,3,3,3,3,3,3,3,3,3,1, - 1,3,2,2,2,0,3,3,3,3,3,3,3,3,3,3,1, + 1,0,0,0,2,2,2,0,3,3,3,3,3,3,3,3,1, + 1,4,0,2,2,2,0,3,3,3,3,3,3,3,3,3,1, + 1,0,2,2,2,0,3,3,3,3,3,3,3,3,3,3,1, 1,2,2,2,0,3,3,3,3,3,3,3,3,3,3,3,1, 1,2,2,0,3,3,3,3,3,3,3,3,3,3,3,3,1, 1,2,0,3,3,3,3,3,3,3,3,3,3,3,3,3,1, @@ -137,7 +137,7 @@ var G = (function() { var COLOR_DEF = PS.COLOR_GRAY; // def color var COLOR_AREA = 0x45FFA8; // Area color var COLOR_GOAL = PS.COLOR_YELLOW; // Goal color - var COLOR_RETICAL = 0xA1A7FF;//Retical color + var COLOR_RETICLE = 0xA1A7FF;//Retical color var timer = null; // timer id, null if none @@ -182,12 +182,14 @@ var G = (function() { if (PS.color(xglobe, yglobe) === COLOR_WALL) { PS.timerStop(timer); timer = null; + PS.gridPlane(0); } else if (PS.color(xglobe, yglobe) === COLOR_DEF) { PS.audioPlay(musicOST[musicTrack]); musicTrack--; PS.color(xglobe, yglobe, COLOR_FLOOR); PS.timerStop(timer); + PS.gridPlane(0); timer = null; } else if (PS.color(xglobe, yglobe) === COLOR_GOAL) { @@ -195,13 +197,23 @@ var G = (function() { musicTrack--; PS.color(xglobe, yglobe, COLOR_FLOOR); PS.timerStop(timer); + PS.gridPlane(0); timer = null; } + else if (PS.color(xglobe, yglobe) === COLOR_AREA) { + PS.audioPlay(musicOST[musicTrack]); + musicTrack--; + PS.color(xglobe, yglobe, COLOR_AREA); + PS.timerStop(timer); + timer = null; + PS.gridPlane(0); + } else { PS.debug( "In ELSE \n") PS.audioPlay(musicOST[musicTrack]); musicTrack--; - PS.color(xglobe, yglobe, COLOR_FLOOR); + PS.alpha( xglobe, yglobe, PS.ALPHA_TRANSPARENT ); + } @@ -213,9 +225,10 @@ var G = (function() { //y: original y position of starting point end : function (x, y) { - PS.debug("END\n"); + + xglobe = x; yglobe = y; @@ -228,7 +241,7 @@ var G = (function() { PS.audioPlay(musicOST[musicTrack]); musicTrack--; - PS.color( xglobe, yglobe, COLOR_FLOOR); // set bead color + PS.alpha( xglobe, yglobe, PS.ALPHA_TRANSPARENT ); if (!timer) { @@ -294,11 +307,12 @@ var G = (function() { PS.debug("x, y after " + x + " " + y + "\n"); - PS.debug( "PS.Color " + PS.color(x, y) + "\n") + PS.debug( "PS.Color " + colorG + "\n") PS.debug( "Wall " + COLOR_WALL + "\n") PS.debug( "Def " + COLOR_DEF + "\n") PS.debug( "Floor" + COLOR_FLOOR + "\n") + if (PS.color(xglobe, yglobe) === COLOR_WALL) { PS.timerStop(timer); timer = null; @@ -316,9 +330,11 @@ var G = (function() { } else { PS.debug( "In ELSE \n") + PS.audioPlay(musicOST[musicTrack]); musicTrack++; PS.color(xglobe, yglobe, colorG); + PS.alpha( xglobe, yglobe, PS.ALPHA_OPAQUE ); } }, @@ -334,6 +350,7 @@ var G = (function() { yLift = y; G.firstClickEnd(xglobe, yglobe) + PS.gridPlane(1); if (!timer) { @@ -389,14 +406,26 @@ var G = (function() { xglobe = x; yglobe = y; - PS.color( x+1, y, COLOR_RETICAL ); - PS.color( x, y+1, COLOR_RETICAL ); - PS.color( x+1, y+1, COLOR_RETICAL ); - PS.color( x-1, y-1, COLOR_RETICAL ); - PS.color( x-1, y, COLOR_RETICAL ); - PS.color( x, y-1, COLOR_RETICAL ); - PS.color( x+1, y-1, COLOR_RETICAL ); - PS.color( x-1, y+1, COLOR_RETICAL ); + PS.gridPlane(1); + + PS.color( x+1, y, COLOR_RETICLE); + PS.alpha( x+1, y, PS.ALPHA_OPAQUE ) + PS.color( x, y+1, COLOR_RETICLE ); + PS.alpha( x, y+1, PS.ALPHA_OPAQUE ) + PS.color( x+1, y+1, COLOR_RETICLE ); + PS.alpha( x+1, y+1, PS.ALPHA_OPAQUE ) + PS.color( x-1, y-1, COLOR_RETICLE ); + PS.alpha( x-1, y-1, PS.ALPHA_OPAQUE ) + PS.color( x-1, y, COLOR_RETICLE ); + PS.alpha( x-1, y, PS.ALPHA_OPAQUE ) + PS.color( x, y-1, COLOR_RETICLE ); + PS.alpha( x, y-1, PS.ALPHA_OPAQUE ) + PS.color( x+1, y-1, COLOR_RETICLE ); + PS.alpha( x+1, y-1, PS.ALPHA_OPAQUE ) + PS.color( x-1, y+1, COLOR_RETICLE ); + PS.alpha( x-1, y+1, PS.ALPHA_OPAQUE ) + + }, @@ -404,18 +433,45 @@ var G = (function() { //Function that gets rid of the reticle. firstClickEnd : function (x, y) { - PS.color( x+1, y, COLOR_FLOOR ); - PS.color( x, y+1, COLOR_FLOOR ); - PS.color( x+1, y+1, COLOR_FLOOR ); - PS.color( x-1, y-1, COLOR_FLOOR ); - PS.color( x-1, y, COLOR_FLOOR ); - PS.color( x, y-1, COLOR_FLOOR ); - PS.color( x+1, y-1, COLOR_FLOOR ); - PS.color( x-1, y+1, COLOR_FLOOR ); + + PS.alpha( x+1, y, PS.ALPHA_TRANSPARENT ); + PS.alpha( x, y+1, PS.ALPHA_TRANSPARENT ); + PS.alpha( x+1, y+1, PS.ALPHA_TRANSPARENT ); + PS.alpha( x-1, y-1, PS.ALPHA_TRANSPARENT ); + PS.alpha( x-1, y, PS.ALPHA_TRANSPARENT ); + PS.alpha( x, y-1, PS.ALPHA_TRANSPARENT ); + PS.alpha( x+1, y-1, PS.ALPHA_TRANSPARENT ); + PS.alpha( x-1, y+1, PS.ALPHA_TRANSPARENT ); + + PS.gridPlane(0); }, + + getPreset : function( desiredColor ) { + + if (desiredColor === "COLOR_FLOOR") { + return COLOR_FLOOR; + } + else if (desiredColor === "COLOR_AREA") { + return COLOR_AREA; + } + else if (desiredColor === "COLOR_GOAL") { + return COLOR_GOAL; + } + else if (desiredColor === "COLOR_DEF") { + return COLOR_DEF; + } + else if (desiredColor === "COLOR_RETICLE") { + return COLOR_RETICLE; + } + else if (desiredColor === "COLOR_WALL") { + return COLOR_WALL; + } + + }, + //Reduces energy for each touch. energyLifeManip : function () { if (energyLife > 0) { @@ -434,8 +490,9 @@ var G = (function() { //Sets the global color variable to establish the color of the vector - colorSet (colorVar) { + colorSet : function (colorVar) { colorG = colorVar; + PS.debug("color g " + colorG + "\n"); }, @@ -490,7 +547,10 @@ var G = (function() { PS.color( x, y, COLOR_WALL ); } else if ( selectedBoard[(y*17) + x] === 2) { + PS.gridPlane(1); PS.color( x, y, COLOR_DEF ); + PS.alpha( x, y, PS.ALPHA_OPAQUE ) + PS.gridPlane(0); } else if ( selectedBoard[(y*17) + x] === 3) { PS.color( x, y, COLOR_AREA ); @@ -505,23 +565,23 @@ var G = (function() { } - PS.audioLoad( "xylo_c5" );//1 - PS.audioLoad( "xylo_db5" );//2 - PS.audioLoad( "xylo_d5" );//3 - PS.audioLoad( "xylo_eb5" );//4 - PS.audioLoad( "xylo_e5" );//5 - PS.audioLoad( "xylo_f5" );//6 - PS.audioLoad( "xylo_gb5" );//7 - PS.audioLoad( "xylo_g5" );//8 - PS.audioLoad( "xylo_ab5" );//9 - PS.audioLoad( "xylo_a5" );//10 - PS.audioLoad( "xylo_bb5" );//11 - PS.audioLoad( "xylo_b5" );//12 - PS.audioLoad( "xylo_c6" );//13 - PS.audioLoad( "xylo_db6" );//14 - PS.audioLoad( "xylo_d6" );//15 - PS.audioLoad( "xylo_eb6" );//16 - PS.audioLoad( "fx_squawk");//Duck Squak on failure + PS.audioLoad( "xylo_c5" ); //1 + PS.audioLoad( "xylo_db5" ); //2 + PS.audioLoad( "xylo_d5" ); //3 + PS.audioLoad( "xylo_eb5" ); //4 + PS.audioLoad( "xylo_e5" ); //5 + PS.audioLoad( "xylo_f5" ); //6 + PS.audioLoad( "xylo_gb5" ); //7 + PS.audioLoad( "xylo_g5" ); //8 + PS.audioLoad( "xylo_ab5" ); //9 + PS.audioLoad( "xylo_a5" ); //10 + PS.audioLoad( "xylo_bb5" ); //11 + PS.audioLoad( "xylo_b5" ); //12 + PS.audioLoad( "xylo_c6" ); //13 + PS.audioLoad( "xylo_db6" ); //14 + PS.audioLoad( "xylo_d6" ); //15 + PS.audioLoad( "xylo_eb6" ); //16 + PS.audioLoad( "fx_squawk"); //Duck Squak on failure } @@ -560,16 +620,25 @@ PS.touch = function( x, y, data, options ) { g = PS.random(256) - 1; // random green b = PS.random(256) - 1; // random blue - if (G.energyLifePrint() > 0) { - var color = PS.color( x, y, r, g, b ); // set bead color - G.firstClickSetup(x, y); - G.colorSet(color); - } - else { - PS.statusColor(PS.COLOR_RED); - PS.statusText("OUT OF ENERGY"); - PS.audioPlay("fx_squawk"); + if(PS.color(x, y) === G.getPreset("COLOR_AREA")) { + PS.debug("x and y within touch: " + x + " " + y + "\n"); + if (G.energyLifePrint() > 0) { + PS.debug("Good Energy"); + PS.gridPlane(1); + var color = PS.color(x, y, r, g, b); // set bead color + PS.alpha( x, y, PS.ALPHA_OPAQUE ); + PS.gridPlane(0); + PS.debug(color + " color" + "\n"); + G.colorSet(color); + G.firstClickSetup(x, y); + } + else { + PS.statusColor(PS.COLOR_RED); + PS.statusText("OUT OF ENERGY"); + PS.audioPlay("fx_squawk"); + } + } }; @@ -597,19 +666,21 @@ PS.release = function( x, y, data, options ) { // Add code here for when the mouse button/touch is released over a bead. - if (G.energyLifeManip()) { + if(PS.color(x, y) === G.getPreset("COLOR_RETICLE")) { + if (G.energyLifeManip()) { + PS.debug("LIFTOFF"); + PS.statusColor(PS.COLOR_BLUE); + PS.statusText("Energy is : " + G.energyLifePrint()); - PS.statusColor(PS.COLOR_BLUE); - PS.statusText("Energy is : " + G.energyLifePrint()); + // Add code here for mouse clicks/touches over a bead. - // Add code here for mouse clicks/touches over a bead. + G.start(x, y); - G.start(x, y); + } } - };