Added letter selector thats still broken
This commit is contained in:
44
web/game.js
44
web/game.js
@@ -3,6 +3,12 @@
|
|||||||
const width = 1260;
|
const width = 1260;
|
||||||
const height = 620;
|
const height = 620;
|
||||||
|
|
||||||
|
// Menu variables
|
||||||
|
let letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
|
||||||
|
let currentIndex = 0;
|
||||||
|
let name = '';
|
||||||
|
let pressed = false;
|
||||||
|
|
||||||
// Player variables
|
// Player variables
|
||||||
const playerSize = 10;
|
const playerSize = 10;
|
||||||
let radius = playerSize / 2;
|
let radius = playerSize / 2;
|
||||||
@@ -11,7 +17,7 @@ let playerPosY = 300;
|
|||||||
let playerSpeed = 4;
|
let playerSpeed = 4;
|
||||||
let booleanArray = window.booleanArray;
|
let booleanArray = window.booleanArray;
|
||||||
let lives = 1;
|
let lives = 1;
|
||||||
|
let isDead = false;
|
||||||
let bossPosX = width / 2;
|
let bossPosX = width / 2;
|
||||||
let bossPosY = 100;
|
let bossPosY = 100;
|
||||||
let shotSpeed = 12;
|
let shotSpeed = 12;
|
||||||
@@ -67,15 +73,22 @@ function score() {
|
|||||||
time += 3 / framerate;
|
time += 3 / framerate;
|
||||||
}
|
}
|
||||||
|
|
||||||
function life() {
|
function gameOver() {
|
||||||
textAlign(CENTER);
|
|
||||||
if (lives == 0) {
|
if (lives == 0) {
|
||||||
|
isDead = true;
|
||||||
push();
|
push();
|
||||||
fill(255, 0, 0);
|
fill(255, 0, 0);
|
||||||
textSize(40);
|
textSize(40);
|
||||||
textAlign(CENTER);
|
textAlign(CENTER);
|
||||||
text("Game Over", width / 2, height / 2);
|
text("Game Over", width / 2, height / 2 - 80);
|
||||||
pop();
|
pop();
|
||||||
|
push();
|
||||||
|
fill(255,255,255)
|
||||||
|
textSize(32);
|
||||||
|
text(letters[currentIndex], width / 2, height / 2);
|
||||||
|
pop();
|
||||||
|
|
||||||
if (key == ' ') {
|
if (key == ' ') {
|
||||||
lives = 1;
|
lives = 1;
|
||||||
time = 0;
|
time = 0;
|
||||||
@@ -98,7 +111,12 @@ function movementCheck() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function keyDown() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
async function keyPressed() {
|
async function keyPressed() {
|
||||||
|
if (!isDead) {
|
||||||
if (keyIsDown(LEFT_ARROW) && playerPosX > 0 + radius) {
|
if (keyIsDown(LEFT_ARROW) && playerPosX > 0 + radius) {
|
||||||
playerPosX -= playerSpeed;
|
playerPosX -= playerSpeed;
|
||||||
}
|
}
|
||||||
@@ -112,6 +130,21 @@ async function keyPressed() {
|
|||||||
playerPosY += playerSpeed;
|
playerPosY += playerSpeed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (isDead) {
|
||||||
|
if (keyCode === UP_ARROW) {
|
||||||
|
currentIndex = (currentIndex + 1) % letters.length;
|
||||||
|
}
|
||||||
|
if (keyCode === DOWN_ARROW) {
|
||||||
|
currentIndex = (currentIndex - 1 + letters.length) % letters.length;
|
||||||
|
}
|
||||||
|
if (keyCode === ENTER) {
|
||||||
|
name += letters[currentIndex];
|
||||||
|
console.log(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function wait(waitTime) {
|
function wait(waitTime) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -144,7 +177,7 @@ async function Movementloop() {
|
|||||||
// the function draw() is called every frame
|
// the function draw() is called every frame
|
||||||
function draw() {
|
function draw() {
|
||||||
keyPressed();
|
keyPressed();
|
||||||
life();
|
gameOver();
|
||||||
phase();
|
phase();
|
||||||
// draw background
|
// draw background
|
||||||
//myBullet.draw();
|
//myBullet.draw();
|
||||||
@@ -156,6 +189,7 @@ function draw() {
|
|||||||
if (homescreenOn == false) {
|
if (homescreenOn == false) {
|
||||||
game();
|
game();
|
||||||
}
|
}
|
||||||
|
keyDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function randPatern() {
|
async function randPatern() {
|
||||||
|
Reference in New Issue
Block a user