Skip to content

Commit

Permalink
Merge pull request #12 from Patrick-W-McMahon/Dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Patrick-W-McMahon committed Aug 5, 2015
2 parents ebe2788 + 36730f6 commit 5c9dec8
Show file tree
Hide file tree
Showing 11 changed files with 534 additions and 0 deletions.
11 changes: 11 additions & 0 deletions JinxEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,17 @@ function GameEngine(){
return gameEngineThis;
}

this.collitionDetection = function(rect1,rect2){
if(typeof(rect1)==="undefined"||typeof(rect2)==="undefined"){
return false;
}else{
if(rect1.x < rect2.x + rect2.width && rect1.x + rect1.width > rect2.x && rect1.y < rect2.y + rect2.height && rect1.height + rect1.y > rect2.y){
return true;
}
}
return false;
}

this.setScene = function(sceneObject){
gameEngineThis.stop();
if(gameEngineThis.activeScene!=undefined){
Expand Down
65 changes: 65 additions & 0 deletions examples/flappyBird/hud.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
function HUD(){
this.gameEngine;
this.playerOneScore=0;
this.mousePos;
this.gameState;
var screenHeight;
var screenWidth;
var screenHeightHalf;
var screenWidthHalf;
var game_over_sign;

this.init = function(e){
this.gameEngine = e;
}

this.update = function(){
this.mousePos = this.gameEngine.getEventInStack("cursor",false);
this.gameState = this.gameEngine.getEventInStack("gameover",false);
screenHeight = this.gameEngine.getDisplayHeight();
screenWidth = this.gameEngine.getDisplayWidth();
screenHeightHalf = screenHeight/2;
screenWidthHalf = screenWidth/2;
game_over_sign={
x:screenWidthHalf-100,
y:screenHeightHalf-40,
width:screenWidthHalf-180,
height:screenHeightHalf-100,
textX:screenWidthHalf-80,
textY:screenHeightHalf,
scoreX:screenWidthHalf-80,
scoreY:screenHeightHalf+40
}
}

this.input = function(keyDown,keyPress,KeyUp){
if(keyDown.indexOf(19)>-1){//pause button
console.log("pause button");
this.gameEngine.addEvent({name:"GameEngine",message:"pause"});
}
}

this.EventLisener = function(e){
var pointEvent = this.gameEngine.getEventInStack("point",true);
if(pointEvent){
if(pointEvent.player==1){
this.playerOneScore++;
}
}
}

this.draw = function(g){
g.fillStyle = "black";
g.font="20px Verdana";
g.fillText("Score: "+this.playerOneScore,10,18);
if(this.gameState){
g.font="32px Verdana";
g.fillStyle = "black";
g.fillRect(game_over_sign.x,game_over_sign.y,game_over_sign.width,game_over_sign.height);
g.fillStyle = "white";
g.fillText("Game Over",game_over_sign.textX,game_over_sign.textY);
g.font="24px Verdana";
g.fillText("Score: "+this.playerOneScore,game_over_sign.scoreX,game_over_sign.scoreY);
}
}
}
31 changes: 31 additions & 0 deletions examples/flappyBird/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<title>Flappy Bird</title>
<link rel="stylesheet" href="style.css">
<script src="../../libs/ObjectiveJS/core.o.js"></script>
<script src="../../libs/ObjectiveJS/math.o.js"></script>
<script src="../../libs/ObjectiveJS/array.o.js"></script>
<script src="../../libs/ObjectiveJS/dom.o.js"></script>
<script src="../../system/Scene.js"></script>
<script src="../../system/Cursor.js"></script>
<script src="../../system/Button.js"></script>
<script src="menuUI.js"></script>
<script src="hud.js"></script>
<script src="wall.js"></script>
<script src="player.js"></script>
<script src="../../JinxEngine.js"></script>
<script src="main.js"></script>
</head>
<body>
<h1>Flappy Bird Example</h1>
<nav>
<button id="newGameButton">New Game</button>
<button id="PauseButton">Pause</button>
<button id="quitButton">Quit</button>
</nav>
<canvas id="screen" height="400" width="800">
<p>your browser will not support canvas, upgrade your browser.</p>
</canvas>
</body>
</html>
29 changes: 29 additions & 0 deletions examples/flappyBird/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var myDom = new DOM();
var myEngine = new GameEngine();
myEngine.engineMode="live";
var gamePaused=0;
myDom.OnReady(function(){
myEngine.setDisplay("screen");
myDom.getId("newGameButton").addEventListener("click", function(){
myEngine.stop();
var mainMenu = new Scene();
var menuUI = mainMenu.addObject(new MenuUI());
var cursor = mainMenu.addObject(new Cursor());
myEngine.setScene(mainMenu);
myEngine.init();
myEngine.start();
}, false);
myDom.getId("PauseButton").addEventListener("click", function(){
if(gamePaused){
myEngine.start();
gamePaused=0;
}else{
myEngine.pause();
gamePaused=1;
}

}, false);
myDom.getId("quitButton").addEventListener("click", function(){
myEngine.stop();
}, false);
});
117 changes: 117 additions & 0 deletions examples/flappyBird/menuUI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
function MenuUI(){
this.gameEngine;
this.levels={
lvl1:{speed:0.2,max:4000,iterate:900,playerSpeed:0.5},
lvl2:{speed:0.45,max:1800,iterate:600,playerSpeed:0.65},
lvl3:{speed:0.7,max:1000,iterate:300,playerSpeed:0.85}
}
this.buttons=[];
var buttonXPos;


this.init = function(e){
this.gameEngine = e;
buttonXPos = (this.gameEngine.getDisplayWidth()/2)-100;

this.buttons.push(new Button({
id:"levelOneButton",
x:buttonXPos,
y:100,
height:50,
width:200,
baseColor:"darkGreen",
hoverColor:"green",
fontColor:"white",
borderColor:"black",
text:"Level One"
}));

this.buttons.push(new Button({
id:"levelTwoButton",
x:buttonXPos,
y:160,
height:50,
width:200,
baseColor:"darkGreen",
hoverColor:"green",
fontColor:"white",
borderColor:"black",
text:"Level Two"
}));

this.buttons.push(new Button({
id:"levelThreeButton",
x:buttonXPos,
y:220,
height:50,
width:200,
baseColor:"darkGreen",
hoverColor:"green",
fontColor:"white",
borderColor:"black",
text:"Level Three"
}));

console.log(this.buttons.length);
for(x=0;x<this.buttons.length;x++){
this.buttons[x].init(e);
}
}

this.update = function(){
for(x=0;x<this.buttons.length;x++){
this.buttons[x].update();
}
var levelSelect = false;
var maxVal;
var iterate;
var speed;
var playerSpeed;

if(this.gameEngine.getEventInStack("levelOneButton",true)){
maxVal = this.levels.lvl1.max;
iterate = this.levels.lvl1.iterate;
speed = this.levels.lvl1.speed;
playerSpeed = this.levels.lvl1.playerSpeed;
levelSelect=true;
}

if(this.gameEngine.getEventInStack("levelTwoButton",true)){
maxVal = this.levels.lvl2.max;
iterate = this.levels.lvl2.iterate;
speed = this.levels.lvl2.speed;
playerSpeed = this.levels.lvl2.playerSpeed;
levelSelect=true;
}

if(this.gameEngine.getEventInStack("levelThreeButton",true)){
maxVal = this.levels.lvl3.max;
iterate = this.levels.lvl3.iterate;
speed = this.levels.lvl3.speed;
playerSpeed = this.levels.lvl3.playerSpeed;
levelSelect=true;
}

if(levelSelect){
var gameScene = new Scene();
for(x=0;x<maxVal;x=x+iterate){
var testwall = gameScene.addObject(new Wall("blue",speed,x));
}
var player = gameScene.addObject(new Player("red","Player",playerSpeed));
var hudId = gameScene.addObject(new HUD());
var cursor = gameScene.addObject(new Cursor("crosshair"));
this.gameEngine.setScene(gameScene);
this.gameEngine.init();
}
}

this.draw = function(g){
g.font="34px Verdana";
g.fillStyle="black";
g.fillText("Flappy Bird Example",buttonXPos-80,60);
for(x=0;x<this.buttons.length;x++){
this.buttons[x].draw(g);
}
}

}
59 changes: 59 additions & 0 deletions examples/flappyBird/player.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
function Player(c,n,s){
this.color=c;
this.score=0;
this.radius=8;
this.name=n;
this.x;
this.y=10;
this.speed=s;
this.gameEngine;
this.upKey;
this.movingUp=false;


this.init = function(e){
this.gameEngine = e;
this.x = this.gameEngine.getDisplay("widthCenter");
this.y = this.gameEngine.getDisplay("heightCenter");
}

this.input = function(keys){
var gameState = this.gameEngine.getEventInStack("gameover",false);
if(gameState==false){
this.upKey=32;
if(keys[this.upKey]){//up key
this.y-=this.speed;
if(this.y<0){
this.y=0;
}
this.movingUp=true;
}else{
this.movingUp=false;
}
}
}

this.update = function(){
var gameState = this.gameEngine.getEventInStack("gameover",false);
if(gameState==false){
if(!this.movingUp){
this.y+=this.speed;
}
if(this.y>this.gameEngine.getDisplayHeight()||this.y<0){
this.gameEngine.addEvent({name:"gameover",score:this.score});//Game Over Trigger
}
this.gameEngine.getEventInStack("player",true);
this.gameEngine.addEvent({name:"player",x:this.x,y:this.y,radius:this.radius});
}
}

this.draw = function(g){
g.fillStyle = this.color;
g.beginPath();
g.arc(this.x,this.y,this.radius,0,2*Math.PI);
g.fill();
g.fillStyle = "black";
g.font="12px Verdana";
g.fillText(""+this.name,this.x-20,this.y-10);
}
};
30 changes: 30 additions & 0 deletions examples/flappyBird/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
html,body{
background:black;
color:white;
width:800px;
padding:0px;
margin:0px auto 0px auto;
}

h1{
position:fixed;
top:0px;
left:0px;
font-size:12p;
padding:0px;
margin:0px;
}

canvas{
background:white;
margin:40px auto 0px auto;
height:400px;
width:800px;
cursor:none;
}

nav{
position:fixed;
top:0px;
right:0px;
}
Loading

0 comments on commit 5c9dec8

Please sign in to comment.