Page 1 of 1

SquareZ

Posted: Tue Sep 08, 2015 4:57 am
by Xyore
You've probably heard of this game. Does Picross ring a bell? Or more obscurely, CubeMania, that homebrew game for the PSP.

Well, this is pretty much that.

What makes this special, at least for me, is that this game was made from scratch without knowledge in how to make these types of games. If there's one thing I'm (sort of) good at, it's reverse-engineering games. Even if just small, basic games.

That's enough about me. Why not give it a shot? It's free! And if you have any feedback, awesome!

Note: I made this on a small lil' laptop and for some reason it ran pretty slow at times (game freezing,input lag, etc.), so I'm not sure if it's just me or the game. If anyone can figure it out for me, I'll highly appreciate it.

Edit: v1.1 comes with the following changes:
- changed the way the game checked if you won to account for multiple solutions
- small optimizations
- font changes
- grid size indicator
- other small stuff

Re: SquareZ

Posted: Tue Sep 08, 2015 5:50 am
by arampl
1. love.graphics.setNewFont can be bottleneck here. Check warning (yellow background) on its Wiki page. You should create all fonts in love.load and use love.graphics.setFont later on.

2. love.graphics.getWidth / love.graphics.getHeight don't need to be called from love.update. Use love.resize event.
And use love.mousemoved event to get mx & my (exists since LÖVE v. 0.9.2).

3. love.graphics.setBackgroundColor(bgColor) can also be called only once from love.load.

To summarize all this info - move all unnesessary stuff from love.draw & love.update to other events.


4. You don't need setBorder at all. Again, love.graphics.setLineWidth goes to love.load and change loop in love.draw to:
EDIT: I'm wrong here.

Code: Select all

	for i=1,gridSize do
		for j=1,gridSize do
			if player[i][j] == 1 then love.graphics.setColor(tileColor)
			else love.graphics.setColor(bgColor)
			end
			x, y, w, h = gx+(i-1)*(gs/gridSize),gy+(j-1)*(gs/gridSize),gs/gridSize,gs/gridSize
			love.graphics.rectangle("fill", x, y, w, h)
			love.graphics.setColor(txtColor)
			love.graphics.rectangle("line", x, y, w, h)
		end
	end
5. Study and make use of canvases. This way you don't need to redraw each cell (until resize occures).

EDIT: I can also recommend never use "magic numbers" like 800, 600 right in the code. Use variables with meaningful names. It applies to any programming language.

Re: SquareZ

Posted: Tue Sep 08, 2015 10:24 am
by rmcode
For some reason I expected a zombie survival game with cubes :D

A small issue I found: When you open the help with F1 and press escape the game will close after your press 'OK' on the help panel.

Re: SquareZ

Posted: Wed Sep 09, 2015 5:08 am
by Xyore
rmcode wrote:For some reason I expected a zombie survival game with cubes :D

A small issue I found: When you open the help with F1 and press escape the game will close after your press 'OK' on the help panel.
I don't think I'm able to fix that as love.window.showMessageBox() is a built-in function.
arampl wrote:1. love.graphics.setNewFont can be bottleneck here. Check warning (yellow background) on its Wiki page. You should create all fonts in love.load and use love.graphics.setFont later on.

2. love.graphics.getWidth / love.graphics.getHeight don't need to be called from love.update. Use love.resize event.
And use love.mousemoved event to get mx & my (exists since LÖVE v. 0.9.2).

3. love.graphics.setBackgroundColor(bgColor) can also be called only once from love.load.

To summarize all this info - move all unnesessary stuff from love.draw & love.update to other events.


4. You don't need setBorder at all. Again, love.graphics.setLineWidth goes to love.load and change loop in love.draw to:
EDIT: I'm wrong here.

Code: Select all

	for i=1,gridSize do
		for j=1,gridSize do
			if player[i][j] == 1 then love.graphics.setColor(tileColor)
			else love.graphics.setColor(bgColor)
			end
			x, y, w, h = gx+(i-1)*(gs/gridSize),gy+(j-1)*(gs/gridSize),gs/gridSize,gs/gridSize
			love.graphics.rectangle("fill", x, y, w, h)
			love.graphics.setColor(txtColor)
			love.graphics.rectangle("line", x, y, w, h)
		end
	end
5. Study and make use of canvases. This way you don't need to redraw each cell (until resize occures).

EDIT: I can also recommend never use "magic numbers" like 800, 600 right in the code. Use variables with meaningful names. It applies to any programming language.
1. For some stupid reason, I wasn't aware of love.graphics.setFont(). Thanks for reminding me.

2. Actually, love.resize() is only called when love.window.setMode() is set to an unsupported width/height. So I have to leave it as is, unfortunately.

3 & 4. More stupid mistakes of mine. Thanks again. :D

5. I won't implement a canvas for this little project as it would involve reworking a lot (especially since I have no idea how to use canvases yet). I'd rather wait until my next project so that I may learn it properly.

The changes have been made and the attached game has been updated. Thanks for trying it!

Re: SquareZ

Posted: Thu Sep 10, 2015 9:45 pm
by pel
How do you play?

When I press F1, it crashes:

Code: Select all

Error

main.lua:106  attempt to call field 'showMessageBox' (a nil value)

Traceback

main.lua: 106 in function <main.lua:97>
[C]: in function 'xpcall'

Re: SquareZ

Posted: Fri Sep 11, 2015 3:55 am
by zorg
pel wrote:main.lua:106 attempt to call field 'showMessageBox' (a nil value)
Use 0.9.2, since the message box was added in that release of löve.
Edit: Tested and worksforme on win7... dunno then.

Re: SquareZ

Posted: Fri Sep 11, 2015 4:22 am
by pel
Use 0.9.2, since the message box was added in that release of löve.
I am. 0.9.2 for OS X Yosemite.

Re: SquareZ

Posted: Mon Sep 14, 2015 8:07 am
by Xyore
pel wrote:
Use 0.9.2, since the message box was added in that release of löve.
I am. 0.9.2 for OS X Yosemite.
Well, I just tested it on a Mac laptop with the mac build which can be found here: http://xyore.itch.io/squarez

Feel free to try that one.