The epic love demo thread!

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Xcmd
Party member
Posts: 211
Joined: Fri Feb 13, 2009 10:45 pm

Re: The epic love demo thread!

Post by Xcmd » Mon Apr 13, 2009 12:34 pm

Second crack. This one is a little better as it attempts to weigh the costs between the X Axis and the Y Axis and move accordingly. The motion is a little smoother, however it still heavily biases towards one or the other. Part of me thinks that in order to do this right, I'm going to have to either invoke the physics engine (set an angle, set the impulse/force/whatever) or else I'm going to have to come up with an implementation of A* Path-finding algorithm. Or maybe just Dykstra's Algorithm...

Code: Select all

--Move Directly To Function

--What the program does is determine which value in an X/Y array is higher.
--It then gives whichever axis has a higher value an extra movement turn
--on that pass.

function load()
	mousePressed = false
	gotoX = 0
	gotoY = 0
	playerBallX = 400
	playerBallY = 300
	speed = 1
end

function update(dt)
	--Step 1: Get the values
	local xAxisCost
	local yAxisCost
	local moveTokenX
	local moveTokenY
	
	if mousePressed == true then
		if gotoX > playerBallX then
			xAxisCost = gotoX - playerBallX
			playerBallX = playerBallX + speed -- move the ball
			moveTokenX = true
		else
			xAxisCost = makePositive((gotoX - playerBallX))
			playerBallX = playerBallX - speed -- move the ball
			moveTokenX = false
		end
		if gotoX == playerBallX then
			xAxisCost = 0
		end
		
		if gotoY > playerBallY then
			yAxisCost = gotoY - playerBallY
			playerBallY = playerBallY + speed
			moveTokenY = true
		else
			yAxisCost = makePositive((gotoY - playerBallY))
			playerBallY = playerBallY - speed
			moveTokenY = false
		end
		if gotoY == playerBallY then
			yAxisCost = 0
		end
		
		if xAxisCost > yAxisCost then
			if moveTokenX then
				playerBallX = playerBallX + speed
			else
				playerBallX = playerBallX - speed
			end
		else
			if moveTokenY then
				playerBallY = playerBallY + speed
			else
				playerBallY = playerBallY - speed
			end
		end
	end
end

function draw()
	love.graphics.circle(1, gotoX, gotoY, 5)
	love.graphics.circle(1, playerBallX, playerBallY, 20)
end

function mousereleased(x, y, button)
	if button == love.mouse_left then
		mousePressed = true
		gotoX = x
		gotoY = y
	end
end

function makePositive ( negativeNumber )
	local positiveNumber
	positiveNumber = (negativeNumber * -1)
	return positiveNumber
end

If this isn't clear to you (I try to make my variables very human readable, but I still sometimes wind up with esoteric things) and you'd like more code commenting, please let me know.

Side Note: I couldn't find any sort of built-in function for making a negative number positive in Lua. Since we don't have a text console in Love and this is the only Lua implementation I have, I couldn't quickie test what one site told me I could do:

print( not -50 )

Known Issues:

When the big circle (the player sprite) matches up to the little circle (the cursor), it doesn't stop moving, it just sort of twitches. I'm not 100% sure what the deal is, but I may have to build in a "if we're within blah and blah, then set the X of the Player Sprite to the X of the Destination" type function.

Notes for the Future:

I'm thinking that in order to make it a much smoother progression, what I'm going to have to do is basically simplify the x/y axis costs and determine what the ratio is. Basically, if we've got 100 pixels to shift for X but 200 pixels to shift for Y, then for every 1 time we move X, we need to move Y twice (1:2). But if we're 100 away for X and 300 away for Y, for every time we move X, we need to move Y three times (1:3). If that makes any sense.
We don't borrow, we don't read, we don't rent, we don't lease, we take the minds!

User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: The epic love demo thread!

Post by bartbes » Mon Apr 13, 2009 5:21 pm

Xcmd wrote:Side Note: I couldn't find any sort of built-in function for making a negative number positive in Lua. Since we don't have a text console in Love and this is the only Lua implementation I have, I couldn't quickie test what one site told me I could do:

print( not -50 )
math.abs?

User avatar
Xcmd
Party member
Posts: 211
Joined: Fri Feb 13, 2009 10:45 pm

Re: The epic love demo thread!

Post by Xcmd » Mon Apr 13, 2009 8:36 pm

That works. It's what I get for coding at 7 in the morning after having been up since noon the previous day. Thanks!

Updated Code:

Code: Select all

--Move Directly To Function

--What the program does is determine which value in an X/Y array is higher.
--It then gives whichever axis has a higher value an extra movement turn
--on that pass.

function load()
	mousePressed = false
	gotoX = 0
	gotoY = 0
	playerBallX = 400
	playerBallY = 300
	speed = 1
end

function update(dt)
	--Step 1: Get the values
	local xAxisCost
	local yAxisCost
	local moveTokenX
	local moveTokenY
	
	if mousePressed == true then
		if gotoX > playerBallX then
			xAxisCost = gotoX - playerBallX
			playerBallX = playerBallX + speed -- move the ball
			moveTokenX = true
		else
			xAxisCost = math.abs((gotoX - playerBallX))
			playerBallX = playerBallX - speed -- move the ball
			moveTokenX = false
		end
		if gotoX == playerBallX then
			xAxisCost = 0
		end
		
		if gotoY > playerBallY then
			yAxisCost = gotoY - playerBallY
			playerBallY = playerBallY + speed
			moveTokenY = true
		else
			yAxisCost = math.abs((gotoY - playerBallY))
			playerBallY = playerBallY - speed
			moveTokenY = false
		end
		if gotoY == playerBallY then
			yAxisCost = 0
		end
		
		if xAxisCost > yAxisCost then
			if moveTokenX then
				playerBallX = playerBallX + speed
			else
				playerBallX = playerBallX - speed
			end
		else
			if moveTokenY then
				playerBallY = playerBallY + speed
			else
				playerBallY = playerBallY - speed
			end
		end
	end
end

function draw()
	love.graphics.circle(1, gotoX, gotoY, 5)
	love.graphics.circle(1, playerBallX, playerBallY, 20)
end

function mousereleased(x, y, button)
	if button == love.mouse_left then
		mousePressed = true
		gotoX = x
		gotoY = y
	end
end
Now to figure out how to simplify the numbers and come up with a ratio. Hmm. This may go beyond my knowledge of maths.
We don't borrow, we don't read, we don't rent, we don't lease, we take the minds!

User avatar
osgeld
Party member
Posts: 303
Joined: Sun Nov 23, 2008 10:13 pm

Re: The epic love demo thread!

Post by osgeld » Mon Apr 13, 2009 8:37 pm

negative * -1 = positive

-50*-1 = 50

User avatar
Xcmd
Party member
Posts: 211
Joined: Fri Feb 13, 2009 10:45 pm

Re: The epic love demo thread!

Post by Xcmd » Mon Apr 13, 2009 8:39 pm

osgeld wrote:negative * -1 = positive

-50*-1 = 50
Actually if you look up there, my makePositive function did precisely that. :D But as was pointed out to me, math.abs does the same thing. I'd prefer built-in functionality over cobbled-together madness any day. But thank you for the response!
We don't borrow, we don't read, we don't rent, we don't lease, we take the minds!

User avatar
qubodup
Inner party member
Posts: 775
Joined: Sat Jun 21, 2008 9:21 pm
Location: Berlin, Germany
Contact:

belly

Post by qubodup » Tue Apr 14, 2009 5:06 am

I made belly.

It is a simple music thing.

You can download a .love file.

It looks like this:
Image

I wonder how I could allow the user to save the table.

Currently I'm struggling with being able to synthesize sounds on my linux machine.

PS: *thinks* perhaps... combine this with game of life?....
lg.newImage("cat.png") -- made possible by lg = love.graphics
-- Don't force fullscreen (it frustrates those who want to try your game real quick) -- Develop for 1280x720 (so people can make HD videos)

User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: The epic love demo thread!

Post by bartbes » Tue Apr 14, 2009 7:05 am

I love playing with sounds!!
(especially if I actually create a song by just clicking randomly :P)

EDIT: let me post it
Attachments
sample.png
sample.png (6.92 KiB) Viewed 2606 times

User avatar
Gerrit
Prole
Posts: 46
Joined: Wed Mar 25, 2009 7:40 pm

Re: belly

Post by Gerrit » Thu Apr 16, 2009 1:53 pm

qubodup wrote:I made belly.

It is a simple music thing.
I just löve it :) Made some small enhancements, hope you like them:
- pause the game with spacebar
- switch between banks with 1 .. 9 (if you switch your progress will be saved to the last used bank)

The only thing left now would be the option to save the set for good because the banks are also temporary. But 9 banks should be enaugh to make a small song with it. To save it just grab the sound with a program or hook your pc up to your stereo and record it there ;)

http://rapidshare.com/files/222049965/b ... 5-mod.love

PS: Uploaded to RS. It seems I can't upload anything here right now..

User avatar
athanazio
Citizen
Posts: 96
Joined: Fri Apr 10, 2009 3:12 am
Location: Rio de Janeiro - Brazil
Contact:

Re: The epic love demo thread!

Post by athanazio » Thu Apr 16, 2009 2:51 pm

only one word I LOVE it ! =)
will add the file to my blog, so its easier to share
with my friends !!

http://www.athanazio.com/2009/04/16/love-games-belly/
would be great to have a way to save the composition to a file and send to a site, so others could hear and share the songs !!
that would be GREAT !!

So where is the www.BellyHits.com ? =) or TechnoBelly.com heheheh

lots of fun !!
Nothing is simple but everything is possible.

User avatar
qubodup
Inner party member
Posts: 775
Joined: Sat Jun 21, 2008 9:21 pm
Location: Berlin, Germany
Contact:

Re: The epic love demo thread!

Post by qubodup » Thu Apr 16, 2009 3:08 pm

athanazio wrote:would be great to have a way to save the composition to a file and send to a site, so others could hear and share the songs !!
that would be GREAT !!
bartbes implemented a save load function that saves 12 files in your home/HIDDEN_LOVE_FOLDER/belly directory. It was in git, so I created a new release: 0.6 http://github.com/qubodup/belly/downloads
lg.newImage("cat.png") -- made possible by lg = love.graphics
-- Don't force fullscreen (it frustrates those who want to try your game real quick) -- Develop for 1280x720 (so people can make HD videos)

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests