Giter Site home page Giter Site logo

shenshuu / froggy-bash Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 25.76 MB

Froggy Bash is a game I created that is inspired by Bubble Trouble. In order to win, the player must wipe out all the frogs on the map before the timer ends without getting hit. Upon winning the game, the player will have a choice to make the game "spicy" by randomly spawning frogs of random sizes every 7 seconds with a 60% probability.

Home Page: https://shenshuu.github.io/Froggy-Bash/

HTML 14.40% JavaScript 73.78% SCSS 11.83%

froggy-bash's Introduction

Froggy-Bash

Background

Bubble Trouble is a 2D shooter that was first introduced in the formerly popular flash games website, Miniclip.com. The rules of Bubble Trouble are quite simple. There are multiple levels in the game, each with a timer and a fixed number of bubbles. During gameplay, the bubbles in each level bounce around the room and split into two smaller bubbles if the player manages to attack them. The bubbles then eventually disapear when they get small enough.

Froggy Bash is a game I created that is inspired by Bubble Trouble. In order to win, the player must wipe out all the frogs on the map before the timer ends without getting hit. Upon winning the game, the player will have a choice to make the game "spicy" by randomly spawning frogs of random sizes every 7 seconds with a 60% probability.

Alt Text

Functionality & MVPs

With Froggy Bash, users will be able to:

  • Move left and right with character
  • Collide with other game entities
  • Play and pause game music
  • Shoot projectiles
  • Interact with frogs by shooting them

Code Snippets

To handle the enemy multiplication algorithm, I devised a splitting algorithm where two new enemies get pushed into an array that stores all the enemies still alive in the current game state. The size of the new enemies are then determined by multiplying the destroyed enemy's size by a constanct factor c where c = 1 / 1.5.

split() {
        if (this.radius >= 5) {
            let e1 = new Enemy({
                position: {
                    x: this.position.x - 25,
                    y: this.position.y
                },
                velocity: {
                    x: this.velocity.x - 0.25,
                    y: this.velocity.y - 0.25
                },
                radius: this.radius / 1.5,
                ctx: this.ctx,
                sprites: this.sprites,
                canvas: this.canvas,
            })
            let e2 = new Enemy({
                position: {
                    x: this.position.x + 25,
                    y: this.position.y
                },
                velocity: {
                    x: -(this.velocity.x + 0.25),
                    y: this.velocity.y - 0.25
                },
                radius: this.radius / 1.5,
                ctx: this.ctx,
                sprites: this.sprites,
                canvas: this.canvas,
            })
            this.children.push(...[e1, e2]);
}

To check for projectile collision, I calculated and checked if the hit boxes for both the projectile and enemy were within a specific threshold. This simple function allowed for the core game functionality to be possible.

collided(enemy) {
        if (enemy.position.x - enemy.radius <= this.position.x + this.width &&
            this.position.x <= enemy.position.x + enemy.radius &&
            enemy.position.y + enemy.radius <= this.position.y + this.height &&
            this.position.y <= enemy.position.y + enemy.radius) {
            this.hit = true;
            return true;
        } else {
            return false;
        }
}

One of the biggest challenges of this project was coming up with a way to allow the user to have exactly one projectile in the game state at a time. Through the use of null checks, I was able to incorporate the Singleton pattern for projectiles, effectively disabling the player from abusing the attack button.

if (game.player.missile && !game.player.missile.reseted) {
            game.player.missile.update();
        }

         if (game.player.missile && game.player.missile.position.y <= 2.5) {
            game.player.missile = null;
        }

        for (let enemy of game.enemies) {
            
            if (enemy.velocity.x <= 0) {
                enemy.image = enemy.sprites.frogLeft.image; 
                enemy.offset = {
                    x: enemy.radius * 5,
                    y: enemy.radius * 6
                };
            } else {
                enemy.image = enemy.sprites.frogRight.image;
                enemy.offset = {
                    x: enemy.radius * 3.3, 
                    y: enemy.radius * 6
                };
            }

            enemy.update();

            if (game.player.missile && game.player.missile.collided(enemy)) {
                game.player.missile = null;
                if (enemy.children.length === 0) {
                    enemy.split();
                    for (let child of enemy.children) {
                        game.enemies.push(child);
                    }
                    game.enemies = game.enemies.filter((e) => e !== enemy);
                }
            }
        }

froggy-bash's People

Contributors

shenshuu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.