Commit 5b2573f2 authored by Bruno Coudoin's avatar Bruno Coudoin
Browse files

football, better management of Tux collition

parent ca9e829d
...@@ -34,6 +34,7 @@ var flag = 0 ...@@ -34,6 +34,7 @@ var flag = 0
var friction = 0.995 var friction = 0.995
var velocityX var velocityX
var velocityY var velocityY
var tuxCollision
function start(items_) { function start(items_) {
items = items_ items = items_
...@@ -50,6 +51,7 @@ function initLevel() { ...@@ -50,6 +51,7 @@ function initLevel() {
items.ball.y = items.border.height / 2 - items.ball.height / 2 items.ball.y = items.border.height / 2 - items.ball.height / 2
velocityX = 0 velocityX = 0
velocityY = 0 velocityY = 0
tuxCollision = false
/* Increase size of TUX for each level */ /* Increase size of TUX for each level */
items.tux.sourceSize.height = 10 * (5 + 2 * items.bar.level) * GCompris.ApplicationInfo.ratio items.tux.sourceSize.height = 10 * (5 + 2 * items.bar.level) * GCompris.ApplicationInfo.ratio
moveTux(items.background.height) moveTux(items.background.height)
...@@ -76,6 +78,7 @@ function startMotion(x1, y1) { ...@@ -76,6 +78,7 @@ function startMotion(x1, y1) {
/* Modify speed of ball here */ /* Modify speed of ball here */
velocityX = velocity * x1 * 0.01 * -1 / 5 velocityX = velocity * x1 * 0.01 * -1 / 5
velocityY = velocity * y1 * 0.01 * -1 / 5 velocityY = velocity * y1 * 0.01 * -1 / 5
tuxCollision = false
items.timer.start() items.timer.start()
} }
...@@ -130,6 +133,7 @@ function ballMotion() { ...@@ -130,6 +133,7 @@ function ballMotion() {
if(items.ball.y > (items.border.height - items.ball.height)) { //bottom if(items.ball.y > (items.border.height - items.ball.height)) { //bottom
velocityY *= -1 velocityY *= -1
items.ball.y = items.border.height - items.ball.height items.ball.y = items.border.height - items.ball.height
tuxCollision = false
} else if(items.ball.x > (items.border.width)) { //right ---- GOAL! } else if(items.ball.x > (items.border.width)) { //right ---- GOAL!
velocityX *= 0 velocityX *= 0
velocityY *= 0 velocityY *= 0
...@@ -138,18 +142,21 @@ function ballMotion() { ...@@ -138,18 +142,21 @@ function ballMotion() {
} else if(items.ball.x < 0) { // left } else if(items.ball.x < 0) { // left
velocityX *= -1 velocityX *= -1
items.ball.x = 0 items.ball.x = 0
tuxCollision = false
} else if(items.ball.y < 0) { //top } else if(items.ball.y < 0) { //top
velocityY *= -1 velocityY *= -1
items.ball.y = 0 items.ball.y = 0
tuxCollision = false
} }
/* Collision with TUX */ /* Collision with TUX */
else if(items.ball.y > items.tux.y && else if(items.ball.y > items.tux.y &&
items.ball.y <= items.tux.y + items.tux.height/2 && items.ball.y <= items.tux.y + items.tux.height/2 &&
items.ball.x > items.tux.x && items.ball.x > items.tux.x &&
items.ball.x <= items.tux.x + items.tux.width/2){ items.ball.x <= items.tux.x + items.tux.width/2 &&
velocityY *= -1 !tuxCollision) {
velocityX *= -1 velocityY *= -2
items.ball.x = items.ball.x - items.tux.width velocityX *= -2
tuxCollision = true
} }
// Friction // Friction
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment