Page 1 of 1

loveJS - LÖVE API in javascript

Posted: Mon May 05, 2014 11:35 am
by Sheepolution
GitHub

loveJS is an attempt to copy the LÖVE API into javascript.
The goal is to make it easy for LÖVE users to make webgames, and to port their games.

Example
The source for this example

Code: Select all

//Create an object.
obj = {};
//Load in the image
//love.graphics.newImage(url);
obj.image = love.graphics.newImage("pyramid.png");
//Load in the image
//love.audio.newSource(url);
obj.bounce = love.audio.newSource("bounce.ogg");
//Get a new font
//love.graphics.newFont(name,size);
obj.font = love.graphics.newFont("arial",15);
//All the other properties
obj.x = 200;
obj.y = 250;
obj.r = 1;
obj.sx = 1;
obj.sy = 1;
obj.dir = 1;
obj.speed = 100;

//The main updater
love.update = function (dt) {
	//Move the pyramid
	obj.x = obj.x + obj.speed * obj.dir * dt;

	//Make him bounce to the walls
	if (obj.x > 800) {
		obj.dir = -obj.dir;
		obj.x = 800;
		//Play a sound as he bounces
		love.audio.stop(obj.bounce);
		love.audio.play(obj.bounce);
	}

	if (obj.x<0) {
		obj.dir = -obj.dir;
		obj.x = 0;
		love.audio.stop(obj.bounce);
		love.audio.play(obj.bounce);
	}

	//Spin the pyramid
	obj.r += 3 * dt;

	//Scale the pyramid down as he gets closer to the center
	obj.sx = 4*((400-obj.x)/400);
	obj.sy = 4*((400-obj.x)/400);

	//Speed up the pyramid's movement
	if (love.keyboard.isDown("w","up")) {
		obj.speed += 300 * dt;
	}

	//Slow down the pyramid's movement
	if (love.keyboard.isDown("s","down")) {
		obj.speed -= 300 * dt;
	}

}

love.draw = function () {
	//Set the font
	love.graphics.setFont(obj.font)
	//Prevent images of being blurry
	love.graphics.setDefaultFilter("nearest");
	//Draw the pyramid
	love.graphics.draw(obj.image,obj.x,obj.y,obj.r,obj.sx,obj.sy,49,42);
	//Draw the description
	love.graphics.print("lovescript Demo v0.01",10,30);
	love.graphics.print("A/Up to speed up",10,55);
	love.graphics.print("S/Down to slow down",10,75);
	love.graphics.print("Space to invert direction",10,95);
	love.graphics.print("Click to position pyramid",10,115);
}

love.config = function (t) {
	//Set the width/height of the canvas
	t.width = 800;
	t.height = 600;
}

//If a key is pressed
love.keypressed = function (key) {
	//If the key pressed is space
	if (key==" ") {
		//Change the direction of the pyramid
		obj.dir = - obj.dir;
	}
}

//If a mousebutton is pressed
love.mousepressed = function (x,y,button) {
	//If the left mousebutton is pressed
	if (button=="l") {
		//Position the pyramid
		obj.y = y;
		obj.x = x;
	}
}

//Initialize love
love.run();
All implemented modules and their functions are listen on the GitHub page.
Right now it has graphics, audio, keyboard and mouse. The basics to make a decent game.

I could use any help with this project. Right now I'm just implementing every function that looks possible to do in my eyes.

Currently on top of my TODO list:
  • Add more not-all-too-complicated modules

    Make quads work as how they are supposed to work.

    Have love.graphics.draw support color change by setColor.
I could use any help, so feel free to contribute.

Re: lovescript - LÖVE API in javascript

Posted: Mon May 05, 2014 12:35 pm
by Tanner
I've done some preliminary work getting Love's Lua code to run in the browser. I'm not ready to "announce" it yet because I feel like it needs to webgl support to do some graphics stuff properly but you might be interested in looking at it: https://github.com/TannerRogalsky/moonshine-love2d

Here's the basic demo: http://tannerrogalsky.com/moonshine-love2d/

Re: lovescript - LÖVE API in javascript

Posted: Mon May 05, 2014 1:04 pm
by Sheepolution
Oh damn that looks really cool. It won't make me quit this project, but it does make it feel more unnecessary :P. Is it okay if I copy some of your methods? It would be a big help!

Re: lovescript - LÖVE API in javascript

Posted: Mon May 05, 2014 1:14 pm
by Tanner
Sheepolution wrote:Oh damn that looks really cool. It won't make me quit this project, but it does make it feel more unnecessary :P. Is it okay if I copy some of your methods? It would be a big help!
Please do. I, in turn, took a bunch of code from luv.js if you'd like another resource.

Re: loveJS - LÖVE API in javascript

Posted: Wed May 06, 2015 2:59 am
by adekto
i have played around with this web implementation of löve and its really great, this deserves some attention

Re: loveJS - LÖVE API in javascript

Posted: Sat Jul 04, 2015 10:38 pm
by gomez
adekto wrote:i have played around with this web implementation of löve and its really great, this deserves some attention
sorry for digging up the topic, but this implementation love-to-web is the most promising * - *

Do not let it die, please o/