Commit 3ba0bafa authored by Raphaël Bastide's avatar Raphaël Bastide

Checkpoint

parent 4daf078e
var Example = Example || {};
Example.car = function() {
var urlRider = urlRider || {};
history.pushState(null, null, '#ddbftbgfffftuuffffdfff');
urlRider.car = function() {
var Engine = Matter.Engine,
Render = Matter.Render,
Runner = Matter.Runner,
......@@ -28,16 +28,16 @@ Example.car = function() {
// create renderer
var render = Render.create({
element: document.body,
engine: engine,
options: {
wireframes:false,
width: 1900,
height: 1000,
showAngleIndicator: false,
showCollisions: false,
background: '#222',
}
element: document.body,
engine: engine,
options: {
wireframes:false,
width: 1900,
height: 1000,
showAngleIndicator: false,
showCollisions: false,
background: '#222',
}
});
var startX = 100
var startY = 200
......@@ -60,7 +60,7 @@ Example.car = function() {
var car = Composites.car(150, 100, 150, 30, 40)
var ball = Bodies.circle(100, 100, 100, { friction:1, frictionAir:.003, restitution: 0.2})
var bonus = Bodies.circle(1800, 0, 100, {name:"bonus",isStatic:true, isSensor:true})
var bonus = Bodies.circle(1800, 0, 10, {name:"bonus",isStatic:true, isSensor:true})
bonus.render.fillStyle ="red"
ball.render.sprite.texture = 'img/ball.svg'
// ball.render.fillStyle = ballColor
......@@ -158,6 +158,13 @@ Example.car = function() {
getDistances(unit)
nextPos.x += unit.distances.w
nextPos.y += unit.distances.h
}else if (char == 't') {
var unit = Bodies.rectangle(nextPos.x, posY, w, h, { isStatic: true})
unit.name = 'time'
unit.render.fillStyle = '#2797f2'+tr
getDistances(unit)
nextPos.x += unit.distances.w
nextPos.y += unit.distances.h
}else if (char == "1") { // up
nextPos.x += 0
nextPos.y += -500
......@@ -194,8 +201,7 @@ Example.car = function() {
var zoom = 500
var zoomTarget = 500
var counter = 0
var bulletTime = false
var bonusTime = false
var bulletTime, bonusTime, isBackInTime, checkPoint, lastCollided = false
// Render after each Tick
Events.on( engine, 'afterTick', (e)=> {
......@@ -238,13 +244,13 @@ Example.car = function() {
for (var i = 0, j = pairs.length; i != j; ++i) {
var pair = pairs[i];
var col = pair.bodyB.render.fillStyle
col = col.substring(0, col.length - 2);
pair.bodyB.render.fillStyle = col+"FF"
console.log(col);
if (col !== "#ffffff00") { // If not transparent, highlight the color when collision
col = col.substring(0, col.length - 2);
pair.bodyB.render.fillStyle = col+"FF"
}
if (pair.bodyB.name === 'boost') {
pair.bodyA.render.fillStyle = '#00FF00';
Body.setVelocity(ball, { x: 50, y: 0 });
// bell.triggerAttackRelease(300);
}else if(pair.bodyB.name === 'bulletTime') {
ball.render.sprite.texture = 'img/ball-bullettime.svg'
bulletTime = true
......@@ -260,11 +266,24 @@ Example.car = function() {
}else {
engine.world.gravity.y = -1;
}
}else if(pair.bodyB.name === 'time') {
var currentCollided = pair.bodyB.id; // avoid repeated collision
if ( lastCollided != currentCollided) {
if (isBackInTime) {
// console.log('back',checkPoint);
console.log(ball.position.x, ball.position.y);
Body.setPosition(ball,{x:checkPoint.x, y:checkPoint.y})
isBackInTime = false
}else {
checkPoint = {x:ball.position.x, y:ball.position.y}
isBackInTime = true
}
lastCollided = currentCollided
}
}
}
});
// context for MatterTools.Demo
return {
engine: engine,
runner: runner,
......
......@@ -7,7 +7,7 @@
*/
(function() {
var sourceLinkRoot = 'https://github.com/liabru/matter-js/blob/master/examples';
var sourceLinkRoot = 'https://gitlab.com/raphaelbastide/urlrider';
var urlcar = MatterTools.Demo.create({
// toolbar: false,
......@@ -34,12 +34,11 @@
{
name: 'Car',
id: 'car',
init: Example.car,
init: urlRider.car,
sourceLink: sourceLinkRoot + '/car.js'
}
]
});
document.body.appendChild(urlcar.dom.root);
MatterTools.Demo.start(urlcar);
})();
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