loveJS - LÖVE API in javascript

Discuss any ports of LÖVE to different platforms.
Post Reply
User avatar
Sheepolution
Party member
Posts: 264
Joined: Mon Mar 04, 2013 9:31 am
Location: The Netherlands
Contact:

loveJS - LÖVE API in javascript

Post 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.
Last edited by Sheepolution on Tue May 06, 2014 10:28 pm, edited 1 time in total.
User avatar
Tanner
Party member
Posts: 166
Joined: Tue Apr 10, 2012 1:51 am

Re: lovescript - LÖVE API in javascript

Post 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/
User avatar
Sheepolution
Party member
Posts: 264
Joined: Mon Mar 04, 2013 9:31 am
Location: The Netherlands
Contact:

Re: lovescript - LÖVE API in javascript

Post 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!
User avatar
Tanner
Party member
Posts: 166
Joined: Tue Apr 10, 2012 1:51 am

Re: lovescript - LÖVE API in javascript

Post 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.
User avatar
adekto
Prole
Posts: 35
Joined: Thu Dec 06, 2012 11:42 am

Re: loveJS - LÖVE API in javascript

Post by adekto »

i have played around with this web implementation of löve and its really great, this deserves some attention
User avatar
gomez
Citizen
Posts: 65
Joined: Mon Feb 18, 2013 12:23 am
Location: Sao Luís, Brazil

Re: loveJS - LÖVE API in javascript

Post 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/
Hey dude :D
Do you want to protect earth from an apocalypse ? Me too o/
Check my new game here: viewtopic.php?f=5&t=81001
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest