Why wont this shitty Javascript collision detection system work?function colCheck(shapeA, shapeB) {
// get the vectors to check against
var vX = (shapeA.x + (shapeA.width / 2)) - (shapeB.x + (shapeB.width / 2)),
vY = (shapeA.y + (shapeA.height / 2)) - (shapeB.y + (shapeB.height / 2)),
// add the half widths and half heights of the objects
hWidths = (shapeA.width / 2) + (shapeB.width / 2),
hHeights = (shapeA.height / 2) + (shapeB.height / 2),
colDir = null;
// if the x and y vector are less than the half width or half height, they we must be inside the object, causing a collision
if (Math.abs(vX) < hWidths && Math.abs(vY) < hHeights) { // figures out on which side we are colliding (top, bottom, left, or right)
//var oX = hWidths - Math.abs(vX), oY = hHeights - Math.abs(vY); if (oX >= oY) {
if (vY > 0) {
colDir = "t";
shapeA.y += oY;
} else {
colDir = "b";
shapeA.y -= oY;
}
} else {
if (vX > 0) {
colDir = "l";
shapeA.x += oX;
} else {
colDir = "r";
shapeA.x -= oX;
}
}
}
return colDir;
}
Chrome dev tools says it's an illegal return statement
>>56272368
post your shapea and shape b too
>>56272368
>repeating arithmetic operations instead of storing the result in a variable
>variables instead of consts
>longass lines with comments behind instead of above
>code in comments
>writing comments of no value like "add half the height"
>returning results as strings instead of something like public consts or other enum-likes
how was le code bootcamp? :)))
>>56272395player = {
x : width/2,
y : height - 100,
width : 5,
height : 20,
speed : 3,
velX : 0,
velY : 0,
jumping : false,
grounded : false
};
box = {
x: 0,
y: 0,
width: 10,
height: 100
};
>>56272408
wait the box width is 10 and your player width is 5 so if you have 2 players you are more than likely going to collide or overflow outside the box?
>>56272436
if your x is 2.5 for each player you will be in the box if its less than that you will overflow out if its more you will collide
>>56272446
and please use
https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Drawing_shapes
and not your own object
>>56272458
also please use javascript object prototype and create a .getx() and a .gety() to get x and y co-ordinates otherwise anyone can change the x and y variables when instancing or when ever
>>56272488
wait so how do you instance your shape? if x is a function, how do you move the shape across the x and y axis?
Pajeet-tier code quality.
>>56272654
How would you improve it?
>>56272654
>>56272407
>>56272458
OP here: im just following this JS tutorial to get a quick grasp of how games are developed with JS.
http://www.somethinghitme.com/2013/01/09/creating-a-canvas-platformer-tutorial-part-one/
Please link me a better tutorial if you know of any
>>56273362
just read a fkn book
>>56273362
Everyone on reddit said it's a good tutorial but 4chan thinks it's bad
>>56273848
It is a decent tutorial for beginners but nothing that is good comes to you easy. Only hard work or talent will get you good results.
>>56274375
Thanks for nothing
>>56274392
https://shodan.me/books/
Have fun plebbit monkey.