Commit 4daf078e authored by Raphaël Bastide's avatar Raphaël Bastide

Bonus, more platform type, tests.

parent 9fdc8cfb
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="200"
height="200"
viewBox="0 0 52.916668 52.916668"
version="1.1"
id="svg8"
inkscape:version="0.92.3 (2405546, 2018-03-11)"
sodipodi:docname="bonus.svg">
<defs
id="defs2" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="2.8"
inkscape:cx="-16.017187"
inkscape:cy="101.59706"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="false"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0"
inkscape:window-width="1920"
inkscape:window-height="1024"
inkscape:window-x="0"
inkscape:window-y="868"
inkscape:window-maximized="1"
units="px" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(46.310902,285.37685)">
<circle
id="path817"
style="opacity:1;vector-effect:none;fill:#ff0000;fill-opacity:1;stroke:none;stroke-width:0.59829068;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal"
cx="-19.852568"
cy="-258.91852"
r="26.458334"
inkscape:export-xdpi="57.439999"
inkscape:export-ydpi="57.439999" />
<g
id="g940"
transform="matrix(0.31873447,0.02352675,-0.02320874,0.3231018,-5.661252,-170.34948)"
style="stroke:#ffffff;stroke-width:7.7697587;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none">
<path
style="opacity:1;vector-effect:none;fill:none;fill-opacity:1;stroke:#ffffff;stroke-width:7.7697587;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal"
d="m -90.544714,-264.43722 c 5.304341,0.78317 10.700125,-0.26491 16.063629,-0.38683 1.041152,-0.0237 2.090544,0.0217 3.127462,-0.0538"
id="path868"
inkscape:connector-curvature="0" />
<path
style="opacity:1;vector-effect:none;fill:none;fill-opacity:1;stroke:#ffffff;stroke-width:7.7697587;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal"
d="m -80.091698,-272.59188 c -0.04962,0.62408 -0.202903,1.11882 -0.22009,1.75568 -0.05264,1.9503 0.334741,4.16881 0.09492,6.08187 -0.350846,2.79873 -0.558332,5.47244 -0.346938,8.3756"
id="path870"
inkscape:connector-curvature="0" />
<path
style="opacity:1;vector-effect:none;fill:none;fill-opacity:1;stroke:#ffffff;stroke-width:7.7697587;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal"
d="m -58.718888,-281.74214 c 1.263179,-0.93935 2.820754,-2.04422 3.852415,-3.23793 1.73214,-2.0042 2.904101,-2.79342 4.203899,-5.08843 0.405227,-0.71549 2.992305,-1.4795 3.362614,-2.21261 0.242176,-0.47945 0.401962,-1.13522 0.363317,-0.98327 -0.245806,0.96643 0.12248,2.13617 0.05376,3.12746 -0.182406,2.63132 0.32724,5.26618 0.227229,7.89888 -0.01699,0.44725 0.16236,0.94247 0.100805,1.38438 -0.158473,1.13765 -0.395737,2.34139 -0.440183,3.51136 -0.0179,0.47123 0.164464,1.16956 0.03318,1.65026 -0.07187,0.26317 -0.324447,0.45707 -0.382217,0.72369 -0.234018,1.08011 0.216834,2.37376 0.07897,3.47356 -0.02739,0.21852 -0.181664,0.40695 -0.215472,0.62457 -0.17369,1.1181 0.173669,2.32215 -0.100384,3.39963 -0.285747,1.12346 0.621282,2.61847 0.270911,3.72053 -0.387073,1.21749 0.208375,6.44537 0.326354,8.06563"
id="path872"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccccsccccccscc" />
</g>
</g>
</svg>
......@@ -4,7 +4,9 @@ Example.car = function() {
var Engine = Matter.Engine,
Render = Matter.Render,
Runner = Matter.Runner,
Composite = Matter.Composite,
Composites = Matter.Composites,
Constraint = Matter.Constraint,
MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse,
World = Matter.World,
......@@ -20,7 +22,6 @@ Example.car = function() {
}else {
terrain = terrain.split('')
}
console.log(terrain);
// create engine
var engine = Engine.create(),
world = engine.world;
......@@ -44,7 +45,8 @@ Example.car = function() {
var lastDir = 0
var w = 400
var h = 10
var platformColor = "#CCC"
var tr = "77"
var platformColor = "#CCCCCC"+tr
var ballColor = "#e91763"
var zoom = false
......@@ -58,10 +60,26 @@ 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})
bonus.render.fillStyle ="red"
ball.render.sprite.texture = 'img/ball.svg'
// ball.render.fillStyle = ballColor
var tailBall = Bodies.circle(-10, -10, 10, 60);
var tail = Constraint.create({
bodyA: ball,
pointA: { x: 0, y: 0 },
bodyB: tailBall,
pointB: { x: 0, y: 0 },
stiffness: 0.001,
// damping: 0.2
});
World.add(world, ball);
World.add(world, [
// tail,
// tailBall,
bonus,
ball
]);
// World.add(world, car);
for (var i = 0; i < terrain.length; i++) {
......@@ -76,7 +94,7 @@ Example.car = function() {
function buildUnit(char, nextPos){
var posY = nextPos.y
if (char == 'f') {
var unit = Bodies.rectangle(nextPos.x, posY, w, h, { isStatic: true, angle: Math.PI * 0.0 })
var unit = Bodies.rectangle(nextPos.x, posY, w, h, { isStatic: true })
unit.name = 'flat'
unit.render.fillStyle = platformColor
getDistances(unit)
......@@ -97,9 +115,9 @@ Example.car = function() {
nextPos.x += unit.distances.w
nextPos.y += unit.distances.h
}else if (char == 'b') {
var unit = Bodies.rectangle(nextPos.x, posY, w, h, {isStatic: true, angle: Math.PI * 0.0})
var unit = Bodies.rectangle(nextPos.x, posY, w, h, {isStatic: true})
unit.name = 'boost'
unit.render.fillStyle = '#60a74b'
unit.render.fillStyle = '#60a74b'+tr
getDistances(unit)
nextPos.x += unit.distances.w
nextPos.y += unit.distances.h
......@@ -111,30 +129,45 @@ Example.car = function() {
nextPos.x += 100
nextPos.y += 0
}else if (char == 'z') {
var unit = Bodies.rectangle(nextPos.x, posY , w, h, {isStatic: true, angle: Math.PI * 0})
var unit = Bodies.rectangle(nextPos.x, posY , w, h, {isStatic: true})
unit.name = 'bulletTime'
unit.render.fillStyle = "#ba36a0"
unit.render.fillStyle = "#ba36a0"+tr
getDistances(unit)
nextPos.x += unit.distances.w
nextPos.y += unit.distances.h
}else if (char == 'g') { // gap
var unit = Bodies.rectangle(nextPos.x, posY, w, h, { isStatic: true, angle: Math.PI * 0.0 })
} else if (char == 'g') {
var unit = Bodies.rectangle(nextPos.x, posY, w, h, { isStatic: true})
unit.name = 'gap'
unit.render.fillStyle = 'rgba(0,0,0,0)'
unit.render.fillStyle = '#ffffff00'
unit.isSensor = true
getDistances(unit)
nextPos.x += unit.distances.w
nextPos.y += unit.distances.h
}else if (char == 'j') { // gap
var unit = Bodies.rectangle(nextPos.x, posY, w, h, { isStatic: true, angle: Math.PI * 0.0 })
}else if (char == 'j') {
var unit = Bodies.rectangle(nextPos.x, posY, w, h, { isStatic: true})
unit.name = 'jump'
unit.render.fillStyle = '#f227dd'
unit.render.fillStyle = '#f227dd'+tr
unit.isSensor = true
getDistances(unit)
nextPos.x += unit.distances.w
nextPos.y += unit.distances.h
}else if (char == 'i') {
var unit = Bodies.rectangle(nextPos.x, posY, w, h, { isStatic: true})
unit.name = 'invertedGravity'
unit.render.fillStyle = '#f2b927'+tr
getDistances(unit)
nextPos.x += unit.distances.w
nextPos.y += unit.distances.h
}else if (char == "1") { // up
nextPos.x += 0
nextPos.y += -500
}else if (char == "0") { // down
nextPos.x += 0
nextPos.y += 500
}
if (unit != null) {
World.add(world,unit);
}
World.add(world,unit);
}
function getDistances(unit){
......@@ -157,44 +190,46 @@ Example.car = function() {
// World.add(world, mouseConstraint);
render.mouse = mouse;
var timeScaleTarget = 1
var zoom = 500
var zoomTarget = 500
var counter = 0
var bulletTime = false
Events.on( engine, 'afterTick', (e)=> {
// Render.lookAt( render, car.bodies[0].bounds.max, {x: 500, y: 500 },true );
var bonusTime = false
// Render after each Tick
Events.on( engine, 'afterTick', (e)=> {
if (bulletTime) {
engine.timing.timeScale += (timeScaleTarget - engine.timing.timeScale) * 0.05;
engine.timing.timeScale
zoom += (zoomTarget - zoom) * 0.05;
if (counter >= 60 * 3.5) {
zoomTarget = 500
timeScaleTarget = 1
console.log(1);
}else{
zoomTarget = 200
timeScaleTarget = 0.05
console.log(2);
}
if (counter >= 60 * 3.6) {
ball.render.sprite.texture = 'img/ball.svg'
}
if (counter >= 60 * 4.5) {
engine.timing.timeScale = 1
bulletTime = false
timeScaleTarget = 1
zoomTarget = 500
zoom = 500
counter = 0
bulletTime = false
}
counter +=1
}
// console.log(ball.render.sprite.texture);
console.log(bulletTime);
if (bonusTime) {
if (counter >=50) {
console.log(counter);
ball.render.sprite.texture = 'img/ball.svg'
bonusTime = false
}
counter +=1
}
Render.lookAt(render, ball, {x: zoom, y: zoom },true );
})
......@@ -202,6 +237,10 @@ Example.car = function() {
var pairs = event.pairs;
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 (pair.bodyB.name === 'boost') {
pair.bodyA.render.fillStyle = '#00FF00';
Body.setVelocity(ball, { x: 50, y: 0 });
......@@ -209,8 +248,18 @@ Example.car = function() {
}else if(pair.bodyB.name === 'bulletTime') {
ball.render.sprite.texture = 'img/ball-bullettime.svg'
bulletTime = true
}else if(pair.bodyB.name === 'bonus') {
bonusTime = true
bonus.render.fillStyle = "#ffffff00"
ball.render.sprite.texture ="img/bonus.svg"
}else if(pair.bodyB.name === 'jump') {
Body.setVelocity(ball, { x: ball.speed, y: -50 });
}else if(pair.bodyB.name === 'invertedGravity') {
if (engine.world.gravity.y == -1) {
engine.world.gravity.y = 1;
}else {
engine.world.gravity.y = -1;
}
}
}
});
......
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