-
-
Save DavidBuchanan314/13f4c4e8d9573108ff9999be56844022 to your computer and use it in GitHub Desktop.
Original version from https://killedbyapixel.github.io/TinyCode/games/CrossMyHeart/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
X=Y=V=U=Z=t=1;onkeydown=e=>(k=e.which)&1?X-=k-38:Y-=k-39;setInterval("for(++t,o=Z,i=50;i--;)for(b.innerText=o+='\\n',j=99;j--;Y>49?Z+=Y=1:o+=i-Y|j-X-50?q?'.':'█':q?'♥':Y=1)q=((j+t*Math.sin(A=i>>1)/9*Z>>3)*A*Z)**4%97<89",9) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
X=Y=1; // player position | |
level=t=1; | |
onkeydown = e => { | |
let k = e.which; // a deprecated but functional equivalent to e.keyCode | |
// left = 37 | |
// right = 39 | |
// up = 38 | |
// down = 40 | |
if (k & 1) { // up or down | |
X -= k - 38; | |
} else { // left or right | |
Y -= k - 39 | |
} | |
}; | |
setInterval(() => { | |
++t; // increment time | |
let out = level; // current level is displayed at the top | |
for(let i = 50 + 1; i >= 0; i--) { // for each line of generated text | |
let vehicle_row = i >> 1; // floored div by 2 (vehicles are 2 rows tall) | |
b.innerText = out += '\n'; | |
for(let j = 100; j >= 0; j--) { | |
// procedural vehicle position calculation. | |
// to be honest I can't figure out how the longer vehicles come to be - very clever | |
let is_empty_space = ( | |
(j + t * Math.sin(vehicle_row)/9 * level>>3) * vehicle_row * level | |
)**4 % 97 < 89; | |
if ( Y > 49 ) { // top row, time to level up | |
Y=1; | |
level++; | |
} else { // do collision detection | |
if (i-Y | j-X-50) { // if the player is not at this coordinate (X coordinate centered on column 50) | |
out += is_empty_space ? '.' : '█'; // render road/vehicles | |
} else { | |
out += is_empty_space ? '♥' : Y=1; // render the player if no collision, or reset Y pos | |
} | |
} | |
} | |
} | |
}, 9); // run every 9ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment