Version 1.1.0 is out !

Version 1.1.0 is out now !

Download it from here

In this version you see a flexible Editor. also we made lots of changes in the core and many bugs fixed. You can make different objects, set your project settings visually and run your games by simply click a button. some code snippets and easy to use event buttons, Audio engine and new algorithm to animate strip images. There is a sample project in the rar file. open Quick2D and hit the Folder button to open the project.
Functions and Parameters Added to this release:

ray_hit

draw_background

load_sound

play_sound

stop_sound

Image

Image

Have fun

How to debug faster !

Are you tired of dragging your scripts onto Quick2D.exe ?

The solution is simple !

- Put your scripts in a different folder.

- Right click on a script.

Image

- Choose Open With … -> Choose default program

- Select Quick2D.exe

and BAM ! you’re done.

Now double click on your script and your game runs.

 

Enjoy

How to make Object Instancing

First of all, this tutorial is written based on revision 1.0.3 so if you don’t have it, download it from here.

To have instances of an object, you need to make a class for it.

Its simple and flexible.

function Object ()
{
this.id=0;
this.x=0;
this.y=0;
this.direction=0;
this.speed=0;
this.life=0;
this.draw = function ()
{
draw_sprite(this.id,this.x,this.y,this.life*3);
}
}

This is an example of a class named Object with some parameters and a function for drawing the object.
Project settings are not anything special, simply put:

function Project_Settings (id)
{
set_title(“Object Instancing”);
set_screen(800,600);
}

And then define an Array and a variable:

var rocks=new Array();
var can_create;

rocks is gonna be an array of Object. but how ?

In Start event put :

for (var i=0;i<20;i+=1)
{
rocks[i]=new Object();
rocks[i].id=load_texture(“gem_”+Math.floor(Math.random()*5)+”.png”);
}

We want to have 20 instances of Object class, with random textures loaded from Sprites folder with names like “gem_1.png”

Then, initialize our only variable:

can_create=true;

In this example we want to make 20 gems at mouse clicking point and having the gems moving in different angles.

So before doing anything, write onMouseButtonPressed event:

function onMouseButtonPressed (e)
{
if (can_create)
{
can_create=false;
for (var i=0;i<20;i+=1)
{
rocks[i].x=e.X;
rocks[i].y=e.Y;
rocks[i].life=80;
rocks[i].direction=Math.floor(Math.random()*360);
rocks[i].speed=Math.floor(Math.random()*3)+3;
rotate(rocks[i].id,rocks[i].direction);
}
}
}

can_create is just a variable that controls when we can create our instances.

We have a loop that fills every single object in rocks array with position of mouse clicked point, a life, random direction and random speed and finally a rotation to object’s angles.

Now the Main event:

function Main (id)
{
if (!can_create)
{
for (var i=0;i<20;i+=1)
{
if (rocks[i].life>0)
{
rocks[i].life-=1;
rocks[i].draw();
}else{
can_create=true;
}
rocks[i].x+=xval_to_direction(rocks[i].id,rocks[i].direction,rocks[i].speed);
rocks[i].y+=yval_to_direction(rocks[i].id,rocks[i].direction,rocks[i].speed);
}
}
}

We draw every single object while its life is larger than 0. once its not, we can create another bunch of objects.

And using the functions xval_to_direction and yval_to_direction we move every object along its direction.

Note: objects will fadeout by the time they loose life.

rev 1.0.3

Finally rev 1.0.3 is ready !

*=*=*=*=*=*=*=*=*=*=*=*=*

Download rev 1.0.3 (1.25Mb)
A mini game with source is included. not all functions are used in it though.
Functions and Parameters Added in this version:

LeftButton

RightButton

MiddleButton

rotate (id, angle)

double = xval_to_point (id, targetX, targetY, speed)

double = yval_to_point (id, targetX, targetY, speed)

double = xval_to_direction (id, angle, speed)

double = yval_to_direction (id, angle, speed)

angle = lookAt (id, targetX, targetY)

double = distance_to_point (id, targetX, targetY)

wait (milliseconds)

double = mouse_hit (id, mouseX, mouseY)

 

Screenshots of the sample project:

Image

Image

To run the sample project, simply draw bubble_poker.js onto <Quick2D.exe>

Some features of rev 1.0.3

New movement functions in rev 1.0.3

rotate (id, angle)

double = xval_to_point (id, targetX, targetY, speed)

double = yval_to_point (id, targetX, targetY, speed)

double = xval_to_direction (id, angle, speed)

double = yval_to_direction (id, angle, speed)

angle = lookAt (id, targetX, targetY)

And new mouse events

LeftButton

RightButton

MiddleButton

Instead of “Left” and converting Button to string, easily use e.Button==LeftButton

How to make character animation

- first, make a file named “character_animation.js” and put the tamplate in it:

function Project_Settings(id)
{
}
function Start(id)
{
}
function Main(id)
{
}
- Go to the Sprites folder and put character folder in it. (Download character.rar)
- define these variables:
var speed, is_down, f, x, y, timer;
var frames=new Array();
- in Project_Settings :
set_title("Character Animation");
window_mode(0);
set_screen(800,600);
in the first line, we set the window title, next we set it to windowed and finally set the resolution to 800×600 pixels.

- in Start event, lets initialize our variables:

speed=0;
f=0;
timer=0;
x=100;
y=250;
is_down=false;
- after that, we need to fill our array with frames. so:
for (var i=0; i < 8; i+=1)
{
    frames=load_texture("character\\"+(i+1)+".png");
}
now we’re set to go.
– in Main event, draw the character using draw_sprite function :
draw_sprite(frames[f],x,y);
- now we need to make a timer for frame animation :
if (is_down)
{
    if (timer < 4)
    {
        timer+=1;
    }else{
        timer=0;
        f+=1;
        if (f > 7)
        {
            f=0;
        }
    }
}
you can play with timer values to change the speed of the animation.
now its time to move our character using keyboard.
I’ll do it for one direction, you do the rest ;)

- make a keyboard keypress event :

function onKeyPressed(e)
{
}
- add following lines in it :
if (e=="Right")
{
    is_down=true;
}
it says if you press the Right arrow on your keyboard, it’ll start moving. now lets stop it on releasing the key !
function onKeyReleased(e)
{
    if (e=="Right")
    {
        is_down=false;
        f=0;
    }
}
Time to move !
– get back to Main event and add this line after if (is_down){
x+=2;
Save your script and run your game by dragging character_animation.js onto <Quick2D.exe>

Feel free to ask your questions.

rev 1.0.2

Download rev 1.0.2 (770kb)

For now, it has no editor, you can use any editor of your choice, like Notepad++ .
In this package, there’s a main.js file which includes some base codes and not used variables just to show you how things look and are gonna work.

Once you’re script is done, simply run it by Dragging it on the core <Quick2D.exe>. there is no standalone exe version of your game yet but it’ll be added as soon as the main developing process of the engine is over.

You can have your own script like myname.js or anything else, also additional script files can easily be attached.

Functions and Parameters available in this version:

  • double = load_texture (string);
  • draw_sprite (id, x, y);
  • draw_text (text, size, x, y);
  • set_origin (id, x, y);
  • set_cursor ("visible" or "invisible");
  • set_title (title);
  • set_screen (width, height);
  • get_width (id);
  • get_height (id);
  • double = screen_width;
  • double = screen_height;
  • exec ("script.js");
  • alert (message);
  • double = random (max);
  • window_mode (0 or 1);
  • quit ();
  • double = Length (string);
  • double = check_collision (id1, id2);
Events available in this version:
  • onMouseButtonPressed (e)
  • onMouseButtonReleased (e)
  • onMouseMove (e)
  • onMouseWheelMoved (e)
  • onKeyPressed (e)
  • onKeyReleased (e)

 

There are 3 main Events/Functions that you should never attempt to delete them, Project_Settings, Start and Update.

Project_Settings will be called at the beginning of your game once and for all. in this event you can set your project settings like Windowed or Fullscreen, window size, window title, etc…

Start will be called once after Project_Settings. its the best place to initialize your variables.

Update is the main loop of the game. nothing fancy.

In Mouse Button events, e contains Button, X, Y (small and capital letters are important)

if (e.Button+""=="Left")
{
// Your code
}

You have to convert Button to string. it’ll be fixed in the next version.
The function exec is for calling scripts from outside of the main script. simply put it at the beginning of Start event.
get_width and get_height are usable to get sprites sizes by giving them the sprite id.
And remember, never use load_texture in Update event.

Empty template for main.js:

function Project_Settings(id)
{
}
function Start(id)
{
}
function Main(id)
{
}
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: