Page 2 of 3

Re: moving multiple objects with mouse

Posted: Tue Jul 01, 2008 11:23 pm
by cag
oh, lovetris doesn't really snap blocks to places. it's state is actually (hackily) held by an array. :oops:
Plus, it's not a very good example in the first place. Don't do as I do unless you don't plan on maintaining your game. ;)

Example implementation of snapping:
hgonfanon-edit.love
(124.92 KiB) Downloaded 203 times
Scroll down to have a look at the last two functions. I'm afraid the snapping method is a bit cryptic, though, but note that floor(num + .5) is functionally equivalent to round(num), and the 28.35 seems to be the average pixel width of your boxes (after noodling around with it a bit...).

Re: moving multiple objects with mouse

Posted: Wed Jul 02, 2008 12:52 pm
by farvardin
your snapping system is really good! I've adapted it to my game, and changed a few things. The width of the boxes was not easy to use, so I've resampled the board to give a 30 pixels width instead (I'll work again on the appearance later).

thanks again.

I think I'll need some arrays later anyway, because I'll have to test the positions of the pawns and if a movement is allowed and such...

Re: moving multiple objects with mouse

Posted: Thu Jul 03, 2008 7:04 pm
by farvardin
I've worked a bit more on my game.

I'm not totally satisfied with my code with is probably not very clean, but I managed to do a few things anyway.

What is working so far:

- initial placement of the pawns.

- after a move the positions of the pawns are stored in the own reference of the board (not in pixel). The console can display the positions to check them. The previous positions are stored too. It will allow to test if a move a legible in the future.
The x coordinates are upside down though, I may change this in the future.

- every pawn is recognised and can be named.

- beginning of a system of turns. At the moment it's only changing turn between black and white (1 turn black / 1 turn white), and disallow a color to play in place of the other, but in the future it should be possible to move several pawns, and end the turn after a few movements. (the rules are quite complicated, and I'd like to be able to change the code easily if I discover a rule in my game system should be changed)

I was just wondering if it was possible with Löve to allow a kind of "hyperlink", when you click on a text it will do an action. It may be easier than to check for the text position. If not, I will make a button to end the turn, it'd probably be the best.

Re: Farvardin's game (was: moving multiple objects with mouse)

Posted: Fri Jul 04, 2008 8:46 pm
by rude
farvardin wrote:I was just wondering if it was possible with Löve to allow a kind of "hyperlink", when you click on a text it will do an action. It may be easier than to check for the text position. If not, I will make a button to end the turn, it'd probably be the best.
There is no built-in support for this.

Maybe you can explain the rules of hgonfanon? Wikipedia and Google gives me nothing.

Re: Farvardin's game (was: moving multiple objects with mouse)

Posted: Fri Jul 04, 2008 9:16 pm
by farvardin
The rules are not from a known game, it's only an invention of my own.

They are there:
http://anamnese.online.fr/site2/index.p ... anon#toc13

I just don't know if the game would be playable or enjoyable, that's the reason the rules may change in the future.

Re: Farvardin's game (was: moving multiple objects with mouse)

Posted: Sat Jul 05, 2008 5:38 pm
by farvardin
is it possible to "factorise" the code like this:

I have a list which was created like this:

Code: Select all

	for i = 1,4 do 
		table.insert(objectsBG, 
		{ 
			x = 75, -- Position of the object.
			y = 75+i*boardSquareSize, 
			dx = 0, -- Displacement of the object.
			dy = 0,
			prevposx = 0, -- Previous Position in the checker's own referency
			prevposy = 0,
			posx = 2, -- Position in the checker's own referency
			posy = 2+i
		})
	end
Later I need to test if the 4 individual objects in this list are somewhere. So I have to test every instance like this:

if current == objectsBG[1] or current == objectsBG[2] or current == objectsBG[3]or current == objectsBG[4] then...

isn't it possible to do it a better way? Like objectsBG[1-4] for example ? I've tried to use a loop, but it's not accepted either.
What do you suggest?

Re: Farvardin's game (was: moving multiple objects with mouse)

Posted: Sat Jul 05, 2008 8:53 pm
by Merkoth
I'm working in a little IMGUI module, I have a working button widget that works something like this:

Code: Select all

function update(dt)

	gui_start()
	
   -- gui_button(x_position, y_position, text_to_show)
	if gui_button(400,300,"ShowThisText") then
		-- do something if the user clicked the button
	else
		-- if not, do something else
	end

   gui_finish()
end

function draw()

	gui_draw()
end
I'm not sure how is the API really going to look. But maybe you find it useful? I also have scrollbar/slider and textbox widgets on the works, but they aren't ready yet. This button can look like a link if you want...

If you're interested, maybe I can put together some code for you :)

Re: Farvardin's game (was: moving multiple objects with mouse)

Posted: Sat Jul 05, 2008 9:41 pm
by farvardin
I've used a highlighted button in fact, like this:

I've defined the coordinate where I wanted to place the button (which is 14 px big)

Code: Select all

love.graphics.draw(endturnbutton, endturnx, endturny)
I've used a test for the coordinates:

Code: Select all

	if x > (endturnx-7) and x < (endturnx+7) then
		if y > (endturny-7) and y < (endturny+7) then
			endturnbutton = love.graphics.newImage("endturn2.png")
		else
		    endturnbutton = love.graphics.newImage("endturn.png")
		end
		else
		    endturnbutton = love.graphics.newImage("endturn.png")
	end
and elsewhere:

Code: Select all

function mousepressed(x, y, button)
	if x > (endturnx-7) and x < (endturnx+7) and button == love.mouse_left then
		if y > (endturny-7) and y < (endturny+7) then
			tour_de_jeu() -- change the turn of play
			return
		end
	end
end
It's working well like this. I've uploaded the new version.

What is working now:

- the turn system: after a few moves, the player can shift turn.

- moves : If the player is moving the "soldat" (black only at the moment), it will prevent to move more than 3 steps

known bug:

- it's possible to snap a pawn outside the board by mistake

Problem:

- In the rules, the "soldat" movement is:
Soldats can move 3 squares in any direction (colums, rows or diagonales). The only exception is for reaching a hill (= black square), which takes 2 moves instead of one, but for moving on a hill or going back to plains, it takes 1 normal move.
I really don't know how to implement this. The problem is

░░░░
S██E
░██░
░░░░
(S= start, E= end)

would be legal because the pawn can go round the "hill", while


░░░░
S██░
░██░
░░░E

wouldn't, because the hill should be crossed somewhere.

I'm still thinking about the problem.

Re: Farvardin's game (was: moving multiple objects with mouse)

Posted: Tue Jul 08, 2008 6:26 am
by farvardin
I've opened a sourceforge project: http://hgonfanon.sourceforge.net/

I'd really like to have some contributors to help me working on it!

Re: Farvardin's game (was: moving multiple objects with mouse)

Posted: Tue Jul 08, 2008 7:25 am
by rude
You could probably use the A* algorithm for this, maybe with a heuristic like: distance_to_goal + terrain_type. With a max movement cost of 3, it shouldn't take too long either. Let me know if you need any help with it.

(Disclaimer: there are probably simpler ways to do it.)