MOVE!!!!! + InfoBarGlow
This commit is contained in:
parent
748c2df27c
commit
af522c6b43
25
js/game.js
25
js/game.js
|
|
@ -189,8 +189,33 @@ function prepairRender() {
|
||||||
|
|
||||||
var infoBarIcons = ["build.png", "move.png", "rotate.png", "delete.png", null, "upgrade.png", "info.png", null, "rocket.png"]
|
var infoBarIcons = ["build.png", "move.png", "rotate.png", "delete.png", null, "upgrade.png", "info.png", null, "rocket.png"]
|
||||||
|
|
||||||
|
var infoGlowOpacity = 0
|
||||||
|
var infoGlowOpacityD = 0.03
|
||||||
|
|
||||||
function drawInfoBar() {
|
function drawInfoBar() {
|
||||||
infoCtx.clearRect(0, 0, innerWidth, innerHeight)
|
infoCtx.clearRect(0, 0, innerWidth, innerHeight)
|
||||||
|
var selectedX = -1;
|
||||||
|
if (mode == "build" || mode == "selectbuilding") {
|
||||||
|
selectedX = 0
|
||||||
|
} else if(mode=="move"){
|
||||||
|
selectedX = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedX != -1) {
|
||||||
|
infoCtx.globalAlpha = infoGlowOpacity + 0.2
|
||||||
|
infoCtx.beginPath();
|
||||||
|
infoCtx.arc(selectedX * 48 + 24, 24, 24, 0, 2 * Math.PI);
|
||||||
|
infoCtx.fillStyle = "orange"
|
||||||
|
infoCtx.fill()
|
||||||
|
if (infoGlowOpacity < 0) {
|
||||||
|
infoGlowOpacityD = +0.02
|
||||||
|
}
|
||||||
|
if (infoGlowOpacity > 0.4) {
|
||||||
|
infoGlowOpacityD = -0.02
|
||||||
|
}
|
||||||
|
infoGlowOpacity += infoGlowOpacityD
|
||||||
|
infoCtx.globalAlpha = 1
|
||||||
|
}
|
||||||
for (var i = 0; i < infoBarIcons.length; i++) {
|
for (var i = 0; i < infoBarIcons.length; i++) {
|
||||||
if (infoBarIcons[i] != null) {
|
if (infoBarIcons[i] != null) {
|
||||||
var img = new Image;
|
var img = new Image;
|
||||||
|
|
|
||||||
|
|
@ -118,12 +118,24 @@ function clickEvents() {
|
||||||
mode = "none"
|
mode = "none"
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
case 1:
|
||||||
|
//MOVE BUTTON
|
||||||
|
if (mode == "none") {
|
||||||
|
mode = "move"
|
||||||
|
} else {
|
||||||
|
mode = "none"
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var toBuild = {}
|
var toBuild = {}
|
||||||
|
var moveFromX = 0
|
||||||
|
var moveFromY = 0
|
||||||
|
var moveFromCX = -1
|
||||||
|
var moveFromCY = -1
|
||||||
|
|
||||||
function buildEvents() {
|
function buildEvents() {
|
||||||
$('img').click(function() {
|
$('img').click(function() {
|
||||||
|
|
@ -137,9 +149,72 @@ function buildEvents(){
|
||||||
})
|
})
|
||||||
$('#screen').click(function() {
|
$('#screen').click(function() {
|
||||||
if (mode == "build") {
|
if (mode == "build") {
|
||||||
if(factorys[currentFactory].tiles[cursorScreenX][cursorScreenY]!=null){
|
if (factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] == 0) {
|
||||||
factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] = new toBuild(cursorScreenX, cursorScreenY)
|
factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] = new toBuild(cursorScreenX, cursorScreenY)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (mode == "move") {
|
||||||
|
if (isCursorInScreen) {
|
||||||
|
if (factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] != 0) {
|
||||||
|
moveFromCX = cursorScreenX
|
||||||
|
moveFromCY = cursorScreenY
|
||||||
|
} else if (moveFromCX != -1) {
|
||||||
|
if (factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] == 0) {
|
||||||
|
factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] = factorys[currentFactory].tiles[moveFromCX][moveFromCY]
|
||||||
|
factorys[currentFactory].tiles[cursorScreenX][cursorScreenY].x = cursorScreenX
|
||||||
|
factorys[currentFactory].tiles[cursorScreenX][cursorScreenY].y = cursorScreenY
|
||||||
|
factorys[currentFactory].tiles[moveFromCX][moveFromCY] = 0
|
||||||
|
} else {
|
||||||
|
moveFromCX = cursorScreenX
|
||||||
|
moveFromCY = cursorScreenY
|
||||||
|
}
|
||||||
|
moveFromCX = -1
|
||||||
|
moveFromCY = -1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
$('body').mousedown(function() {
|
||||||
|
if (mode == "move") {
|
||||||
|
if (isCursorInScreen) {
|
||||||
|
moveFromX = cursorScreenX
|
||||||
|
moveFromY = cursorScreenY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
$('body').mouseup(function() {
|
||||||
|
if (mode == "move") {
|
||||||
|
if (isCursorInScreen && moveFromX != -1) {
|
||||||
|
if (moveFromX != cursorScreenX || moveFromY != cursorScreenY) {
|
||||||
|
if (factorys[currentFactory].tiles[moveFromX][moveFromY] != 0 && factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] == 0) {
|
||||||
|
factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] = factorys[currentFactory].tiles[moveFromX][moveFromY]
|
||||||
|
factorys[currentFactory].tiles[cursorScreenX][cursorScreenY].x = cursorScreenX
|
||||||
|
factorys[currentFactory].tiles[cursorScreenX][cursorScreenY].y = cursorScreenY
|
||||||
|
factorys[currentFactory].tiles[moveFromX][moveFromY] = 0
|
||||||
|
}
|
||||||
|
moveFromX = -1
|
||||||
|
moveFromY = -1
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
$('body').on("contextmenu", function() {
|
||||||
|
if (mode == "build") {
|
||||||
|
mode = "none"
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (mode == "selectbuilding") {
|
||||||
|
mode = "none"
|
||||||
|
$('#buildselect').fadeOut(200)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (mode == "move") {
|
||||||
|
mode = "none"
|
||||||
|
return false
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue