Git Product home page Git Product logo

raycast-ts's Introduction

Raycast Engine

A raycast engine written in TypeScript.

You can play the demo at https://games.delarco.com.br/raycast-demo.

Screenshot 01 Screenshot 02

Getting Started

Create a TypeScript project from scratch or using your favorite tool/framework:

npm create vite@latest

Install the raycast-ts package:

npm install git+https://github.com/delarco/raycast-ts.git

Create a scene:

// test-scene.ts
import { RaycastScene } from "raycast-ts";

export class TestScene extends RaycastScene {

    public override preload(): void {

        // create a map from a number array
        this.load.mapFromIntArray([
            1, 1, 1, 1, 1,
            1, 0, 0, 0, 1,
            1, 0, 0, 0, 1,
            1, 0, 0, 0, 1,
            1, 1, 1, 1, 1,
        ], {
            width: 5,
            height: 5
        })
    }
}

In the main file (main.ts for Vite), create a game and start the scene:

// index.ts or main.ts or app.ts or whatever.ts
import { TestScene } from './TestScene.ts'

const game = new Game()
game.start(TestScene)

Running, we get something like this:

Screenshot 03

You can move the camera with:

  • Arrow keys;
  • WASD keys; and
  • Click on the canvas and use the mouse to rotate the camera.

Tiles whith value 0 are not solid and have no collision. Values greater than 0 are walls (solid and collision) and we can set a color:

// test-scene.ts

/* ... */

this.load.mapFromIntArray([
    1, 1, 1, 5, 1,
    1, 0, 0, 0, 2,
    1, 0, 0, 0, 3,
    1, 0, 0, 0, 4,
    1, 1, 1, 6, 1,
], {
    width: 5,
    height: 5
}, {
    1: Color.WHITE,
    2: Color.RED,
    3: Color.GREEN,
    4: Color.BLUE,
    5: Color.YELLOW,
    6: Color.ORANGE,
})

/* ... */

Screenshot 04

You can also load a map from json files, check the demo project.

To use a texture, load it in the preload method and apply in init method:

// test-scene.ts
public override preload(): void {

    /* ... */
    this.load.texture("texture-1", "./texture-file.jpg")
}

public override init(): void {

    for (const tile of this.map.tiles) {
        tile.texture = {
            ...tile.texture,
            [Side.WEST]: this.load.getTexture("texture-1")!
            // each side can have a different texture
        }
    }
}

Screenshot 05

TODO

  • tests
  • Keymaps
  • Animated rectangle (sprites)
  • Create an AssetsManager
  • Implement a good map parser

Resources

raycast-ts's People

Contributors

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