Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/AlexOwen/Hyperspace
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan0net committed Feb 7, 2016
2 parents 4cfa16f + 5486960 commit ae7dac3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
Binary file added public/img/ship.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 12 additions & 7 deletions public/js/shipLivePanel.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
var initShipDisplay = function(socket) {

$('#stars, #stars2, #stars3').remove();

var width = 20, height = 7;

var speeds = {
Expand Down Expand Up @@ -55,20 +53,27 @@ var initShipDisplay = function(socket) {
$(object.elem).remove();
} else {
if (newY > oldY || newY < oldY) { //move down/up
$(object.elem).animate({top: 'calc(' + (newPosition.y+0.5) * vGridUnit + '% - 15px)'}, animateSpeed, 'linear');
if (object.type === 'ship') {
$(object.elem).animate({top: (newPosition.y+0.3) * vGridUnit + '%'}, animateSpeed, 'linear');
} else {
$(object.elem).animate({top: 'calc(' + (newPosition.y+0.5) * vGridUnit + '% - 15px)'}, animateSpeed, 'linear');
}
} else if (newX > oldX || newX < oldX) { //move right/left
$(object.elem).animate({left: newPosition.x * hGridUnit + '%'}, animateSpeed, 'linear');
}
}
};

var place = function(object, newPosition) {
console.log(newPosition);
$(object.elem).css('top', 'calc(' + (newPosition.y+0.5) * vGridUnit + '% - 15px)');
if (object.type === 'ship') {
$(object.elem).css('top', (newPosition.y+0.3) * vGridUnit + '%');
} else {
$(object.elem).css('top', 'calc(' + (newPosition.y+0.5) * vGridUnit + '% - 15px)');
}
$(object.elem).css('left', newPosition.x * hGridUnit + '%');
};

$('#grid').append('<div id="ship" style="position:absolute;width:margin:auto;width:' + hGridUnit + '%;height:' + vGridUnit + '%;font-size: 30px;color:#17AE17;">=></div>');
$('#grid').append('<div id="ship" style="position:absolute;width:margin:auto;width:' + hGridUnit + '%;height:' + vGridUnit + '%;"><img src="/img/ship.png" style="height:60%;""/></div>');
ship.elem = $('#ship');
place(ship, {x: 0, y: 3});

Expand Down Expand Up @@ -96,7 +101,7 @@ var initShipDisplay = function(socket) {
var enemyDamaged = function(enemy) {
if (enemy !== undefined && enemy.health !== undefined) {
if (enemy.health <= 0) {
$('#enemy_' + enemy.id).addClass('hit').html('X');
$('#enemy_' + enemy.id).html('X');
setTimeout(function() {
$('#enemy_' + enemy.id).remove();
}, 500);
Expand Down
1 change: 1 addition & 0 deletions sockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ exports.init = (server) => {
});

state.out.on('ship:status', (ship) => {
console.log(ship.position);
socket.emit('ship:status', ship);
});

Expand Down
2 changes: 1 addition & 1 deletion state.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ exports.init = () => {
},
health: {
hull: 50,
main_shields: 50,
main_shields: 10,
shields: 10,
engineering: 10,
weapons: 10,
Expand Down

0 comments on commit ae7dac3

Please sign in to comment.