Giter VIP home page Giter VIP logo

game-iverse's Introduction

GAME-IVERSE

jumpstart your JS game using game-iverse game libraries.

CURRENT GAMES

* brickbreak
* snake

INSTALL

in your project directory npm install game-iverse

USAGE

Currently you can't natively require NPM packages in the browser to make a client side game. There are however a couple hacks you can use to make a javascript game. new methods will be added as time goes on.

Using the browser's native module support

the easiest implementation at the moment is to make a client side game importing the classes directly from the package folder. in your html add this script : <script type="module" src="./example.js"></script>

BrickBreak

//add to a js file "example.js"
// this is the full game just add the script to your html
import { World, Ball, Paddle, Brick, Hud } from '../node_modules/game-iverse/brickbreak/brickbreakclasses.js'
var canvas = new World(document.getElementById("canvas"));
var ball = new Ball(canvas);
var brick = new Brick(canvas);
var hud = new Hud(canvas);
var paddle = new Paddle(canvas);

paddle.keyUp
paddle.keyDown
paddle.mouseMove
brick.bricksArray(brick.bricks)
ball.draw()
var draw = () => {
    canvas.ctx.clearRect(0, 0, canvas.canvas.width, canvas.canvas.height);
    brick.draw()
    ball.draw()
    paddle.draw()
    hud.draw()
    ball.boundaries(ball.x, paddle)
    brick.collisionDetection(ball, hud)
    paddle.movement()

    ball.x += ball.dx;
    ball.y += ball.dy;
    requestAnimationFrame(draw)
}
draw();

Snake

//add to a js file "example.js"
// this is the full game just add the script to your html
import { World, Snake, Food, Hud } from '../node_modules/game-iverse/snake/snakeclasses.js'
var canvas = new World(document.getElementById("canvas"));
var hud = new Hud(canvas);
var snake = new Snake(canvas);
var food = new Food(canvas);
var count = 0;

snake.keyUp
snake.keyDown
snake.draw()
food.draw()
var draw = () => {
    requestAnimationFrame(draw)
    // reduce to 15 fps.
    if (++count < 4) {
        return;
    }
    count = 0;

    canvas.ctx.clearRect(0, 0, canvas.canvas.width, canvas.canvas.height);
    snake.draw()
    food.draw()
    hud.draw()

    food.collisionDetection(snake, hud)
    snake.movement()

}
draw();

You can use a bundler like webpack or browserify

I'd suggest taking a look at browserify examples coming soon

Contributors :

jeff-ong pandabear41

game-iverse's People

Contributors

wolffles avatar pandabear41 avatar dimitrikft 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.