Giter Club home page Giter Club logo

run's Introduction

RUN! Live

Collect all 4 coins to win! If the monster strikes you, the round will restart

  • W to Move Up
  • S to Move Down
  • A to Move Left
  • D to Move Right

Screen Shot 2022-11-28 at 10 52 58 AM Screen Shot 2022-11-28 at 10 55 55 AM Screen Shot 2022-11-28 at 10 59 02 AM Screen Shot 2022-11-28 at 10 56 28 AM

Functionality & MVPs

  • Monster AI
  • Movable/animated character
  • Collision detection
  • Coin Collection

Technologies, Libraries, APIs

  • Tiled (https://www.mapeditor.org/)
    • allowed for the simple creation of game map => { allows you to export JSON Array like Data that marks out all collision blocks inside an array

Challanges Faced

  • The character does not move on your screen, but gives the illusion of movement by offseting the enviroment around the monster. During my initial implementation, I did not take this into consideration, leaving myself with minimal options of how an AI would work as I am not tracking the player or monsters location. For the AI to work seemlessly, I would need to track offsetting moves inside an object that will represent the correct offset on every frame. Having this, I could then "revert" the map to its orginial state then implement a pathing algo for the monster to use. Implemented correctly, the monster AI should work seemlessly.

Technical Implementation of AI

Start the Great Chase

    if (gameOn) {
       bruteForceChase({rec1: monster, rec2: player})

Before the AI moves : check for collisions : if true, must navigate taking collisions into consideration

   function bruteForceChase({rec1, rec2}) {
   for (let i = 0; i < boundries.length; i++) {
       const bound = boundries[i]
       if (monsterCollision({rec1: monster, rec2: bound })) {
           navigateCollision({rec1: monster, rec2: player})
           return 
       } 
   }
   
            if (rec1.pos.x < rec2.pos.x + 15) {
               rec1.moveRight()
           }

           if (rec1.pos.y < rec2.pos.y - 100) {
               rec1.moveDown()
           }

           if (rec1.pos.y > rec2.pos.y - 100) {
               rec1.moveUp()
           }

           if (rec1.pos.x > rec2.pos.x +15) {
               rec1.moveLeft()
           }
   
}

Before we attempt to navigate around the Collision : check if we are stuck

  let prev = [0, 0]

  function navigateCollision({rec1, rec2}) {
    prev.push(rec1.pos.x)
    prev.push(rec1.pos.y)

    if (prev[0] === rec1.pos.x && prev[1] === rec1.pos.y) {
        prev.shift()
        prev.shift()
        helpImStuck(50)
        return 
    }  
    prev.shift()
    prev.shift() 

If we are not stuck : check if increasing a specific direction will cause a collision : if it will not cause a collison, add value to that cordinate

  if (
                    monsterCollision({
                        rec1: monster,
                        rec2: {
                            ...bound,
                            pos: {
                                x: bound.pos.x,
                                y: bound.pos.y + 3
                            }
                        }
                    })
                ) {
  • If we are stuck : teleport to a smart location
let prevTeleport = 'leftop'
let prevdirect = 'top';
function helpImStuck(panic) {
        if (prevdirect === 'bottom' || mapY > -500) {
            if (prevTeleport === 'leftTop') {
                spawnRightTop()
                console.log('righttop')
                prevTeleport = 'rightTop'
                prevdirect = 'top'
            } else {
                spawnLeftTop()
                console.log('lefttop')
                prevTeleport = 'leftTop'
                prevdirect = 'top'
            }
        } else {
            if (prevTeleport === 'rightBottom') {
                spawnLeftBottom()
                console.log('leftbottom')
                prevTeleport = 'leftBottom'
                prevdirect = 'bottom'

            } else {
                spawnRightBottom()
                console.log('rightbottom')
                prevTeleport = 'rightBottom'
                prevdirect = 'bottom'
            }
        }
}

run's People

Contributors

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