Bounderies for floating space implemented
This commit is contained in:
1 parent
032db15106
commit
38f160b0ee
4 files changed
+34
-10
No files matched your search
@@ -378,6 +378,7 @@ function newFloatingLayer () {
|
||||
}
|
||||
|
||||
// We let the Floating Object animate the physics loops by itself.
|
||||
checkBoundaries(floatingObject)
|
||||
|
||||
floatingObject.physics()
|
||||
|
||||
@@ -406,6 +407,28 @@ function newFloatingLayer () {
|
||||
}
|
||||
}
|
||||
|
||||
function checkBoundaries (floatingObject) {
|
||||
if (floatingObject.container.frame.position.x - floatingObject.container.frame.radius < 0) {
|
||||
floatingObject.container.frame.position.x = floatingObject.container.frame.radius
|
||||
floatingObject.currentSpeed.x = -floatingObject.currentSpeed.x
|
||||
}
|
||||
|
||||
if (floatingObject.container.frame.position.x + floatingObject.container.frame.radius > canvas.floatingSpace.container.frame.width) {
|
||||
floatingObject.container.frame.position.x = canvas.floatingSpace.container.frame.width - floatingObject.container.frame.radius
|
||||
floatingObject.currentSpeed.x = -floatingObject.currentSpeed.x
|
||||
}
|
||||
|
||||
if (floatingObject.container.frame.position.y - floatingObject.container.frame.radius < 0) {
|
||||
floatingObject.container.frame.position.y = floatingObject.container.frame.radius
|
||||
floatingObject.currentSpeed.y = -floatingObject.currentSpeed.y
|
||||
}
|
||||
|
||||
if (floatingObject.container.frame.position.y + floatingObject.container.frame.radius > canvas.floatingSpace.container.frame.height) {
|
||||
floatingObject.container.frame.position.y = canvas.floatingSpace.container.frame.height - floatingObject.container.frame.radius
|
||||
floatingObject.currentSpeed.y = -floatingObject.currentSpeed.y
|
||||
}
|
||||
}
|
||||
|
||||
function gravityForce (floatingObject, payload) {
|
||||
try {
|
||||
/* We simulate a kind of gravity towards the target point of each floatingObject. This force will make the floatingObject to keep pushing to reach that point. */
|
||||
@@ -728,3 +751,4 @@ function newFloatingLayer () {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ function newStrategyPartConstructor () {
|
||||
}
|
||||
|
||||
function level_0 () {
|
||||
floatingObject.friction = FRICTION// 0.93
|
||||
floatingObject.friction = 0.93
|
||||
|
||||
floatingObject.initializeMass(500)
|
||||
floatingObject.initializeRadius(45)
|
||||
@@ -105,7 +105,7 @@ function newStrategyPartConstructor () {
|
||||
}
|
||||
|
||||
function level_1 () {
|
||||
floatingObject.friction = FRICTION // 0.94
|
||||
floatingObject.friction = 0.94
|
||||
|
||||
floatingObject.initializeMass(250)
|
||||
floatingObject.initializeRadius(45)
|
||||
|
||||
@@ -29,10 +29,10 @@ function newFloatingSpace () {
|
||||
thisObject.container.isWheelable = true
|
||||
thisObject.container.detectMouseOver = true
|
||||
thisObject.container.frame.radius = 0
|
||||
thisObject.container.frame.width = browserCanvas.width * 1
|
||||
thisObject.container.frame.height = browserCanvas.height * 1
|
||||
thisObject.container.frame.position.x = 0 // browserCanvas.width / 2// - thisObject.container.frame.width / 2
|
||||
thisObject.container.frame.position.y = 0 // browserCanvas.height / 2// - thisObject.container.frame.height / 2
|
||||
thisObject.container.frame.width = browserCanvas.width * 3
|
||||
thisObject.container.frame.height = browserCanvas.height * 3
|
||||
thisObject.container.frame.position.x = browserCanvas.width / 2 - thisObject.container.frame.width / 2
|
||||
thisObject.container.frame.position.y = browserCanvas.height / 2 - thisObject.container.frame.height / 2
|
||||
|
||||
let visible = false
|
||||
|
||||
|
||||
@@ -43,13 +43,13 @@ function newInvestmentPlan () {
|
||||
let payload = {}
|
||||
if (chainParent === undefined) {
|
||||
payload.targetPosition = {
|
||||
x: canvas.floatingSpace.container.frame.position.x + canvas.floatingSpace.container.frame.width / 2,
|
||||
y: canvas.floatingSpace.container.frame.position.y + canvas.floatingSpace.container.frame.height / 2
|
||||
x: canvas.floatingSpace.container.frame.width / 2,
|
||||
y: canvas.floatingSpace.container.frame.height / 2
|
||||
}
|
||||
} else {
|
||||
payload.targetPosition = {
|
||||
x: chainParent.payload.position.x,
|
||||
y: chainParent.payload.position.y
|
||||
x: chainParent.payload.position.x - canvas.floatingSpace.container.frame.position.x,
|
||||
y: chainParent.payload.position.y - canvas.floatingSpace.container.frame.position.y
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user