Code Monkey home page Code Monkey logo

corgirunner's Introduction

Corgi Runner

Corgi Runner

live

Corgi Runner is an infinite run game inspired by the likes of T-rex runner, Temple Run, and Subway Surfers. The goal of the game is to survive as long as possible and get the highest score.

Instructions

Your Corgi has escaped! Chase after him! Choose a difficulty level. Avoid obstacles (trees and birds) by pressing the space key to jump.

Technologies

  • JavaScript
  • HTML5 Canvas

Features and Implementation

All features in this game were implemented using native JavaScript DOM manipulation and, HTML5 canvas. No additional libraries were used.

Parallax Background

The Parallax background effect was created by having multiple canvas layers.

class Background {
  constructor(ctx, image, posY, imageLength, speed) {
    ...
  }
  ...
}

createBackground(backgroundCtx, foregroundCtx) {
  const backgroundImage = new Image();
  backgroundImage.src = './assets/images/scrolling-background.jpg';
  this.background = new Background(backgroundCtx, backgroundImage, -35, 1422, 0.8);

  const foregroundImage = new Image();
  foregroundImage.src = './assets/images/foreground-grass.png';
  this.foreground = new Background(foregroundCtx, foregroundImage, 250, 720, 6);
}

Two different instances of the Background class are created in the main game class, and are each given a different image and a separate canvas context. These will scroll at different speeds, creating the parallax effect. The degree of this effect can be adjusted directly in the game class.

Difficulty Settings

The difficulty settings change the random obstacle generation in the game. This is achieved by having a difficulty object that stores all of these settings, and will readjust the game based on the player selection.

const Difficulty = {
  'hard': {
    birds: true,
    multiplier: 7,
    maxTrees: 3,
    maxObstacles: 10,
  },
  'medium': {
    birds: false,
    multiplier: 3,
    maxTrees: 3,
    maxObstacles: 7,
  },
  'easy': {
    birds: false,
    multiplier: 1,
    maxTrees: 1,
    maxObstacles: 6,
  }
};

These settings are called on the game.start(difficulty) method. These settings can be tweaked as needed directly in the difficulty file.

High Scores

Local high scores are saved in a score object. This score object will also try to write a cookie to the browser in order to save local high scores between sessions. The score object will check if there is a cookie with scores already present, and if there is it will use those saved high scores.

const scoreCookie = Util.readCookie('localHighScores');
if (scoreCookie) {
  this.localHighScores = JSON.parse(scoreCookie);
} else {
  this.localHighScores = [
    [ 'dio', 15000 ],
    [ 'dio', 12000 ],
    [ 'dio', 8000 ],
    [ 'dio', 4000 ],
    [ 'dio', 1000 ]
  ];
}

On the live version there is a global high score that requires a backend database to store names and scores. This not a feature you will have if you download and play this game locally.

Future Features

  1. Add more difficulty settings (VERY HARD).
  2. Create obstacles that move up and down and create beatable patterns around those.

Legal

Art and music assets used in this project are for educational purposes only. Art and Music assets are property of Tobi Fox, Nintendo, and Nexon.

corgirunner's People

Contributors

direcorgi 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.