Skip to content

Commit

Permalink
Rk/update index (#23)
Browse files Browse the repository at this point in the history
* update index html

* hacky fix for bug

* debug mode :D
  • Loading branch information
rkaufman13 authored Nov 21, 2023
1 parent b748f58 commit cfd396b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
Binary file removed .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions 2048Invaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ const config = {
};

const game = new Phaser.Game(config);
game.debugMode = true;
13 changes: 11 additions & 2 deletions helpermethods.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { TOP_BUFFER, initialValues } from "./constants.js";
import {
LEFT_BUFFER,
RIGHT_BUFFER,
TOP_BUFFER,
initialValues,
} from "./constants.js";

// Helper Methods below:
// sortedEnemies() returns an array of enemy sprites sorted by their x coordinate
Expand Down Expand Up @@ -52,7 +57,11 @@ export const findValidXSlot = (gameState, row) => {
.filter((enemy) => enemy.row == row)
.map((enemy) => enemy.col);
let slot = rollAnNSidedDie(8);
while (filledSlots.includes(slot)) {
while (
filledSlots.includes(slot) ||
(slot - 1) * 50 + sortedEnemies(gameState)[0].x > 450 - RIGHT_BUFFER ||
(slot - 1) * 50 + sortedEnemies(gameState)[0].x < LEFT_BUFFER + 10
) {
slot = rollAnNSidedDie(8);
}
return [(slot - 1) * 50 + sortedEnemies(gameState)[0].x, slot];
Expand Down
9 changes: 4 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
</style>

</head>
<body>
<div style="margin:auto;text-align: center;"><h1>2048 Invaders</h1>
<p>A probably not-winnable game by Rachel Kaufman</p>
<P>Hit matching enemies to create higher powers of 2. Hit the 2048 enemy to win!</P>
<body bgcolor="#000">


<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/phaser.min.js"></script>


<script defer src="2048Invaders.js" type="module"></script>
</div>

</body>
</html>
4 changes: 3 additions & 1 deletion mainGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,9 @@ export default class mainGame extends Phaser.Scene {
});
if (this.healthBar.frame.name < 3) {
hitSelf.play();
this.healthBar.setFrame(this.healthBar.frame.name + 1);
if (!this.sys.game.debugMode) {
this.healthBar.setFrame(this.healthBar.frame.name + 1);
}
} else {
this.healthBar.setFrame(4);
this.player.destroy();
Expand Down

0 comments on commit cfd396b

Please sign in to comment.