MCPcopy Create free account
hub / github.com/Code-Bullet/Jump-King / CheckCollisions

Method CheckCollisions

Player.js:367–593  ·  view source on GitHub ↗
(currentLines)

Source from the content-addressed store, hash-verified

365 }
366
367 CheckCollisions(currentLines) {
368
369 let collidedLines = [];
370 for (let i = 0; i < currentLines.length; i++) {
371 if (this.IsCollidingWithLine(currentLines[i])) {
372 collidedLines.push(currentLines[i]);
373 }
374 }
375
376 let chosenLine = this.GetPriorityCollision(collidedLines)
377
378 let potentialLanding = false;
379 if (chosenLine == null) return;
380
381 if (chosenLine.isHorizontal) {
382 if (this.IsMovingDown()) {
383 // so the player has potentially landed
384 //correct the position first then player has landed
385 this.currentPos.y = chosenLine.y1 - this.height;
386
387 if (collidedLines.length > 1) {
388 potentialLanding = true;
389 if (levels[this.currentLevelNo].isIceLevel) {
390 this.currentSpeed.y = 0;
391 if (this.IsMovingRight()) {
392 this.currentSpeed.x -= iceFrictionAcceleration;
393 } else {
394 this.currentSpeed.x += iceFrictionAcceleration;
395 }
396
397 } else {
398 this.currentSpeed = createVector(0, 0)
399
400 }
401 // print("potentail landing on nooooooo")
402
403 } else {
404 this.playerLanded();
405 }
406
407 } else {
408 // if moving up then we've hit a roof and we bounce off
409
410 this.currentSpeed.y = 0 - this.currentSpeed.y / 2;
411 // ok we gonna need to snap this shit
412 this.currentPos.y = chosenLine.y1;
413 if (!mutePlayers || testingSinglePlayer) {
414 bumpSound.playMode('sustain');
415 bumpSound.play();
416 }
417
418 }
419
420
421 } else if (chosenLine.isVertical) {
422 if (this.IsMovingRight()) {
423 this.currentPos.x = chosenLine.x1 - this.width;
424 } else if (this.IsMovingLeft()) {

Callers 1

UpdateMethod · 0.95

Calls 7

IsCollidingWithLineMethod · 0.95
GetPriorityCollisionMethod · 0.95
IsMovingDownMethod · 0.95
IsMovingRightMethod · 0.95
playerLandedMethod · 0.95
IsMovingLeftMethod · 0.95
IsPlayerOnGroundMethod · 0.95

Tested by

no test coverage detected