@ -93,6 +93,7 @@ const TITLE = 7;
const STARTUP = 8 ;
var ISTESTING = false ;
var MOUSEOVERTIME = - 1
const UP = 0 ;
const RIGHT = 1 ;
@ -198,24 +199,24 @@ var KEY_ROTATION_UP = ["W","K","w","k","8","ArrowUp"]
var KEY _ROTATION _DOWN = [ "S" , "J" , "s" , "j" , "2" , "ArrowDown" ]
var KEY _BRIDGED _BELT = [ "Shift" ]
var CONVEYOR _BUILD _BUTTON = { img : ID _CONVEYOR , x : - 1 , y : - 1 , w : - 1 , h : - 1 , lastselected : DEF _CONVEYOR }
var BRANCH _BUILD _BUTTON = { img : ID _BRANCH , x : - 1 , y : - 1 , w : - 1 , h : - 1 , submenu _buttons : [ DEF _BRANCHUP _RB , DEF _BRANCHUP _BR , DEF _BRANCHUP _GY , DEF _BRANCHUP _YG , DEF _BRANCHUP _PPI , DEF _BRANCHUP _PIP , DEF _BRANCHUP _BLGR , DEF _BRANCHUP _GRBL ] , lastselected : undefined , default : DEF _BRANCHUP _RB }
var WRITER _BUILD _BUTTON = { img : ID _WRITER , x : - 1 , y : - 1 , w : - 1 , h : - 1 , submenu _buttons : [ DEF _WRITERRIGHT _R , DEF _WRITERRIGHT _B , DEF _WRITERRIGHT _G , DEF _WRITERRIGHT _Y , DEF _WRITERRIGHT _P , DEF _WRITERRIGHT _PI , DEF _WRITERRIGHT _BL , DEF _WRITERRIGHT _GR ] , lastselected : undefined , default : DEF _WRITERRIGHT _R }
var ROTATE _CLOCKWISE _BUTTON = { img : ID _ROTATE _CLOCKWISE , x : - 1 , y : - 1 , w : - 1 , h : - 1 , cb : rotateClockwise
var CONVEYOR _BUILD _BUTTON = { img : ID _CONVEYOR , x : - 1 , y : - 1 , w : - 1 , h : - 1 , lastselected : DEF _CONVEYOR , tooltip : "Conveyor Belt\nMoves bots in a direction.\n\nHold (Shift) to bridge over other belts" , mobileTooltip : "Conveyor Belt\nMoves bots in a direction.\n\nHold button down to toggle bridge mode. Used to bridge over other belts" }
var BRANCH _BUILD _BUTTON = { img : ID _BRANCH , x : - 1 , y : - 1 , w : - 1 , h : - 1 , submenu _buttons : [ DEF _BRANCHUP _RB , DEF _BRANCHUP _BR , DEF _BRANCHUP _GY , DEF _BRANCHUP _YG , DEF _BRANCHUP _PPI , DEF _BRANCHUP _PIP , DEF _BRANCHUP _BLGR , DEF _BRANCHUP _GRBL ] , lastselected : undefined , default : DEF _BRANCHUP _RB , tooltip : "Branch\nReads next tape and moves bot in the\nmatching color direction.\n\nMoves bot forward and does not consume\ntape if no match found." }
var WRITER _BUILD _BUTTON = { img : ID _WRITER , x : - 1 , y : - 1 , w : - 1 , h : - 1 , submenu _buttons : [ DEF _WRITERRIGHT _R , DEF _WRITERRIGHT _B , DEF _WRITERRIGHT _G , DEF _WRITERRIGHT _Y , DEF _WRITERRIGHT _P , DEF _WRITERRIGHT _PI , DEF _WRITERRIGHT _BL , DEF _WRITERRIGHT _GR ] , lastselected : undefined , default : DEF _WRITERRIGHT _R , tooltip : "Writer\nWrites a color to the end of the tape." }
var ROTATE _CLOCKWISE _BUTTON = { img : ID _ROTATE _CLOCKWISE , x : - 1 , y : - 1 , w : - 1 , h : - 1 , cb : rotateClockwise , tooltip : "Rotate selection clockwise."
}
var ROTATE _COUNTERCLOCKWISE _BUTTON = { img : ID _ROTATE _COUNTERCLOCKWISE , x : - 1 , y : - 1 , w : - 1 , h : - 1 , cb : rotateCounterClockwise
var ROTATE _COUNTERCLOCKWISE _BUTTON = { img : ID _ROTATE _COUNTERCLOCKWISE , x : - 1 , y : - 1 , w : - 1 , h : - 1 , cb : rotateCounterClockwise , tooltip : "Rotate selection counter-clockwise."
}
var PLAY _BUTTON = { img : ID _PLAY , x : - 1 , y : - 1 , w : - 1 , h : - 1 , cb : runGameSimulation
var PLAY _BUTTON = { img : ID _PLAY , x : - 1 , y : - 1 , w : - 1 , h : - 1 , cb : runGameSimulation , tooltip : "Test your great machine.\n\nConvert all the bots!"
}
var PAUSE _BUTTON = { img : ID _PAUSE , x : - 1 , y : - 1 , w : - 1 , h : - 1 , cb : pauseGameSimulation
var PAUSE _BUTTON = { img : ID _PAUSE , x : - 1 , y : - 1 , w : - 1 , h : - 1 , cb : pauseGameSimulation , tooltip : "Pause the great machine."
}
var RESET _BUTTON = { img : ID _RESET , x : - 1 , y : - 1 , w : - 1 , h : - 1 , cb : resetSimulation
var RESET _BUTTON = { img : ID _RESET , x : - 1 , y : - 1 , w : - 1 , h : - 1 , cb : resetSimulation , tooltip : "Reset the great machine."
}
var DELETE _BUTTON = { img : ID _DELETE , x : - 1 , y : - 1 , w : - 1 , h : - 1 , cb : toggleDeleteMode
var DELETE _BUTTON = { img : ID _DELETE , x : - 1 , y : - 1 , w : - 1 , h : - 1 , cb : toggleDeleteMode , tooltip : "Remove a piece on the field."
}
var HOME _BUTTON = { img : ID _HOME , x : - 1 , y : - 1 , w : - 1 , h : - 1 , cb : goHome
var HOME _BUTTON = { img : ID _HOME , x : - 1 , y : - 1 , w : - 1 , h : - 1 , cb : goHome , tooltip : "Go back to the level selection menu."
}
var MENU = {
@ -830,6 +831,8 @@ function clickEvent(e) {
LAST _MOUSE _X = mousepos . x
LAST _MOUSE _Y = mousepos . y
MOUSEDOWN = true
if ( gameState === STARTUP ) {
currentSound . play ( )
setupTitleScreen ( )
@ -846,7 +849,7 @@ function clickEvent(e) {
if ( mouseOverButton ( canvas , e , button ) ) {
if ( MOBILE && button === CONVEYOR _BUILD _BUTTON ) {
setTimeout ( ( ) => {
if ( ! MOUSEDOWN &&
if ( MOUSEDOWN &&
LAST _MOUSE _X >= CONVEYOR _BUILD _BUTTON . x &&
LAST _MOUSE _X <= CONVEYOR _BUILD _BUTTON . x + CONVEYOR _BUILD _BUTTON . w &&
LAST _MOUSE _Y >= CONVEYOR _BUILD _BUTTON . y &&
@ -893,8 +896,6 @@ function clickEvent(e) {
//console.log(gameGrid)
}
}
MOUSEDOWN = true
}
function coordsInBounds ( coords ) {
@ -924,7 +925,6 @@ function placeObject(coords,def) {
if ( notAForbiddenObject ( coords ) ) {
if ( gameGrid [ coords . y ] [ coords . x ] . direction !== undefined && gameGrid [ coords . y ] [ coords . x ] . type && gameGrid [ coords . y ] [ coords . x ] . type === "BELT" && BRIDGEDBELT ) {
gameGrid [ coords . y ] [ coords . x ] = { ... gameGrid [ coords . y ] [ coords . x ] , direction2 : ITEM _DIRECTION }
console . log ( gameGrid )
} else {
var newObj = { ... def , direction : ITEM _DIRECTION }
gameGrid [ coords . y ] [ coords . x ] = newObj
@ -959,7 +959,7 @@ function releaseEvent(e) {
SUBMENU . visible = false
}
DRAGGING = false
MOUSEDOWN = false
MOUSEDOWN = false
}
function loadLevel ( level , botx , boty ) {
@ -1858,26 +1858,80 @@ function ButtonIsUnlocked(button) {
return gameStage . locked === undefined || ( ! gameStage . locked . includes ( button ) )
}
function isMouseOverButton ( button ) {
return LAST _MOUSE _X >= button . x &&
LAST _MOUSE _X <= button . x + button . w &&
LAST _MOUSE _Y >= button . y &&
LAST _MOUSE _Y <= button . y + button . h
}
function DisplayTooltip ( button , ctx ) {
//240x(20*lines) (16pt font)
var tooltipSplit = button . tooltip . split ( "\n" )
var tooltipBounds = {
x : Math . min ( Math . max ( LAST _MOUSE _X - 120 , 0 ) , canvas . width * 0.75 - 240 ) ,
y : LAST _MOUSE _Y - tooltipSplit . length * 20 - 4 ,
w : 240 ,
h : tooltipSplit . length * 16 + 8
}
ctx . globalAlpha = 0.9
ctx . fillStyle = "#20424a"
ctx . fillRect ( tooltipBounds . x , tooltipBounds . y , tooltipBounds . w , tooltipBounds . h )
ctx . strokeStyle = "white"
ctx . lineWidth = 1
ctx . setLineDash ( [ ] )
ctx . strokeRect ( tooltipBounds . x , tooltipBounds . y , tooltipBounds . w , tooltipBounds . h )
ctx . fillStyle = "white"
ctx . textAlign = "left"
for ( var i = 0 ; i < tooltipSplit . length ; i ++ ) {
if ( i === 0 ) {
ctx . font = "bold 12px 'Zilla Slab', serif"
} else {
ctx . font = "12px 'Zilla Slab', serif"
}
ctx . fillText ( tooltipSplit [ i ] , tooltipBounds . x + 8 , tooltipBounds . y + i * 16 + 16 )
}
ctx . globalAlpha = 1
}
function RenderMenu ( ctx ) {
if ( MENU . visible ) {
ctx . fillStyle = "#20424a"
ctx . fillRect ( 0 , canvas . height * 0.8 , canvas . width , canvas . height * 0.2 )
var buttonX = 16
var buttonY = canvas . height * 0.8 + 16
var mouseOverButton = undefined
var mousedOver = false
for ( var button of MENU . buttons ) {
button . x = buttonX
button . y = buttonY
button . w = 32
button . h = 32
if ( ButtonIsUnlocked ( button ) ) {
if ( mouseOverButton === undefined && isMouseOverButton ( button ) ) {
mousedOver = true
if ( MOUSEOVERTIME === - 1 ) {
MOUSEOVERTIME = new Date ( ) . getTime ( )
} else
if ( new Date ( ) . getTime ( ) - MOUSEOVERTIME >= 500 ) {
mouseOverButton = button
}
}
if ( button . lastselected ) {
RenderIcon ( buttonX , buttonY , ctx , button . lastselected , ( button . cb === undefined ) ? ITEM _DIRECTION : 0 , "#b5b5b5" )
} else {
AddButton ( button . img , buttonX , buttonY , ctx , button , ( button . cb === undefined ) ? ITEM _DIRECTION : 0 )
}
}
button . x = buttonX
button . y = buttonY
button . w = 32
button . h = 32
buttonX += 47
}
if ( mouseOverButton !== undefined ) {
DisplayTooltip ( mouseOverButton , ctx )
}
if ( ! mousedOver ) {
MOUSEOVERTIME = - 1
}
}
}