first commit

This commit is contained in:
jpez 2022-04-28 16:49:09 +01:00
commit 98aa53685a
76 changed files with 17360 additions and 0 deletions

13100
game.css Normal file

File diff suppressed because it is too large Load Diff

46
game.html Normal file
View File

@ -0,0 +1,46 @@
<!DOCTYPE html>
<html>
<head>
<title>Assignment 2</title>
<link rel="stylesheet" href="game.css" />
<script src="scripts/launch.js"></script>
<script src="scripts/control.js"></script>
</head>
<body>
<div class="hud">
<ul class="health">
<li></li>
<li></li>
<li></li>
</ul>
</div>
<div class="start" id="start">
Start
</div>
<div class="sky">
</div>
<div id="player" class="character stand down">
<div class="head">
</div>
<div class="body">
</div>
<div class="weapon bow">
</div>
</div>
</div>
<div class="alien" id="alien">
</body>
</html>

110
game.js Normal file
View File

@ -0,0 +1,110 @@
var upPressed = false;
var downPressed = false;
var leftPressed = false;
var rightPressed = false;
var lastPressed = false;
function keyup(event) {
var player = document.getElementById('player');
if (event.keyCode == 37) {
leftPressed = false;
lastPressed = 'left';
}
if (event.keyCode == 39) {
rightPressed = false;
lastPressed = 'right';
}
if (event.keyCode == 38) {
upPressed = false;
lastPressed = 'up';
}
if (event.keyCode == 40) {
downPressed = false;
lastPressed = 'down';
}
player.className = 'character stand ' + lastPressed;
}
function move() {
var player = document.getElementById('player');
var positionLeft = player.offsetLeft;
var positionTop = player.offsetTop;
if (downPressed) {
var newTop = positionTop+1;
var element = document.elementFromPoint(player.offsetLeft, newTop+32);
if (element.classList.contains('sky') == false) {
player.style.top = newTop + 'px';
}
if (leftPressed == false) {
if (rightPressed == false) {
player.className = 'character walk down';
}
}
}
if (upPressed) {
var newTop = positionTop-1;
var element = document.elementFromPoint(player.offsetLeft, newTop);
if (element.classList.contains('sky') == false) {
player.style.top = newTop + 'px';
}
if (leftPressed == false) {
if (rightPressed == false) {
player.className = 'character walk up';
}
}
}
if (leftPressed) {
var newLeft = positionLeft-1;
var element = document.elementFromPoint(newLeft, player.offsetTop);
if (element.classList.contains('sky') == false) {
player.style.left = newLeft + 'px';
}
player.className = 'character walk left';
}
if (rightPressed) {
var newLeft = positionLeft+1;
var element = document.elementFromPoint(newLeft+32, player.offsetTop);
if (element.classList.contains('sky') == false) {
player.style.left = newLeft + 'px';
}
player.className = 'character walk right';
}
}
function keydown(event) {
if (event.keyCode == 37) {
leftPressed = true;
}
if (event.keyCode == 39) {
rightPressed = true;
}
if (event.keyCode == 38) {
upPressed = true;
}
if (event.keyCode == 40) {
downPressed = true;
}
}
function myLoadFunction() {
timeout = setInterval(move, 10);
document.addEventListener('keydown', keydown);
document.addEventListener('keyup', keyup);
}
document.addEventListener('DOMContentLoaded', myLoadFunction);

BIN
images/alien.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

BIN
images/arrowsbox.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 522 B

BIN
images/baddyblue.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

BIN
images/baddydragon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
images/baddygold.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
images/baddygray.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

BIN
images/baddyhare.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 B

BIN
images/baddylizardon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
images/baddyninja.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
images/baddyoctopus.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
images/baddyred.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

BIN
images/baddytest.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
images/bcalarmclock.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
images/bg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 960 B

BIN
images/block.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 916 B

BIN
images/bluelampani.mng Normal file

Binary file not shown.

BIN
images/bluelampani2.mng Normal file

Binary file not shown.

BIN
images/blueletters.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
images/body0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

BIN
images/body1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
images/body2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
images/body3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

BIN
images/body4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

BIN
images/bomb1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
images/bomb2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

BIN
images/brother1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 568 B

BIN
images/brother2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 560 B

BIN
images/chest.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 300 B

BIN
images/chestopen.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 B

BIN
images/door.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 345 B

BIN
images/door1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 B

4001
images/editor.html Normal file

File diff suppressed because it is too large Load Diff

BIN
images/gate1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
images/gate2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
images/head0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
images/head1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
images/head2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

BIN
images/head3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

BIN
images/head4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
images/horse1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

BIN
images/horse2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

BIN
images/horse3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

BIN
images/horse4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

BIN
images/khairs0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

BIN
images/klegs0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
images/kmarms100.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
images/lamps_wood.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
images/letters.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
images/light2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
images/nightSky.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 941 B

BIN
images/opps.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

BIN
images/plisticonaway.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 228 B

BIN
images/plisticondnd.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 B

BIN
images/plisticononline.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 B

BIN
images/ride.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

BIN
images/ride2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

BIN
images/ride3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

BIN
images/sprites.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

BIN
images/state.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

BIN
images/sword0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
images/sword1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
images/sword2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
images/testhorse.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
images/tiles.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 KiB

BIN
images/tree.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

BIN
images/treetop.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

1
scripts/agent.js Normal file
View File

@ -0,0 +1 @@
/* logic for enemy movement and firing */

85
scripts/control.js Normal file
View File

@ -0,0 +1,85 @@
/* player movement logic */
function setVars() {
let player = document.getElementById("player");
}
document.onloadend = setVars;
function verticalMovement(keyCode) {
var playerLeft = player.offsetLeft;
var playerTop = player.offsetTop;
switch(keyCode) {
case 38: /*Up*/
case 87: /*W*/
var element = document.elementFromPoint(playerLeft, playerTop-10);
if (element.classList.contains("sky") == false) { /*change to only trigger when not grass*/
player.style.top = (playerTop - 10) + "px";
}
player.className = "character walk up";
console.log("Up");
break;
case 40: /*Down*/
case 83: /*S*/
var element = document.elementFromPoint(playerLeft, playerTop+10);
if (element.classList.contains("sky") == false) {
player.style.top = (playerTop + 10) + "px";
}
player.className = "character walk down";
console.log("Down");
break;
}
}
function horizontalMovement(keyCode) {
var playerLeft = player.offsetLeft;
var playerTop = player.offsetTop;
switch(keyCode) {
case 37: /*Left*/
case 65: /*A*/
var element = document.elementFromPoint(playerLeft-10, playerTop);
if (element.classList.contains("sky") == false) {
player.style.left = (playerLeft - 10) + "px";
}
player.className = "character walk left";
console.log("Left");
break;
case 39: /*Right*/
case 68: /*D*/
var element = document.elementFromPoint(playerLeft+10, playerTop);
if (element.classList.contains("sky") == false) {
player.style.left = (playerLeft + 10) + "px";
}
player.className = "character walk right";
console.log("Right");
break;
}
}
function move(event) {
verticalMovement(event.keyCode);
horizontalMovement(event.keyCode);
}
function stop(event) {
switch(event.keyCode) {
case 38: /*Up*/
case 87: /*W*/
player.className = "character stand up";
break;
case 40: /*Down*/
case 83: /*S*/
player.className = "character stand down";
break;
case 37: /*Left*/
case 65: /*A*/
player.className = "character stand left";
break;
case 39: /*Right*/
case 68: /*D*/
player.className = "character stand right";
break;
}
}

1
scripts/enemy.js Normal file
View File

@ -0,0 +1 @@
/* enemy spawning logic */

13
scripts/launch.js Normal file
View File

@ -0,0 +1,13 @@
/*Add events to webpage*/
function loadScripts() {
document.addEventListener("keydown", move)
document.addEventListener("keyup", stop)
document.getElementById("start").addEventListener("click", startGame)
}
function startGame() {
var button = document.getElementById("start");
button.style.display = "none";
}
document.addEventListener("DOMContentLoaded", loadScripts);

1
scripts/player.js Normal file
View File

@ -0,0 +1 @@
/*Logic for player lives and firing ability */

1
scripts/projectile.js Normal file
View File

@ -0,0 +1 @@
/* logic for bombs */

1
scripts/score.js Normal file
View File

@ -0,0 +1 @@
/* score tracking and scoreboard logic */