Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
soer8647 committed Jul 4, 2017
0 parents commit c766324
Show file tree
Hide file tree
Showing 262 changed files with 46,560 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "leaderboard-bf98b"
}
}
32 changes: 32 additions & 0 deletions Other versions/0.3/Ball.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function Ball(startx,starty, vx, vy, radius) {
this.x = startx;
this.y = starty;
this.radius = radius;
this.xd = randomsign();
this.yd = randomsign();
this.dx = vx;
this.dy = vy;
this.move = function() {
if (this.x+this.dx > height-this.radius || this.x+this.dx < this.radius) {
this.xd = -this.xd;
}
if (this.y+this.dy > width-this.radius || this.y+this.dy < this.radius) {
this.yd = -this.yd;
}

this.x = this.x + this.dx * this.xd;
this.y = this.y + this.dy * this.yd;
}

this.shape = function() {
return new circle(this.x,this.y,this.radius);
}

this.draw = function(ctx) {
ctx.beginPath();
ctx.arc(this.x, this.y, this.radius, 0, Math.PI*2, false);
ctx.fillStyle = "green";
ctx.fill();
ctx.closePath();
}
}
54 changes: 54 additions & 0 deletions Other versions/0.3/Calculations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
console.log("Calculations");

function circle(x,y,radius) {
this.x = x;
this.y = y;
this.r = radius;
}

function rectangle(x,y,width,height) {
this.x = x;
this.y = y;
this.w = width;
this.h = height;
}

function dist(x1,y1,x2,y2) {
return Math.sqrt(Math.pow(Math.abs(x1 - x2),2) + Math.pow(Math.abs(y1 - y2),2));
}

function randomsign() {
var i = random(0, 1);
if (i == 0) {
return -1;
} else {
return 1;
}

}
function random(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}

function CircleCircleColliding(c1,c2) {
var dist = dist(c1.x , c1.y , c2.x , c2.y);
if (dist < Math.max(c1.r,c2.r)) {
return true;
}
return false;
}

function RectCircleColliding(circle,rect){
var distX = Math.abs(circle.x - rect.x-rect.w/2);
var distY = Math.abs(circle.y - rect.y-rect.h/2);

if (distX > (rect.w/2 + circle.r)) { return false; }
if (distY > (rect.h/2 + circle.r)) { return false; }

if (distX <= (rect.w/2)) { return true; }
if (distY <= (rect.h/2)) { return true; }

var dx=distX-rect.w/2;
var dy=distY-rect.h/2;
return (dx*dx+dy*dy<=(circle.r*circle.r));
}
101 changes: 101 additions & 0 deletions Other versions/0.3/Controls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
var playercontrol;

var mouseX;
var mouseY;

var upPressed = false;
var downPressed = false;
var rightPressed = false;
var leftPressed = false;

var upKey = 38;
var rightKey = 39;
var leftKey = 37;
var downKey = 40;

function setKeyBoardControl(mode) {
if (mode=="wasd") {
playercontrol = keyboardControl;
upKey = 87;
leftKey = 65;
downKey = 83;
rightKey = 68;
} else if (mode=="mouse") {
playercontrol = mouseControl;
mouseX = p.x;
mouseY = p.y;
} else {
playercontrol = keyboardControl;
}

}

function keyboardControl(object, speed) {
if(rightPressed) {
object.x += speed;
}
if(leftPressed) {
object.x -= speed;
}

if(downPressed) {
object.y += speed;
}

if(upPressed) {
object.y -= speed;
}

if (object.x < 0) {
object.x = 0;
} else if (object.x > height) {
object.x = height;
}

if (object.y < 0) {
object.y = 0;
} else if (object.y > width) {
object.y = width;
}
}

function keyDownHandler(e) {
if(e.keyCode == downKey) {
downPressed = true;
}
if(e.keyCode == rightKey) {
rightPressed = true;
}
if(e.keyCode == upKey) {
upPressed = true;
}
else if(e.keyCode == leftKey) {
leftPressed = true;
}
}


function mouseControl(object,speed) {
object.x = mouseX - object.width/2;
object.y = mouseY - object.height/2;
}

function mouseMoveHandler(e) {
mouseX = e.clientX - canvas.offsetLeft;
mouseY = e.clientY - canvas.offsetTop;
}

function keyUpHandler(e) {
if(e.keyCode == downKey) {
downPressed = false;
}
if(e.keyCode == rightKey) {
rightPressed = false;
}
if(e.keyCode == upKey) {
upPressed = false;
}
else if(e.keyCode == leftKey) {
leftPressed = false;
}
}
20 changes: 20 additions & 0 deletions Other versions/0.3/Cookies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//Thanks http://www.w3schools.com/js/js_cookies.asp
function setCookie(c_name,c_value,exdays) {
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
document.cookie=encodeURIComponent(c_name)
+ "=" + encodeURIComponent(c_value)
+ (!exdays ? "" : "; expires="+exdate.toUTCString());
;
}

function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
}
return "";
}
74 changes: 74 additions & 0 deletions Other versions/0.3/GameFlow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
var countervalue = 0;
var score = 0;
function count() {
countervalue++;
if (countervalue > newballtick) {
countervalue = 0;
score++;
return true;
}
return false;
}


var game = true;

function addBall() {
var currentdist = 0;
while (currentdist < mindist) {
startx = random(0, height);
starty = random(0, width);
currentdist = dist(startx, starty, p.x, p.y);
}

vx = random(maxBallspeed / Ballmin, maxBallspeed);
vy = random(maxBallspeed / Ballmin, maxBallspeed);
radius = random(ballRadius / Ballmin, ballRadius);
objects.push(new Ball(startx, starty, vx, vy, radius));
}

function draw() {
if (game) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
p.move();
p.draw(ctx);

for (var int = 0; int < objects.length; int++) {
var object = objects[int];

object.draw(ctx);

object.move();

if (RectCircleColliding(object.shape(), p.shape())) {
endgame();
}

}

if (count()) {
addBall();
}
requestAnimationFrame(draw);
}
}

function endgame() {
game = false;
var highscore = getCookie("ballsballsHighScore");
var again;
if (score > highscore) {
setCookie("ballsballsHighScore",score,100);
again = confirm("game over! \n New HighScore: " + score
+ " ( Previous HighScore: " + highscore
+ " ) \n Wanna Play Again?");
} else {
again = confirm("game over! \n Score: " + score + " ( HighScore: "
+ highscore + " ) \n Wanna Play Again?");
}
if (again) {
document.location.reload();
} else {
document.location.href = "credits";
}
}
71 changes: 71 additions & 0 deletions Other versions/0.3/Initialization.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
var canvas;
var ctx;
var p;
var objects;
var difficulty;
var height;
var width;

window.onload = function () {
console.log("init");

canvas = document.getElementById("myCanvas");
ctx = canvas.getContext("2d");

ctx.canvas.width = window.innerWidth;
ctx.canvas.height = window.innerHeight;

height = canvas.width;
width = canvas.height;

p = new Paddle(height/2, width/2, playerlength, playerlength);

objects = [];

difficulty = 1;

if (getCookie("settings")) {
console.log(getCookie("input"));
setKeyBoardControl(getCookie("input"));

difficulty = getCookie("difficulty");

if (difficulty > 0) {
maxBallspeed = maxBallspeed * (difficulty);
if (difficulty == 4) {
Ballmin = Ballmin * 2;
}

}

var maxX = getCookie("maxX");

if (maxX < height && maxX != 0) {
ctx.canvas.height = maxX;
width = maxX;
}

var maxY = getCookie("maxY");

if (maxY < width && maxY != 0) {
ctx.canvas.width = maxY;
height = maxY;
}

} else {
var setSettings = confirm("Settings not found, want to set them?");
if (setSettings) {
window.location.href = "settings";
} else {
}
}

mindist = dist(0,0,width,height) / mindist;

document.addEventListener("keydown", keyDownHandler, false);
document.addEventListener("keyup", keyUpHandler, false);
document.addEventListener("mousemove", mouseMoveHandler, false);

draw();

}
Loading

0 comments on commit c766324

Please sign in to comment.