scale rendering
This commit is contained in:
parent
80bd84230d
commit
0ceea5f4af
7 changed files with 70 additions and 17 deletions
3
public/js/starbugs/world/Untitled Document
Normal file
3
public/js/starbugs/world/Untitled Document
Normal file
|
@ -0,0 +1,3 @@
|
|||
function Body() {
|
||||
|
||||
}
|
|
@ -7,6 +7,19 @@ function Ship(id) {
|
|||
this.move = [];
|
||||
this.lastMove = [];
|
||||
this.bodyType = 'ship';
|
||||
this.com = {
|
||||
x: 16,
|
||||
y: 17.6
|
||||
};
|
||||
|
||||
var s = SCALE;
|
||||
|
||||
this.getPos = function() {
|
||||
return {
|
||||
x: this.x * s,
|
||||
y: this.y * s
|
||||
}
|
||||
}
|
||||
|
||||
this.updateMove = function() {
|
||||
if (JSON.stringify(this.move) != JSON.stringify(this.lastMove) || true) {
|
||||
|
|
|
@ -1,8 +1,27 @@
|
|||
var SCALE = 32;
|
||||
|
||||
function World() {
|
||||
this.bodies = {};
|
||||
this.playerShip = false;
|
||||
this.playerShipId = false;
|
||||
|
||||
this.getCenter = function() {
|
||||
if (!this.playerShip) return { x: 0, y: 0 };
|
||||
|
||||
var x = this.playerShip.getPos().x;
|
||||
var y = this.playerShip.getPos().y;
|
||||
var comx = this.playerShip.com.x;
|
||||
var comy = this.playerShip.com.y;
|
||||
var r = this.playerShip.r;
|
||||
var d = Math.sqrt(comx * comx + comy * comy);
|
||||
var a = Math.atan2(comy, comx);
|
||||
|
||||
x += Math.cos(a + r) * d;
|
||||
y += Math.sin(a + r) * d;
|
||||
|
||||
return { x: x, y: y };
|
||||
}
|
||||
|
||||
this.clear = function() {
|
||||
this.bodies = {};
|
||||
this.playerShip = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue