Giter Site home page Giter Site logo

coyota.js's Introduction

coyota.js

A very very simple game engine written in Javascript.

How to use it

Coyota.js provide two main functions, OnStart and Always. OnStart function will be executed the first time the game is run, Always is the game loop.

    OnStart(() => {
      screen.create(320, 240)    
    })

    Always(() => {
      // Write your game here
    })

Preload resources

It is highly recommended to preload your assets before using them. You can use the promise AssetManager.load () for that.

Use the Setup function to set up your game while your assets are loading. AssetManager is a global object.

let resources = {
  playerTexture: './assets/mauricio.png',
}

Setup(() => {
  screen.create(320, 240)    
})

AssetManager.load(resources).then(() => {

  let player

  OnStart(() => {
    player  = new Sprite(AssetManager.Textures.playerTexture, 160, 120, 24, 43, 12, 20)
  })

  Always(() => {
    player.draw()
  })
})

Create Sprite Animations

You need to import the Sprite and Animation classes from lib/Sprite/

OnStart(() => {
  player = new Sprite('./assets/mauricio.png', 160, 120, 24, 43, 12, 20)
        
  player.addAnimation({
    "Walk": new Animation(player.texture, 1, 3, 10) //source, initialFrame, lastFrame, speed)
  })
}

Always(() => {
  player.setAnimation("Walk").play()
  player.draw()
 })

Animated Sprite

Sprite Animation

Add behaviors

player.addBehavior(new Spinner(40))

Animated Sprite with Spinner Behavior

Spinner Behavior

List of behaviors:

  • Bullet
  • Spinner
  • Solid
  • Platformer (work in progress)

Solid objects and collisions

This project uses Collisions library

All CoyotaObjects has a collider property. When an Sprite is created, collider initialize with a Polygon object from Collisions Library with the same size and position of the Sprite.

import Sprite from './lib/Sprite/Sprite.js' 
import Bullet from './behaviors/Bullet/Bullet.js'
import Solid from './behaviors/Solid/Solid.js'

let ball
let player
let cpu

  OnStart(() => {
    screen.create(320, 240)    

    ball    = new Sprite('./assets/ball.png', 160, 120, 8, 8, 4, 4)
    player  = new Sprite('./assets/paddle.png', 36, 120, 8, 40, 4, 20)
    cpu     = new Sprite('./assets/paddle.png', 280, 120, 8, 40, 4, 20)

    // new Bullet(speed, angleOfMotion, bounceOffSolids)
    ball.addBehavior(new Bullet(200, 0, true))
    cpu.addBehavior(new Solid())
    player.addBehavior(new Solid())

  })

  Always(() => {
    cpu.draw()
    ball.draw()
    player.draw()
  })

Simple pong

  ball.addBehavior(new Bullet(200, 0, true))
  cpu.addBehavior(new Solid())
  player.addBehavior(new Solid())

Pong

coyota.js's People

Contributors

yojona avatar reyisw avatar

Stargazers

mohamad hani janaty avatar Gabriela Cruz avatar  avatar  avatar  avatar

Watchers

James Cloos avatar  avatar  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.