Skip to content

Commit 6e96cee

Browse files
.
1 parent 25363cd commit 6e96cee

28 files changed

+751
-706
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules

.idea/codestream.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/github.png

22.7 KB
Loading

index.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,9 @@ <h1 class="title">A Steampunk Game</h1>
5353

5454
<div class="buttons">
5555
<button class="button" onclick="window.open('https://github.com/FleetAdmiralJakob/Steampunk-Game/wiki')">Steampunk Wiki</button>
56-
<button class="button" onclick="window.open('https://github.com/FleetAdmiralJakob/Steampunk-Game')">View Code on GitHub</button>
56+
<button class="button" onclick="window.open('https://github.com/FleetAdmiralJakob/Steampunk-Game')">View Code on GitHub <img alt="github icon" src="assets/github.png"/></button>
5757
</div>
5858

59-
<script src="javascripts/game.js"></script>
60-
<script src="javascripts/environment.js"></script>
59+
<script type="module" src="javascripts/main.js"></script>
6160
</body>
6261
</html>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {Layer} from "./layer.js";
2+
3+
export class Background {
4+
constructor (game) {
5+
this.game = game
6+
7+
this.image1 = document.getElementById('layer1')
8+
this.image2 = document.getElementById('layer2')
9+
this.image3 = document.getElementById('layer3')
10+
this.image4 = document.getElementById('layer4')
11+
12+
this.layer1 = new Layer(this.game, this.image1, 0.2)
13+
this.layer2 = new Layer(this.game, this.image2, 0.4)
14+
this.layer3 = new Layer(this.game, this.image3, 1)
15+
this.layer4 = new Layer(this.game, this.image4, 1.3)
16+
17+
this.layers = [this.layer1, this.layer2, this.layer3]
18+
}
19+
20+
update () {
21+
this.layers.forEach(layer => layer.update())
22+
}
23+
24+
draw (context) {
25+
this.layers.forEach(layer => layer.draw(context))
26+
}
27+
}

javascripts/components/enemy.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
export class Enemy {
2+
constructor (game) {
3+
this.game = game
4+
this.x = this.game.width
5+
this.speedX = Math.random() * -1.5 - 0.5
6+
this.markedForDeletion = false
7+
this.frameX = 0
8+
this.frameY = 0
9+
this.maxFrame = 37
10+
}
11+
12+
update () {
13+
this.x += this.speedX - this.game.speed
14+
if (this.x + this.width < 0) this.markedForDeletion = true
15+
// Sprite animations
16+
if (this.frameX < this.maxFrame) {
17+
this.frameX++
18+
} else this.frameX = 0
19+
}
20+
21+
draw (context) {
22+
if (this.game.debug) context.strokeRect(this.x, this.y, this.width, this.height)
23+
context.drawImage(this.image, this.frameX * this.width, this.frameY * this.height, this.width, this.height, this.x, this.y, this.width, this.height)
24+
if (this.game.debug) {
25+
context.font = '20px Helvetica'
26+
context.fillText(this.lives, this.x, this.y)
27+
}
28+
}
29+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
export class Explosion {
2+
constructor (game, x, y) {
3+
this.game = game
4+
this.frameX = 0
5+
this.spriteWidth = 200
6+
this.spriteHeight = 200
7+
8+
this.width = this.spriteWidth
9+
this.height = this.spriteHeight
10+
this.x = x - this.width * 0.5
11+
this.y = y - this.height * 0.5
12+
13+
this.fps = 30
14+
this.timer = 0
15+
this.interval = 1000 / this.fps
16+
this.markedForDeletion = false
17+
this.maxFrame = 8
18+
}
19+
20+
update (deltaTime) {
21+
this.x -= this.game.speed
22+
if (this.timer > this.interval) {
23+
this.frameX++
24+
this.timer = 0
25+
} else {
26+
this.timer += deltaTime
27+
}
28+
this.frameX++
29+
if (this.frameX > this.maxFrame) this.markedForDeletion = true
30+
}
31+
32+
draw (context) {
33+
context.drawImage(this.image, this.frameX * this.spriteWidth, 0, this.spriteWidth, this.spriteHeight, this.x, this.y, this.width, this.height)
34+
}
35+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {Enemy} from "../../enemy.js";
2+
3+
export class Angler1 extends Enemy {
4+
constructor (game) {
5+
super(game)
6+
this.width = 228
7+
this.height = 169
8+
this.y = Math.random() * (this.game.height * 0.95 - this.height)
9+
this.image = document.getElementById('angler1')
10+
this.frameY = Math.floor(Math.random() * 3)
11+
this.lives = 5
12+
this.score = this.lives
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {Enemy} from "../../enemy.js";
2+
3+
export class Angler2 extends Enemy {
4+
constructor (game) {
5+
super(game)
6+
this.width = 213
7+
this.height = 165
8+
this.y = Math.random() * (this.game.height * 0.95 - this.height)
9+
this.image = document.getElementById('angler2')
10+
this.frameY = Math.floor(Math.random() * 2)
11+
this.lives = 6
12+
this.score = this.lives
13+
}
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {Enemy} from "../../enemy.js";
2+
3+
export class BulbWhale extends Enemy {
4+
constructor (game) {
5+
super(game)
6+
this.width = 270
7+
this.height = 219
8+
this.y = Math.random() * (this.game.height * 0.95 - this.height)
9+
this.image = document.getElementById('bulb-whale')
10+
this.frameY = Math.floor(Math.random() * 2)
11+
this.lives = 20
12+
this.score = this.lives
13+
this.speedX = Math.random() * -1.2 - 0.2
14+
}
15+
}

0 commit comments

Comments
 (0)