Page 1 of 1

Conquer Iceland v1

Posted: Thu Aug 15, 2013 11:15 pm
by Mermersk
Hello all,

I want to show you what I have been working on lately, It's a 2-player strategy game(inspired by Risk). This is the third project I have done in Löve.
swbaLHm.jpg
swbaLHm.jpg (169.21 KiB) Viewed 415 times
At the start of the game each area, and the number(army strength) is randomly generated. Either a shield or a axe, and the numbers range from 2-6. This happens when you click the "generate" button.

The players choose which side they want to play. Each area can only move units with their neighboring area. Each player gets 3 actions per turn, as indicated on the right-bottom side. Each move order depletes one action. (left-mouse button)
You use the right mouse button to gather army(move order) and then the left mouse button to tell them where to go. Always one army must remain to guard the area. The sail in the left-bottom of the screen is the attack-bonus. Only when you attack the other player you get the bonus (which varies between 0-3).

If the attacker has 3 and the defender is also 3 then the defender wins but loses 1 army. So if even, then the defender always wins. If either all the areas are axe or shield-controlled than that player wins the game.

If something is unexplained then please ask. The clouds are also randomly generated in size-opacity and speed.
If you find a duck flying in the game, then right-clicking it will make it quite happy :crazy:

Things left to do:

# Add a help menu/text explaining the game
# Add either random army units drops or have some areas get a bigger attack bonus to make the game more varied.
# Fix the problem of all areas eventually only having one 1 army left, and therefore the game is a stalemate.

Download: https://www.dropbox.com/s/f9v5kovhhevpp ... eland.love

I cant upload to the forum. something about a limit, even though its only 2,5mb.

Edit#1: Fixed a problem with the win state not showing up properly.

Re: Conquer Iceland v1

Posted: Fri Aug 16, 2013 6:39 pm
by vladgalay
Hello, Mermersk =)

Your game is quite good. I liked the drawn-like style of the graphics. It looks nice, and makes gameplay a little bit more comfortable :) Decorations, like clouds and ducks, fit the game's style very well. Background music and sounds are good. But i have some ideas, that probably, will make your game better =)

- Whole screen message, that informs, who's turn is now ( like <image of team>, your turn! ). Arrow, pointing at the team's icon looks fine, but when i played first time, it was hard for me to discover, who's turn is now =\
- Make possible to play with AI
- [looked in your code, sorry] Try to make a good use of arrays and loops. With them, your code will be much shorter =)

I like the original Risk game, and your game as well! Keep up the good work! =)

Re: Conquer Iceland v1

Posted: Sun Aug 18, 2013 7:19 pm
by shatterblast
I run a resolution of 1600 x 900, and the game goes off the screen somewhat. Can you make an adjustable resolution setting, or something similar, please?

I was trying to run this under Ubuntu Linux, so I have no idea what it looks like in Windows 7 or similar.

Re: Conquer Iceland v1

Posted: Tue Aug 20, 2013 1:07 pm
by Janywer
I just looked into your code a bit and erm ..

It would be far more efficent, if you'd make an use out of tables/loops.

Just an example:
(I'm not sure what the purpose of the function is, but I'll replicate its behaviour)

Your code:

Code: Select all

function vopnbyrjun()

   vopn1 = math.random(1, 2)
	vopn2 = math.random(1, 2)
	vopn3 = math.random(1, 2)
	vopn4 = math.random(1, 2)
	vopn5 = math.random(1, 2)
	vopn6 = math.random(1, 2)
	vopn7 = math.random(1, 2)
	vopn8 = math.random(1, 2)
	vopn9 = math.random(1, 2)
	vopn10 = math.random(1, 2)
	vopn11 = math.random(1, 2)
	vopn12 = math.random(1, 2)
	vopn13 = math.random(1, 2)
	vopn14 = math.random(1, 2)
	vopn15 = math.random(1, 2)
	vopn16 = math.random(1, 2)
	vopn17 = math.random(1, 2)
	vopn18 = math.random(1, 2)
	vopn19 = math.random(1, 2)
	vopn20 = math.random(1, 2)
	vopn21 = math.random(1, 2)
	vopn22 = math.random(1, 2)

    if vopn1 == 1 then
	    vopn1 = skjoldur
	else
	    vopn1 = exi
	end
	
	if vopn2 == 1 then
	    vopn2 = skjoldur
	else
	    vopn2 = exi
	end
	
	if vopn3 == 1 then
	    vopn3 = skjoldur
	else
	    vopn3 = exi
	end
	
	if vopn4 == 1 then
	    vopn4 = skjoldur
	else
	    vopn4 = exi
	end
	
	if vopn5 == 1 then
	    vopn5 = skjoldur
	else
	    vopn5 = exi
	end
	
	if vopn6 == 1 then
	    vopn6 = skjoldur
	else
	    vopn6 = exi
	end
	
	if vopn7 == 1 then
	    vopn7 = skjoldur
	else
	    vopn7 = exi
	end
	
	if vopn8 == 1 then
	    vopn8 = skjoldur
	else
	    vopn8 = exi
	end
	
	if vopn9 == 1 then
	    vopn9 = skjoldur
	else
	    vopn9 = exi
	end
	
	if vopn10 == 1 then
	    vopn10 = skjoldur
	else
	    vopn10 = exi
	end
	
	if vopn11 == 1 then
	    vopn11 = skjoldur
	else
	    vopn11 = exi
	end
	
	if vopn12 == 1 then
	    vopn12 = skjoldur
	else
	    vopn12 = exi
	end
	
	if vopn13 == 1 then
	    vopn13 = skjoldur
	else
	    vopn13 = exi
	end
	
	if vopn14 == 1 then
	    vopn14 = skjoldur
	else
	    vopn14 = exi
	end
	
	if vopn15 == 1 then
	    vopn15 = skjoldur
	else
	    vopn15 = exi
	end
	
	if vopn16 == 1 then
	    vopn16 = skjoldur
	else
	    vopn16 = exi
	end
	
	if vopn17 == 1 then
	    vopn17 = skjoldur
	else
	    vopn17 = exi
	end
	
	if vopn18 == 1 then
	    vopn18 = skjoldur
	else
	    vopn18 = exi
	end
	
	if vopn19 == 1 then
	    vopn19 = skjoldur
	else
	    vopn19 = exi
	end
	
	if vopn20 == 1 then
	    vopn20 = skjoldur
	else
	    vopn20 = exi
	end
	
	if vopn21 == 1 then
	    vopn21 = skjoldur
	else
	    vopn21 = exi
	end
	
	if vopn22 == 1 then
	    vopn22 = skjoldur
	else
	    vopn22 = exi
	end
end
My code:
Cut down from 156 to 6 lines and an exectution time which should be 30 to 45% faster

Code: Select all

local random = math.random

local function vopnbyrjun()
	local Environment = getfenv(2)
	for i = 1, 22 do
		Environment['vopn' .. tostring(i)] = random(1, 2) == 1 and skjoldur or exi
	end
end
The game itself is a very good idea and I love the graphic style :awesome:

Re: Conquer Iceland v1

Posted: Tue Aug 20, 2013 1:24 pm
by Robin
Even better, use a table instead of global variables:

Code: Select all

local random = math.random

local function vopnbyrjun()
	vopn = {}
	for i = 1, 22 do
		vopn[i] = random(1, 2) == 1 and skjoldur or exi
	end
end

Re: Conquer Iceland v1

Posted: Tue Aug 20, 2013 1:27 pm
by Janywer
Robin wrote:Even better, use a table instead of global variables:

Code: Select all

local random = math.random

local function vopnbyrjun()
	vopn = {}
	for i = 1, 22 do
		vopn[i] = random(1, 2) == 1 and skjoldur or exi
	end
end
That's not such a huge difference, as the environment is just a table after all.

It would (no doubt) be a better coding practice, but I'm not sure how he implemented those variables in the other parts of this code.

Re: Conquer Iceland v1

Posted: Wed Aug 21, 2013 1:53 am
by Mermersk
vladgalay wrote:Hello, Mermersk =)

Your game is quite good. I liked the drawn-like style of the graphics. It looks nice, and makes gameplay a little bit more comfortable :) Decorations, like clouds and ducks, fit the game's style very well. Background music and sounds are good. But i have some ideas, that probably, will make your game better =)

- Whole screen message, that informs, who's turn is now ( like <image of team>, your turn! ). Arrow, pointing at the team's icon looks fine, but when i played first time, it was hard for me to discover, who's turn is now =\
- Make possible to play with AI
- [looked in your code, sorry] Try to make a good use of arrays and loops. With them, your code will be much shorter =)

I like the original Risk game, and your game as well! Keep up the good work! =)
Thank you for the feedback! I thought that part(who's turn it is) was clear, but I guess that's what happen when you work on a thing for a long time :o: . Yes I will try to implement loops and arrays, it's unnecessary long now. Honestly I just have to learn how to use them, never done that before as I am rather new to programming.
shatterblast wrote:I run a resolution of 1600 x 900, and the game goes off the screen somewhat. Can you make an adjustable resolution setting, or something similar, please?

I was trying to run this under Ubuntu Linux, so I have no idea what it looks like in Windows 7 or similar.
Yes, I will try to do this. Maybe have the one that is now and one that is smaller so it will fit on laptops screens.
Janywer wrote:I just looked into your code a bit and erm ..

It would be far more efficent, if you'd make an use out of tables/loops.

Just an example:
(I'm not sure what the purpose of the function is, but I'll replicate its behaviour)

Your code:

Code: Select all

function vopnbyrjun()

   vopn1 = math.random(1, 2)
	vopn2 = math.random(1, 2)
	vopn3 = math.random(1, 2)
	vopn4 = math.random(1, 2)
	vopn5 = math.random(1, 2)
	vopn6 = math.random(1, 2)
	vopn7 = math.random(1, 2)
	vopn8 = math.random(1, 2)
	vopn9 = math.random(1, 2)
	vopn10 = math.random(1, 2)
	vopn11 = math.random(1, 2)
	vopn12 = math.random(1, 2)
	vopn13 = math.random(1, 2)
	vopn14 = math.random(1, 2)
	vopn15 = math.random(1, 2)
	vopn16 = math.random(1, 2)
	vopn17 = math.random(1, 2)
	vopn18 = math.random(1, 2)
	vopn19 = math.random(1, 2)
	vopn20 = math.random(1, 2)
	vopn21 = math.random(1, 2)
	vopn22 = math.random(1, 2)

    if vopn1 == 1 then
	    vopn1 = skjoldur
	else
	    vopn1 = exi
	end
	
	if vopn2 == 1 then
	    vopn2 = skjoldur
	else
	    vopn2 = exi
	end
	
	if vopn3 == 1 then
	    vopn3 = skjoldur
	else
	    vopn3 = exi
	end
	
	if vopn4 == 1 then
	    vopn4 = skjoldur
	else
	    vopn4 = exi
	end
	
	if vopn5 == 1 then
	    vopn5 = skjoldur
	else
	    vopn5 = exi
	end
	
	if vopn6 == 1 then
	    vopn6 = skjoldur
	else
	    vopn6 = exi
	end
	
	if vopn7 == 1 then
	    vopn7 = skjoldur
	else
	    vopn7 = exi
	end
	
	if vopn8 == 1 then
	    vopn8 = skjoldur
	else
	    vopn8 = exi
	end
	
	if vopn9 == 1 then
	    vopn9 = skjoldur
	else
	    vopn9 = exi
	end
	
	if vopn10 == 1 then
	    vopn10 = skjoldur
	else
	    vopn10 = exi
	end
	
	if vopn11 == 1 then
	    vopn11 = skjoldur
	else
	    vopn11 = exi
	end
	
	if vopn12 == 1 then
	    vopn12 = skjoldur
	else
	    vopn12 = exi
	end
	
	if vopn13 == 1 then
	    vopn13 = skjoldur
	else
	    vopn13 = exi
	end
	
	if vopn14 == 1 then
	    vopn14 = skjoldur
	else
	    vopn14 = exi
	end
	
	if vopn15 == 1 then
	    vopn15 = skjoldur
	else
	    vopn15 = exi
	end
	
	if vopn16 == 1 then
	    vopn16 = skjoldur
	else
	    vopn16 = exi
	end
	
	if vopn17 == 1 then
	    vopn17 = skjoldur
	else
	    vopn17 = exi
	end
	
	if vopn18 == 1 then
	    vopn18 = skjoldur
	else
	    vopn18 = exi
	end
	
	if vopn19 == 1 then
	    vopn19 = skjoldur
	else
	    vopn19 = exi
	end
	
	if vopn20 == 1 then
	    vopn20 = skjoldur
	else
	    vopn20 = exi
	end
	
	if vopn21 == 1 then
	    vopn21 = skjoldur
	else
	    vopn21 = exi
	end
	
	if vopn22 == 1 then
	    vopn22 = skjoldur
	else
	    vopn22 = exi
	end
end
My code:
Cut down from 156 to 6 lines and an exectution time which should be 30 to 45% faster

Code: Select all

local random = math.random

local function vopnbyrjun()
	local Environment = getfenv(2)
	for i = 1, 22 do
		Environment['vopn' .. tostring(i)] = random(1, 2) == 1 and skjoldur or exi
	end
end
The game itself is a very good idea and I love the graphic style :awesome:
Thank you for the feedback. :awesome: That code is to randomly generate if the image in an area is a shield or an axe. Yes your version looks much much cleaner, I'm going to try to rewrite some of the code, honestly I will first have to learn more about how your code works. :huh:
Janywer wrote:
Robin wrote:Even better, use a table instead of global variables:

Code: Select all

local random = math.random

local function vopnbyrjun()
	vopn = {}
	for i = 1, 22 do
		vopn[i] = random(1, 2) == 1 and skjoldur or exi
	end
end
That's not such a huge difference, as the environment is just a table after all.

It would (no doubt) be a better coding practice, but I'm not sure how he implemented those variables in the other parts of this code.
Thanks for the suggestion Robin, will try that also. Certainly looks a bit more simple.

Coding in the "function love.mousepressed(x, y, button)" was honestly the most time consuming, each time I wanted to make some change I had to go through it all again and change the same thing 22+ times. (for all the areas). Is there a way to make the code shorter there?

Edit #1 After some trying, and some success I have decided to leave the code as it is. I would rather use new techniques in my next Löve project :crazy: