Code Monkey home page Code Monkey logo

wall_e_ball's Introduction

Wall-E Ball

Live Demo

alt text inspired by Doodle Jump

Story

Eve?!

alt text

Gameplay

Tap left and right and Wall-E will use puffs of his fire extinguisher to move around. If you want Wall-E to move fast, you can puff air really quickly or even hold down the left or right key to watch him fly, though that might not be the best way to make sure he lands where he needs to. If you reach the spaceship, press "enter" and your score will persist, so you can continue and keep pushing for new high scores!

alt text

Code

Wall-E is built entirely on JavaScript using Canvas and HTML with CSS. With requestAnimationFrame, the canvas element is repainted up to 60 times a second to create a seamless 2D scrolling experience.

Wall-E

When Wall-E moves up, everything else moves down. By manipulating the y-axis of all the clouds and the boards as Wall-E reaches a certain height on the canvas, the experience of scrolling and upward movement is achieved.

if (ball.y < 200) {
  boards.forEach(board => {
    board[0] += ball.vy;
    if (board[0] < -50) {
      boards.pop();
    }
  });
  cloudsArray.forEach(cloud => {
    cloud[0] += ball.vy;
  });
  ball.y -= ball.vy;
  groundCoord[0] -= ball.vy;
  topCoord[0] += ball.vy;
  score += 1;
}

Boards and Clouds

With every game boards and clouds are positioned randomly. While the position of clouds are entirely random, the boards could not be done that way because of the possibility of there being a gap where the bounce height might not be able to reach the next board. In order to overcome this, the y-coordinate of boards are given max random values that represent the max gap between them. As Wall-E goes higher, that max gap increases. Only the first and last boards are not randomized.

let boards = [];
const lastBoardY = 10000;
function fillBoards() {
  let gap = 0;
  let ypos = lastBoardY - 200;
  let xpos;
  boards.push([lastBoardY, 0.5 * xposMax]);
  while (ypos > 230) {
    xpos = Math.random() * xposMax;
    boards.push([ypos, xpos]);
    if (ypos > 7500) {
      gap = Math.random() * 250;
      ypos -= gap;
    } else if (ypos > 5000) {
      gap = Math.random() * 200;
      ypos -= gap;
    } else if (ypos > 2500) {
      gap = Math.random() * 150;
      ypos -= gap;
    } else if (ypos > 230) {
      gap = Math.random() * 100;
      ypos -= gap;
    }
  }
  boards.push([230, 0.5 * xposMax]);
}

Future Directions

Items

Add items that Wall-E can collect on the way up that would increase the score further.

Board Variations

Add boards that move, boards that give a higher bounce, and boards that can sustain limited bounces.

Enemies

Add enemies that would make Wall-E lose if he collides with them.

Legal

Art and music assets used in this project are for educational purposes only. Art and Music assets are property of Disney.

wall_e_ball's People

Contributors

dannam83 avatar

wall_e_ball's Issues

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.