Skip to content

Commit

Permalink
reset bomb and user rotation in between levels, add creators in title…
Browse files Browse the repository at this point in the history
…, comment dev button
  • Loading branch information
ajtadeo committed Jun 9, 2024
1 parent f802210 commit be31661
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 22 deletions.
13 changes: 12 additions & 1 deletion components/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ class Map {
this.bomb_queue = []
this.bullet_queue = []
this.user.dead = false;
this.user.angle = - Math.PI / 2;
this.user.body_orientation = Math.PI / 2;

// parse schematic
this.level = level;
Expand Down Expand Up @@ -246,10 +248,19 @@ class Map {
}

clearBulletQueue() {
// clear bullet queue (for in between levels)(
this.bullet_queue.splice(0, this.bullet_queue.length)
}

clearBombQueue() {
this.bomb_queue.splice(0, this.bomb_queue.length);
this.user.bombActive = false;
}

resetUserRotation() {
this.user.angle = - Math.PI / 2;
this.user.body_orientation = Math.PI / 2;
}

render(context, program_state, start_shooting=true) {
const dt = program_state.animation_delta_time / 1000;
// draw background
Expand Down
51 changes: 30 additions & 21 deletions game-scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,21 @@ class GameScene extends Scene {
AUDIO.THEME_MUSIC.play();
}
}, "#6E6460", () => {});
this.new_line();
this.key_triggered_button("Toggle Dev Mode", ["l"], () => {
if (this.startGame) {
if (this.state === GAME_STATE_ENUM.DEV_STATE) {
this.stateStart = this.t;
this.state = GAME_STATE_ENUM.TITLE_STATE;
} else {
this.state = GAME_STATE_ENUM.DEV_STATE;
this.map.initializeLevel(0);
}
this.stopRestartMusic();
AUDIO.THEME_MUSIC.play();
}
// this.new_line();
// this.key_triggered_button("Toggle Dev Mode", ["l"], () => {
// if (this.startGame) {
// if (this.state === GAME_STATE_ENUM.DEV_STATE) {
// this.stateStart = this.t;
// this.state = GAME_STATE_ENUM.TITLE_STATE;
// } else {
// this.state = GAME_STATE_ENUM.DEV_STATE;
// this.map.initializeLevel(0);
// }
// this.stopRestartMusic();
// AUDIO.THEME_MUSIC.play();
// }

}, "#6E6460", () => {});
// }, "#6E6460", () => {});
// this.new_line();
// this.key_triggered_button("Unlimited Bullets", ["u"], () => {
// this.haveUnlimitedBullets = !this.haveUnlimitedBullets;
Expand Down Expand Up @@ -334,9 +334,14 @@ class GameScene extends Scene {
// ** Game Loop **
if (this.startGame) {
if (this.state === GAME_STATE_ENUM.TITLE_STATE) {
let text_transform = Mat4.translation(14, 1.1, 16).times(this.textTransform)
this.shapes.text.set_string("Tanks!", context.context);
let text_transform = Mat4.translation(7, 1.1, 13).times(this.textTransform)
this.shapes.text.set_string("CS174A Tanks!", context.context);
this.shapes.text.draw(context, program_state, text_transform, this.materials.text_image);

let model_transform2 = Mat4.translation(10, 1.2, 17).times(this.subtextTransform)
this.shapes.text.set_string(`Created by AKA`, context.context);
this.shapes.text.draw(context, program_state, model_transform2, this.materials.text_image);

this.shapes.square.draw(context, program_state, this.bannerRedTransform, this.materials.banner_red);
this.displayBackground(context, program_state);

Expand All @@ -351,15 +356,15 @@ class GameScene extends Scene {
AUDIO.LEVEL_START_MUSIC.play();
}
} else if (this.state === GAME_STATE_ENUM.LEVEL_INFO_STATE) {
let model_transform = Mat4.translation(12, 1.1, 12).times(this.textTransform)
let model_transform = Mat4.translation(13, 1.1, 12).times(this.textTransform)
this.shapes.text.set_string(`Level ${this.level}`, context.context);
this.shapes.text.draw(context, program_state, model_transform, this.materials.text_image);

let model_transform2 = Mat4.translation(9, 1.2, 16).times(this.subtextTransform)
let model_transform2 = Mat4.translation(10, 1.2, 16).times(this.subtextTransform)
this.shapes.text.set_string(`Enemy tanks: ${this.map.enemies.length}`, context.context);
this.shapes.text.draw(context, program_state, model_transform2, this.materials.text_image);

let model_transform3 = Mat4.translation(13.5, 1.2, 18.7).times(this.subtextTransform)
let model_transform3 = Mat4.translation(14.5, 1.2, 18.7).times(this.subtextTransform)
this.shapes.text.set_string(`Lives: ${this.lives}`, context.context);
this.shapes.text.draw(context, program_state, model_transform3, this.materials.text_image);

Expand All @@ -368,6 +373,7 @@ class GameScene extends Scene {

if (t - this.stateStart >= LEVEL_INFO_STATE_DURATION) {
console.log(`info for level ${this.level} --> starting level ${this.level}`)
this.map.resetUserRotation();
this.state = GAME_STATE_ENUM.LEVEL_START_STATE;
this.map.state = GAME_STATE_ENUM.LEVEL_START_STATE;
this.stateStart = t;
Expand All @@ -379,6 +385,7 @@ class GameScene extends Scene {
} else if (this.state === GAME_STATE_ENUM.LEVEL_START_STATE) {
this.map.render(context, program_state, false);
this.map.clearBulletQueue();
this.map.clearBombQueue();
this.user.render(context, program_state);
this.renderUserInfo(context, program_state);

Expand Down Expand Up @@ -445,6 +452,7 @@ class GameScene extends Scene {
}
} else if (this.state === GAME_STATE_ENUM.LEVEL_CLEARED_STATE) {
this.map.clearBulletQueue();
this.map.clearBombQueue();
if (t - this.stateStart >= 1000) {
let model_transform = Mat4.translation(5, 4.2, 15).times(this.textTransform)
this.shapes.text.set_string(`Level Cleared!`, context.context);
Expand Down Expand Up @@ -485,6 +493,7 @@ class GameScene extends Scene {
}
} else if (this.state === GAME_STATE_ENUM.LEVEL_FAILED_STATE) {
this.map.clearBulletQueue();
this.map.clearBombQueue();
if (t - this.stateStart >= 500) {
let model_transform = Mat4.translation(5, 4.2, 15).times(this.textTransform)
this.shapes.text.set_string(`Level Failed`, context.context);
Expand Down Expand Up @@ -580,11 +589,11 @@ class GameScene extends Scene {
}
} else {
// pressing a button is required to make audio work in javascript code
let model_transform = Mat4.translation(-3, 1.2, 16).times(this.textTransform)
let model_transform = Mat4.translation(-2, 1.2, 16).times(this.textTransform)
this.shapes.text.set_string(`Click Enter to start`, context.context);
this.shapes.text.draw(context, program_state, model_transform, this.materials.text_image);

this.shapes.square.draw(context, program_state, this.bannerRedTransform, this.materials.banner_red);
this.shapes.square.draw(context, program_state, this.bannerRedTransform, this.materials.banner_green);
this.displayBackground(context, program_state);

// DEV: uncomment the following lines and set initializeLevel(n) in display setup() to test map layouts
Expand Down

0 comments on commit be31661

Please sign in to comment.