Commit c497804a authored by Raphaël Bastide's avatar Raphaël Bastide

Check locked units

parent ff07ebc0
* {
box-sizing: border-box;
}
html, body{
height: 100%;
}
body {
margin: 0;
padding: 0;
}
.matter-header-outer{display: none!important;}
.matter-demo{
background: #eee!important;
display: flex;
justify-content: center;
align-items: center;
}
canvas{
position: relative;
}
canvas:before{
z-index: 1000000;
box-shadow: 0px 0px 16px red inset;
background: red;
content:"";
position: absolute;
top:0;
left:0;
bottom: 0;
right: 0;
}
/**
* The Matter.js demo page controller and example runner.
*
* NOTE: For the actual example code, refer to the source files in `/examples/`.
*
* @class Demo
*/
(function() {
var sourceLinkRoot = 'https://gitlab.com/raphaelbastide/urlrider';
var urlcar = MatterTools.Demo.create({
// toolbar: false,
toolbar: {
title: 'urlcar',
// url: 'https://github.com/liabru/matter-js',
reset: false,
source: false,
inspector: false,
tools: false,
fullscreen: false,
exampleSelect: false
},
tools: {
inspector: false,
gui: false
},
inline: false,
preventZoom: false,
resetOnOrientation: true,
routing: false,
startExample: 'car',
examples: [
{
name: 'Car',
id: 'car',
init: urlRider.car,
sourceLink: sourceLinkRoot + '/car.js'
}
]
});
document.body.appendChild(urlcar.dom.root);
// MatterTools.Demo.start(urlcar);
})();
......@@ -22,7 +22,7 @@
"name": "up",
"char": "u",
"verticalShift": "1",
"isLocked": false,
"isLocked": true,
"color":"#eeeeee",
"angle":"-0.2",
"isStatic":true
......@@ -31,7 +31,7 @@
"name": "gap",
"char": "g",
"verticalShift": "0",
"isLocked": false,
"isLocked": true,
"color":"#ffffff00",
"angle":"0",
"isStatic":true,
......@@ -41,7 +41,7 @@
"name": "boost",
"char": "b",
"verticalShift": "0",
"isLocked": false,
"isLocked": true,
"color":"#e26262",
"angle":"0",
"isStatic":true
......@@ -50,7 +50,7 @@
"name": "time",
"char": "t",
"verticalShift": "0",
"isLocked": false,
"isLocked": true,
"color":"#532890",
"angle":"0",
"isStatic":true
......@@ -59,7 +59,7 @@
"name": "invertedGravity",
"char": "i",
"verticalShift": "0",
"isLocked": false,
"isLocked": true,
"color":"#69e262",
"angle":"0",
"isStatic":true
......@@ -68,7 +68,7 @@
"name": "jump",
"char": "j",
"verticalShift": "0",
"isLocked": false,
"isLocked": true,
"color":"#62e2c3",
"angle":"0",
"isStatic":true
......@@ -77,7 +77,7 @@
"name": "bulletTime",
"char": "z",
"verticalShift": "0",
"isLocked": false,
"isLocked": true,
"color":"#dfe262",
"angle":"0",
"isStatic":true
......
......@@ -61,6 +61,7 @@ function launch(units){
var toBuild = Bodies.circle(bonus.posX, bonus.posY, 20,{isStatic:true, isSensor:true})
var toUnLock = findObjectsByKey(data.units, 'name', bonus.unlocks)[0]
var bonusColor = toUnLock.color
toUnLock.isLocked = false
toBuild.render.fillStyle = bonusColor
World.add(world,toBuild);
}
......@@ -87,39 +88,41 @@ function launch(units){
// Building terrain from the character array
function buildUnit(char, nextPos){
var unit = findObjectsByKey(data.units, 'char', char)[0];
if (unit.type == "buildPlace") {
nextPos.x += 0
nextPos.y += unit.verticalShift
}else{
if (unit.verticalShift == 1) {
var posX = nextPos.x
var posY = nextPos.y + (unit.angle * 550) - 6
}else if (unit.verticalShift == 0) {
var posX = nextPos.x + 35
var posY = nextPos.y + (unit.angle * 550)
}else if (unit.verticalShift == -1) {
var posX = nextPos.x
var posY = nextPos.y + (unit.angle * 550) + 6
}
w += w * Math.round(Math.abs(unit.angle))
var toBuild = Bodies.rectangle(posX, posY, w, h, {isStatic:unit.isStatic,angle: Math.PI * unit.angle})
toBuild.isLocked = unit.isLocked
toBuild.name = unit.name
toBuild.isSensor = unit.isSensor
toBuild.render.fillStyle = unit.color + alpha
getDistances(toBuild)
if (toBuild != null) {
World.add(world,toBuild);
}
if (unit.verticalShift == 1) {
nextPos.x += Math.round(toBuild.distances.w)
nextPos.y -= Math.round(toBuild.distances.h) - h
}else if (unit.verticalShift == 0) {
nextPos.x += Math.round(toBuild.distances.w)
nextPos.y += Math.round(toBuild.distances.h) - h
}else {
nextPos.x += Math.round(toBuild.distances.w)
nextPos.y += Math.round(toBuild.distances.h) - h
if (checkLock(unit) == false) { // if not locked, add the unit
if (unit.type == "buildPlace") {
nextPos.x += 0
nextPos.y += unit.verticalShift
}else{
if (unit.verticalShift == 1) {
var posX = nextPos.x
var posY = nextPos.y + (unit.angle * 550) - 6
}else if (unit.verticalShift == 0) {
var posX = nextPos.x + 35
var posY = nextPos.y + (unit.angle * 550)
}else if (unit.verticalShift == -1) {
var posX = nextPos.x
var posY = nextPos.y + (unit.angle * 550) + 6
}
w += w * Math.round(Math.abs(unit.angle))
var toBuild = Bodies.rectangle(posX, posY, w, h, {isStatic:unit.isStatic,angle: Math.PI * unit.angle})
toBuild.isLocked = unit.isLocked
toBuild.name = unit.name
toBuild.isSensor = unit.isSensor
toBuild.render.fillStyle = unit.color + alpha
getDistances(toBuild)
if (toBuild != null) {
World.add(world,toBuild);
}
if (unit.verticalShift == 1) {
nextPos.x += Math.round(toBuild.distances.w)
nextPos.y -= Math.round(toBuild.distances.h) - h
}else if (unit.verticalShift == 0) {
nextPos.x += Math.round(toBuild.distances.w)
nextPos.y += Math.round(toBuild.distances.h) - h
}else {
nextPos.x += Math.round(toBuild.distances.w)
nextPos.y += Math.round(toBuild.distances.h) - h
}
}
}
}
......@@ -131,9 +134,15 @@ function launch(units){
}
function checkLock(unit){
if (unit.isLocked == true) {
notifAlert(unit.name)
notifAlert(unit)
return true
}else {
return false
}
}
function notifAlert(unit){
alert(unit.name+' ('+unit.char+') is locked. Unlock it so you can use it in the URL')
}
function unlock(unit){
unit.isLocked = false
}
......
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