Page 13 of 14

Re: The epic love demo thread!

Posted: Mon Apr 13, 2009 12:34 pm
by Xcmd
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.

Re: The epic love demo thread!

Posted: Mon Apr 13, 2009 5:21 pm
by bartbes
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?

Re: The epic love demo thread!

Posted: Mon Apr 13, 2009 8:36 pm
by Xcmd
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.

Re: The epic love demo thread!

Posted: Mon Apr 13, 2009 8:37 pm
by osgeld
negative * -1 = positive

-50*-1 = 50

Re: The epic love demo thread!

Posted: Mon Apr 13, 2009 8:39 pm
by Xcmd
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!

belly

Posted: Tue Apr 14, 2009 5:06 am
by qubodup
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?....

Re: The epic love demo thread!

Posted: Tue Apr 14, 2009 7:05 am
by bartbes
I love playing with sounds!!
(especially if I actually create a song by just clicking randomly :P)

EDIT: let me post it

Re: belly

Posted: Thu Apr 16, 2009 1:53 pm
by Gerrit
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..

Re: The epic love demo thread!

Posted: Thu Apr 16, 2009 2:51 pm
by athanazio
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 !!

Re: The epic love demo thread!

Posted: Thu Apr 16, 2009 3:08 pm
by qubodup
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