Giter VIP home page Giter VIP logo

bloq's Introduction

Bloq Grammar

Introduction

The Bloq grammar is a Antlr4 grammar that is designed to simplify the process of 2D map design for platformer/RPG/maze games. Bloq allows the user to create patterns of different blocks and place them on a canvas without having to learn how to use a game engine.

NOTE: this is a clone of the repository which is originally located on UBC's private github enterprise.


Intro

Features

  • Variables
  • Conditionals
  • Functions
  • Loops
  • 2D bitmap

Getting Started

Creating a Canvas:

Creating a canvas with width w, and height h:

canvas: w, h

Defaults:

w: 100   
h: 100

Placing a Block:

Placing a block of type at the location (x, y) with shape bitmap:

 block: type 
 start: x, y
 shape: bitmap

Defaults:

start: 0, 0  
shape: 1;

type is a predefined type of block.

Supported blocktypes:

land
water
lava
enemy

bitmap can be a variable that is previously assigned a bitmap, or it can be define on the next line after Shape.
The bitmap should be in the monochrome format, setting a bit to 1 will place a block at that location.
Every row (including the last) must be terminated with semicolon.
The top left bit will be aligned to the start location.
If a block is placed at a location that's already occupied, the new block will replace the old block.

Bitmap Structure:

slantedLine: 
0001;
0010;
0100;
1000;

Placing a slantedline water block at 0, 0 on a 4x4 canvas will look like the following:

bitmap1

canvas: 4, 4

block: water
start: 0, 0
shape:
0001;
0010;
0100;
1000;

You can also place multiple block types in a single statement. The placement of each type of block can be defined in shape. The number associated with each block type corresponds to the position of that block type in the block statement, starting with 1.

canvas: 4, 4

block: water, lava, enemy
start: 0, 0
shape:
0001;
0020;
0300;
1000;

The code above will product the following image:

bitmap2

Using Variables

Bloq supports the following types of variable assignments:

Creating a integer variable named name with value value:

name: value

Creating a bitmap variable named name:

name:
row1;
row2;
...;

Using Loops

Repeating a statement n times:

for i: 1 to 10 {
    statement
}

Statement can be either a variable assignment, a block placement, function call, if-else statement or another loop.

Using Conditionals

Executes a statement(s) if condition is true, can also have else for when the condition is false (optional):

if (condition) {
    statement
} else {
    statement
}

Condition is a comparison between two mathematical expressions. You can also link conditions using the logic operators (&&, ||). You can also negate a condition with !condition.

Supported comparisons:

Comparison Symbol
Equal ==
Not Equal !=
Greater >
Less <
Greater or Equal to >=
Less or Equal to <=

Supported operations for mathematical expressions:

Operation Symbol
Addition +
Subtraction -
Multiplication *
Division /
Modulo %

Logic operators:

Operator Symbol
AND &&
OR ||
NOT !

Using Functions

Creating a new function called name with parameters a, b:

define name(a, b) {
    statement
}

Calling the same function with arguments 1 and 2:

call name(1, 2)

Example

canvas: 10, 5

pattern:
21;
12;
21;
12;
21;

for i: 0 to 9 {
    if (i % 2 == 0) {
        block: water, lava
        start: i, 0
        shape: pattern
    }
}

example_1


Contributors

Charlie Li, Janie Wang, Jessica Zhan, John Pham, and Shawn Lu.

bloq's People

Contributors

chees-e avatar charlie-li-02 avatar parmejohn avatar janiewang26 avatar jessizhan 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.