minkowskibroski
by hotfeet
JavaScript
var canvas;
var ctx;
var displayWidth;
var displayHeight;
var displayRadius;
var now;
var dt;
var last;
var step;
var mousePos;
var PI2 = Math.PI * 2;
var g = 3;
var colors = [
"blue",
"green",
"yellow",
"red"
];
var rectSize;
var rects;
var player;
function init() {
//landscape
displayWidth = 480;
displayHeight = 320;
//portrait
//displayWidth = 320;
//displayHeight = 480;
displayRadius = 0.5 * Math.sqrt(displayWidth + displayHeight);
//create the canvas to use for rendering
canvas = document.createElement("canvas");
canvas.width = displayWidth;
canvas.height = displayHeight;
//append the render canvas to the document
document.body.appendChild(canvas);
//get the drawing context of the render canvas
ctx = canvas.getContext("2d");
//set the default values of the time vars
now = 0;
dt = 0,
last = timestamp(),
step = 1 / 60;
fps = 0;
//add input event listeners
mousePos = { x: 0, y: 0 };
canvas.addEventListener('mousemove', function(evt) {
mousePos = getMousePos(canvas, evt);
}, false);
canvas.addEventListener('mouseup', function(evt) {
player.addForce(0, -g * 4);
}, false);
//setup game here
rects = [];
rectSize = 32;
var rectSpanCount = displayWidth / rectSize;
for(var i = 0; i < rectSpanCount; i++) {
var r = new rect(i * rectSize, displayHeight - rectSize, rectSize, rectSize, colors[i % colors.length]);
rects.push(r);
}
rects.push(new rect(0, displayHeight - rectSize * 2, rectSize, rectSize, colors[0]));
rects.push(new rect(displayWidth - rectSize, displayHeight - rectSize * 2, rectSize, rectSize, colors[3]));
rects.push(new rect(displayWidth / 2, displayHeight / 2, rectSize, rectSize, "purple"));
player = rects[rects.length - 1];
//request an animation frame pass it the update method
requestAnimationFrame(frame);
}
function rect(x, y, width, height, color) {
this.pos = {x:x,y:y};
this.vel = {x:0,y:0};
this.acc =...