Skip to content

Commit

Permalink
made alot of changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fauwara committed Sep 25, 2021
1 parent 4c873a9 commit 5265e74
Show file tree
Hide file tree
Showing 26 changed files with 3,217 additions and 103 deletions.
9 changes: 9 additions & 0 deletions backend/lb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var express = require('express');
var router = express.Router();

// define the home page route
router.get('/', function (req, res) {
res.send('');
});

module.exports = router;
16 changes: 16 additions & 0 deletions backend/model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const mongoose = require('mongoose');
const schema = mongoose.Schema;

const scoreSchema = new schema({
name: {
type: String,
required: true,
},
score: {
type: Number,
required: true,
}
});

const score = mongoose.model('score', scoreSchema);
module.exports = score;
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added game/assets/gleaderboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added game/assets/htplay.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added game/assets/play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added game/assets/samurai.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added game/assets/title.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions game/assets/user-input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<style>
#user-id {
background-color: black;
border: solid 5px #1e1f1e;
padding: 0px 10px;
color: white;
}

::placeholder { /* Chrome, Firefox, Opera, Safari 10.1+ */
color: #1e1f1e;
opacity: 1; /* Firefox */
}

:-ms-input-placeholder { /* Internet Explorer 10-11 */
color: #1e1f1e;
}

::-ms-input-placeholder { /* Microsoft Edge */
color: #1e1f1e;
}
</style>
<input id="user-id" class="nameField" type="text" name="user-id" placeholder="enter your nick" style="font-size: 32px">
3 changes: 2 additions & 1 deletion src/css/game.css → game/css/game.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ body{
justify-content: center;
align-items: center;
height: 100vh;
background: rgb(27, 27, 27);
background: black;
}

canvas {
align-items: center;
margin: auto;
border: solid 5px #1e1f1e;
}
74 changes: 74 additions & 0 deletions game/js/bootGame.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
class bootGame extends Phaser.Scene {
constructor() {
super("bootGame");
}

preload() {
// html to get user input
// this.load.html('nameform', 'game/assets/user-input.html');
//images
// main menu images
this.load.image("title", "game/assets/title.png");
this.load.image("play", "game/assets/play.png");
this.load.image("htplay", "game/assets/htplay.png");
this.load.image("trophy", "game/assets/gleaderboard.png");
// game images
this.load.image("bg", "game/assets/bg.png");
this.load.image("player", "game/assets/samurai.png");
//sprites
this.load.spritesheet("ghost", "game/assets/ghost-sprite.png", {
//ghosts
frameWidth: 75,
frameHeight: 75,
});
this.load.spritesheet("candy", "game/assets/candy-sprite.png", {
// candy
frameWidth: 22,
frameHeight: 22,
});

// audio
// this.load.audio("roblox-death-audio", "src/assets/roblox-death.mp3"); // "src/assets/roblox-death.ogg",
}

create() {

///////////////////////////////////////// create animations
////////////// main menu animations
// play button
this.anims.create({
key: "play",
frames: this.anims.generateFrameNumbers("play", {
start: 0,
end: 1,
}),
frameRate: 5,
repeat: -1,
});

// this.add.text(20, 20, "Loading Game...");
this.anims.create({
key: "candy_beam",
frames: this.anims.generateFrameNumbers("candy", {
start: 0,
end: 1,
}),
frameRate: 5,
repeat: -1,
});
// ghost walk animation
this.anims.create({
key: "ghost_walk",
frames: this.anims.generateFrameNumbers("ghost", {
start: 0,
end: 1,
}),
frameRate: 5,
repeat: -1,
});

// this.deathSound = this.sound.add("roblox-death-audio");

this.scene.start("mainMenu");
}
}
File renamed without changes.
44 changes: 22 additions & 22 deletions src/js/mainMenu.js → game/js/endScene.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
class mainMenu extends Phaser.Scene {
constructor() {
super("mainMenu");
}

create() {
this.add.text(20, 20, "Loading Game...");
// let playButton = this.physics.add.image(config.width/2, config.height/2, "player");

let playButton = this.add.rectangle(config.width/2, config.height/2, 250, 75, 0x2ECC71);
// console.log(getCenter(playButton));
// playButton.setStrokeStyle(3, 0x2ECC71);
console.log(playButton.x);

this.add.text(playButton.x - playButton.width/4, playButton.y - playButton.height/4, "PLAY GAME");

playButton.setInteractive();

playButton.on('pointerdown', () => {
this.scene.start("mainGame");
});
}
class endScene extends Phaser.Scene {
constructor() {
super("endScene");
}

create() {
this.add.text(20, 20, "Game Over ahahahhaha NOOOB");
// let playButton = this.physics.add.image(config.width/2, config.height/2, "player");

let playButton = this.add.rectangle(config.width/2, config.height/2, 250, 75, 0x2ECC71);
// console.log(getCenter(playButton));
// playButton.setStrokeStyle(3, 0x2ECC71);
console.log(playButton.x);

this.add.text(playButton.x - playButton.width/4, playButton.y - playButton.height/4, "PLAY AGAIN");

playButton.setInteractive();

playButton.on('pointerdown', () => {
this.scene.start("mainGame");
});
}
}
10 changes: 8 additions & 2 deletions src/js/game.js → game/js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ var config = {
type: Phaser.AUTO,
width: 1200,
height: 675,
scene: [bootGame, mainMenu, mainGame],
scene: [bootGame, mainMenu, mainGame, endScene],
pixelArt: true,
dom: {
createContainer: true
},
parent: 'user-id',
physics: {
default: "arcade",
arcade: {
Expand All @@ -16,7 +20,9 @@ var player; //player
var playerSpeed = 200;
var distance;
var target = new Phaser.Math.Vector2();

var candyTarget = new Phaser.Math.Vector2();

// actually need these ig
// var userId;

var game = new Phaser.Game(config);
26 changes: 17 additions & 9 deletions src/js/mainGame.js → game/js/mainGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ class mainGame extends Phaser.Scene {
super("mainGame");
}

init(data) {
this.user = data;
}

create() {

// console.log(this);
// add images
this.bg = this.add.image(0, 0, "bg");
this.bg.setOrigin(0, 0);
// this.add.text(200,200, this.user.name);
// this.add.text(200,300, this.user.score);

player = this.physics.add.image(config.width/2, config.height/2, "player");
// this.input.on(
Expand Down Expand Up @@ -63,9 +70,9 @@ class mainGame extends Phaser.Scene {
// colliders

this.health = 5;
this.score = 0;
this.user.score = 0;
// set text to screen
this.scoreLabel = this.add.text(10, 10, `SCORE ${this.score}`, { font: '30px Courier', fill: '#00ff00' });
this.scoreLabel = this.add.text(10, 10, `SCORE ${this.user.score}`, { font: '30px Courier', fill: '#00ff00' });
this.healthLabel = this.add.text(10, 40, `HEALTH ${this.health}`, { font: '30px Courier', fill: '#00ff00' });

// this.physics.add.collider(player, this.ghosts, hurt);
Expand All @@ -75,10 +82,11 @@ class mainGame extends Phaser.Scene {
update() {

if(!this.health){
if(alert(`NOOB XD, MY GRANDMOM COULD SCORE MORE THAN ${this.score}`)){}
else{
window.location.reload();
}
// if(alert(`NOOB XD, MY GRANDMOM COULD SCORE MORE THAN ${this.score}`)){}
// else{
// window.location.reload();
// }
this.scene.start("endScene");
}

this.ghostFlip();
Expand All @@ -87,16 +95,16 @@ class mainGame extends Phaser.Scene {
}

incScore() {
this.score += 15;
this.scoreLabel.text = "SCORE " + this.score;

this.user.score += 15;
this.scoreLabel.text = "SCORE " + this.user.score;
}

playerMove(){

player.setVelocityX(0);
player.setVelocityY(0);

// player movement
if(this.cursorKeys.left.isDown){
player.setVelocityX(-playerSpeed);
}else if(this.cursorKeys.right.isDown){
Expand Down
66 changes: 66 additions & 0 deletions game/js/mainMenu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
class mainMenu extends Phaser.Scene {
constructor() {
super("mainMenu");
}

preload() {
this.load.html('nameform', 'game/assets/user-input.html');
}

create() {
// this.add.text(20, 20, "Loading Game...");
// let playButton = this.physics.add.image(config.width/2, config.height/2, "player");

// game title
this.add.image(600, 200, 'title');

// user input
var element = this.add.dom(600, 330).createFromCache('nameform');

let htplay = this.add.image(400, 430, 'htplay').setInteractive();
let play = this.add.image(600, 430, 'play').setInteractive();
let leaderboard = this.add.image(800, 430, 'trophy').setInteractive();

play.on('pointerdown', () => {
var userId = element.getChildByName('user-id');
this.scene.start("mainGame", {name: userId.value, score: 0});
});

// element.setPerspective(800);
// element.addListener('click');

// element.on('click', function (event) {

// if (event.target.name === 'playButton')
// {
// var inputText = this.getChildByName('nameField');

// // Have they entered anything?
// if (inputText.value !== '')
// {
// // Turn off the click events
// this.removeListener('click');

// // Hide the login element
// this.setVisible(false);

// // Populate the text with whatever they typed in
// text.setText('Welcome ' + inputText.value);
// }
// else
// {
// // Flash the prompt
// this.scene.tweens.add({
// targets: text,
// alpha: 0.2,
// duration: 250,
// ease: 'Power3',
// yoyo: true
// });
// }
// }

// });

}
}
File renamed without changes.
15 changes: 8 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
<head>
<meta charset="UTF-8" />
<title>NOOB GAME</title>
<script type="text/javascript" src="./src/phaser.min.js"></script>
<link rel="stylesheet" href="./src/css/game.css" />
<script type="text/javascript" src="./game/phaser.min.js"></script>
<link rel="stylesheet" href="./game/css/game.css" />

<script type="text/javascript" src="./src/js/bootGame.js"></script>
<script type="text/javascript" src="./src/js/mainMenu.js"></script>
<script type="text/javascript" src="./src/js/mainGame.js"></script>
<script type="text/javascript" src="./game/js/bootGame.js"></script>
<script type="text/javascript" src="./game/js/mainMenu.js"></script>
<script type="text/javascript" src="./game/js/mainGame.js"></script>
<script type="text/javascript" src="./game/js/endScene.js"></script>

<script type="text/javascript" src="./src/js/game.js"></script>
<script type="text/javascript" src="./src/js/console-messages.js"></script>
<script type="text/javascript" src="./game/js/game.js"></script>
<script type="text/javascript" src="./game/js/console-messages.js"></script>
</head>

<body>
Expand Down
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ const express = require('express');
const app = express();
const PORT = 5000;

app.use('/src', express.static(__dirname + '/src'));
// route
const lb = require('./backend/lb');
app.use('/lb', lb);

app.use('/game', express.static(__dirname + '/game'));

// MAIN GAME
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html', (err) = {
if(err) {
Expand Down
Loading

0 comments on commit 5265e74

Please sign in to comment.