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
var express = require('express'); | |
var app = express(); | |
var path = require('path'); | |
app.use(express.static(path.join(__dirname, 'public'))); | |
app.get('/', function(req, res) { | |
res.send('Hello home page'); | |
}); | |
app.get('/route', function(req, res) { | |
res.send('Hello Router, <img src="/image.jpg" style="width:500px; height:500px;">'); |
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
var express = require('express'); | |
var app = express(); | |
app.use(express.static('public')); | |
app.get('/', function(req, res) { | |
res.send('Hello home page');; | |
}); | |
app.get('/route', function(req, res) { | |
res.send('Hello Router, <img src="/route.png">') | |
}) | |
app.get('/login', function(req, res) { |
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
var express = require('express'); | |
var app = express(); | |
app.get('/', function(req, res) { | |
res.send('Hello Main Page'); | |
}); | |
app.get('/login', function(req, res) { | |
res.send('Login Please'); | |
}); |
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
const http = require('http'); | |
const hostname = '127.0.0.1'; | |
const port = 3000; | |
http.createServer((req, res) => { | |
res.writeHead(200, { | |
'Content-Type': 'text/plain' | |
}); | |
res.end('Hello World\n'); |
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
// Check Collision | |
var checkCollision = function(anEnemy) { | |
// check for collision between enemy and player | |
if ( | |
player.y + 131 >= anEnemy.y + 90 && | |
player.x + 25 <= anEnemy.x + 88 && | |
player.y + 73 <= anEnemy.y + 135 && | |
player.x + 76 >= anEnemy.x + 11) { | |
console.log('collided'); | |
// Position player after Collision |
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
Enemy_Rock.prototype.update = function(dt) { | |
this.x += this.speed * dt; | |
if (this.x >= 505) { | |
this.x = 0; | |
} | |
checkCollision(this); | |
checkWin(this); | |
}; |
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
// Enemies our player must avoid | |
var Enemy = function(x, y, speed) { | |
this.x = x; | |
this.y = y; | |
this.speed = speed; | |
// The sprite continuously crops and displays the image. | |
this.sprite = 'images/enemy-bug.png'; | |
}; | |
var Enemy_Rock = function(x, y, speed) { |
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
// This listens for key presses and sends the keys to your | |
// Player.handleInput() method. You don't need to modify this. | |
document.addEventListener('keyup', function(e) { | |
var allowedKeys = { | |
37: 'left', | |
38: 'up', | |
39: 'right', | |
40: 'down' | |
}; |
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
// Initial setting | |
var allEnemies = []; | |
var player = new Player(202.5, 383, 100); | |
var score = 0; | |
var gameLevel = 1; | |
var scoreLevelDiv = document.createElement('div'); | |
var enemy = new Enemy(0, Math.random() * 184 + 50, Math.random() * 256); | |
var enemy_rock = new Enemy_Rock(0, Math.random() * 184 + 50, Math.random() * 256); | |
allEnemies.push(enemy, enemy_rock); |
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
// Check Collision | |
var checkCollision = function(anEnemy) { | |
// check for collision between enemy and player | |
if ( | |
player.y + 131 >= anEnemy.y + 90 && | |
player.x + 25 <= anEnemy.x + 88 && | |
player.y + 73 <= anEnemy.y + 135 && | |
player.x + 76 >= anEnemy.x + 11) { | |
console.log('collided'); | |
// Position player after Collision |