Path: blob/main/public/games/files/algaes-escapade/js/lib/utils.js
1036 views
function include_once(includes)1{2if ( typeof($('head').data('included')) == 'undefined' )3{4$('head').data('included', []);5}67for ( var i = 0; i < includes.length; i++ )8{9if ( $.inArray(includes[i], $('head').data('included')) === -1 )10{11$('head').append(12'<script type="text/javascript" src="js/'+includes[i]+'"></script>'13);1415$('head').data('included').push(includes[i]);16}17}18}1920function playerCollides(playable, rect, drag)21{22if ( typeof(drag) == 'undefined' )23{24drag = 50;25}2627//Define the top edge (left to right, along the top of the28//colliding block)29var topEdge = [ [rect.left, rect.top], [rect.right, rect.top] ];3031//Define the top edge (left to right, along the bottom of the32//colliding this)33var bottomEdge = [ [rect.left, rect.bottom], [rect.right, rect.bottom] ];3435//Define the left edge (top to bottom, along the left of the36//colliding this)37var leftEdge = [ [rect.left, rect.top], [rect.left, rect.bottom] ];3839//Define the right edge (top to bottom, along the right of the40//colliding this)41var rightEdge = [ [rect.right, rect.top], [rect.right, rect.bottom] ];4243//Check the top and bottom colliision points. If a collision is44//detected then set the velocity on the Y axis to zero and move45//the playable so that it is no longer colliding46if ( playable.rect.collideLine(topEdge[0], topEdge[1]) )47{48var newX = playable.getVelocity().x;49if (newX < 0 )50{51newX += drag;52}53else if ( newX > 0 )54{55newX -= drag;56}57playable.setVelocity( newX, 0 );58playable.rect.bottom = (rect.top - 0.01);59playable.setMovement('walk');60}61else if ( playable.rect.collideLine(bottomEdge[0], bottomEdge[1]) )62{63playable.setVelocity( playable.getVelocity().x, 0 );64playable.rect.top = (rect.bottom + 0.01);65}6667//Check the left and right colliision points. If a collision is68//detected then set the velocity on the X axis to zero and move69//the playable so that it is no longer colliding70if ( playable.rect.collideLine(leftEdge[0], leftEdge[1]) )71{72playable.setVelocity( 0, playable.getVelocity().y );73playable.rect.right = (rect.left - 0.01);7475}76else if ( playable.rect.collideLine(rightEdge[0], rightEdge[1]) )77{78playable.setVelocity( 0, playable.getVelocity().y );79playable.rect.left = (rect.right + 0.01);80}81}8283