Digital sweeper

Showcase your completed projects or get feedback about your work-in-progress

Digital sweeper

Postby wheene » Sat Apr 21, 2012 7:25 pm

This is just an early demo really, most functions are missing. But its already playable and I like to show off ;)
So get out there and sweep some mines soldier!

http://www.2shared.com/file/8OxYWgXR/mines.html

left mouse to uncover tile, right to set flag where you think the mine is (flag is not removable, but you can click it again to uncover the tile its on in case you think there is no mine under and just miss clicked the tile, also it is possible to set flag on already uncovered tile, that is bug, not feature, will fix soon)

-There is some stupid error that pops up anytime you drag the window or touch its borders. Just click ok and ignore it, doesnt cause any trouble. I think I know whats causing it, but havent managed to fix it yet.
- I need to add calculation of when the game is over.
- Will try to implement the mass uncovering of tiles (when you click emty tile, all adjecent empty tiles are uncovered and so on, just like in the original Sweeper).
- Better randomness.
- The code is very messy and system heavy now, because I calculate all before the game start, Ill try to rework it to calculate only whats needed on mouse click.
wheene
 
Posts: 28
Joined: Sat Feb 04, 2012 1:51 pm

Re: Digital sweeper

Postby Ivan » Sun Apr 22, 2012 6:57 am

Hi again. I like it so far.
I managed to find all mines so it's pretty much playable.
I don't think the code is slow, the game runs fine on my machine - but maybe it could be simplified a little bit.
Just some random feedback about your code:
-I don't think it's necessary to "detect mine counts around every field" during each tick of the timer. Doing this once at the beginning should be enough I think.
-The mouse press crash is caused by these lines:
Code: Select all
   mouse.xaxis > -128 and mouse.xaxis < 128 and
   mouse.yaxis > -128 and mouse.yaxis < 128 then

Since your window is 128 wide then its minimum and maximum bounds are (-64, -64) to (64, 64) where the center of the window is (0, 0):
Code: Select all
   mouse.xaxis > -64 and mouse.xaxis < 64 and
   mouse.yaxis > -64 and mouse.yaxis < 64 then

By the way, there is a simpler way (which doesn't require a loop) to detect which square the user has clicked on. Something like:
Code: Select all
local mapW, mapH = 8, 8
local squareSize = 16

local sqX = math.floor ( (mouse.xaxis + mapW * squareSize / 2) / squareSize )
local sqY = math.floor ( (mouse.yaxis + mapH * squareSize / 2) / squareSize )

-- check if clicked square is on the board
if sqX >= 1 and sqX <= mapW and sqY >= 1 and sqY <= mapH then


Regarding "mass uncovering of tiles" you may want to checkout the Flood Fill algorithm
Ivan
Site Admin
 
Posts: 415
Joined: Thu Dec 27, 2007 9:21 pm

Re: Digital sweeper

Postby wheene » Sun Apr 22, 2012 7:27 am

Thanks for the feedback! I didnt realize I had to divide the playfield restrictions by two, stupid mistake. I actualy dont count the possitions every tick and do it on the startup as you suggest. The tick part is there so that it can restart, notice the restart == 1 condition at the beginning of the tick function. Ill look into the flood fill soon, thanks for pointing that out to me.
wheene
 
Posts: 28
Joined: Sat Feb 04, 2012 1:51 pm

Re: Digital sweeper

Postby Ivan » Sun Apr 22, 2012 9:58 am

Code: Select all
The tick part is there so that it can restart, notice the restart == 1 condition at the beginning of the tick function

Agh, I must have missed that!

Just a small correction on the code that I posted:
Code: Select all
local sqX = math.floor ( (mouse.xaxis + mapW * squareSize / 2) / squareSize )
local sqY = math.floor ( (mouse.yaxis + mapH * squareSize / 2) / squareSize )

sqX and sqY will have values from 0 to mapW - 1 and mapH - 1 so you may have to add 1 to each:
Code: Select all
local sqX = math.floor ( (mouse.xaxis + mapW * squareSize / 2) / squareSize ) + 1
local sqY = math.floor ( (mouse.yaxis + mapH * squareSize / 2) / squareSize ) + 1


Anyways, keep it man, I like where you're going with your projects. :)
Ivan
Site Admin
 
Posts: 415
Joined: Thu Dec 27, 2007 9:21 pm

Re: Digital sweeper

Postby wheene » Wed May 02, 2012 8:44 am

Here be them mines. The FLOOD of joy FILLs our hearths.

http://www.2shared.com/file/y2W6CwYM/mines2.html

Last thing Id like to do with it is adding difficulties. That means sizes of grid, and for that I need to change window size. I tried with what I found in the documentation, but it doesnt work at all. Here is what I tried, could you help me with this please?

Code: Select all
display:create ( "My Window", 10, 10, 32, true )

displaySmall = DisplayMode ()
displaySmall.height = 10
displaySmall.width = 10

displayMedium = DisplayMode ()
displayMedium.height = 50
displayMedium.width = 50

displayBig = DisplayMode ()
displayBig.height = 00
displayBig.width = 200

keyboard.on_press = function ( keyboard, key )
   if key == KEY_Q then
   display:set_mode (displaySmall)
   end
   
   if key == KEY_W then
   display:set_mode (displayMedium)
   end
   
   if key == KEY_E then
   display:set_mode (displayBig)
   end

end   
wheene
 
Posts: 28
Joined: Sat Feb 04, 2012 1:51 pm

Re: Digital sweeper

Postby Ivan » Wed May 02, 2012 12:51 pm

Hi! Looks pretty cool so far. I almost managed to beat it. Just one small suggestion: users shouldn't be able to mark revealed squares as potential mines using the right mouse button. Other than that, seems to play just fine. :)

The reason why the code isn't working is because you have to set the 'windowed' property or the engine tries changing the resolution to fullscreen and fails (since no video card will support 10x10 res in fullscreen):
Code: Select all
    displaySmall.depth = 32
    displaySmall.windowed = true

This code is sort of long-winded and that's why a while ago I proposed removing the "DisplayMode" object changing the Lua API to:
Code: Select all
display:set_mode(resx, resy, depth, windowed)

It's not a big deal to work around this issue in Lua:
Code: Select all
display.set_mode2 = function(self, resx, resy, depth, windowed)
  local dm = DisplayMode()
  dm.height = resx
  dm.width = resy
  dm.depth = depth or 32
  dm.windowed = windowed or false
  display:set_mode(dm)
end

Then your code would become:
Code: Select all
keyboard.on_press = function ( keyboard, key )
   if key == KEY_Q then
   display:set_mode2 (10, 10, 32, true)
   end
   if key == KEY_W then
   display:set_mode2 (50, 50, 32, true)
   end
   if key == KEY_E then
   display:set_mode2 (200, 200, 32, true)
   end
end
Ivan
Site Admin
 
Posts: 415
Joined: Thu Dec 27, 2007 9:21 pm

Re: Digital sweeper

Postby wheene » Mon May 07, 2012 11:44 am

It is Alive !

http://www.2shared.com/file/t9dW6qFo/mines3.html

Start by choosing difficulty in the menu. Game will start, you can always restart it by pressing R (same difficulty), or go back to menu by pressing Q. In the menu you can then change difficulty or press Q again to quit.

And a taste of things to come (move W,A,S,D shoot Space)

http://www.2shared.com/file/o3ZY48_n/storm.html
wheene
 
Posts: 28
Joined: Sat Feb 04, 2012 1:51 pm

Re: Digital sweeper

Postby Ivan » Tue May 08, 2012 7:48 pm

Hi! Not bad at all. I managed to beat it on the smallest board. It plays fine, however I noticed that on the largest board sometimes the game hanged for 4-5 seconds before revealing an area of squares. As a fellow programmer, this makes me want to optimize your flood-fill algorithm but anyways it doesn't affect the gameplay that much, so it's not a big deal. :)
Keep it up man, looking forward to the shmup thingy you have in the works!
Ivan
Site Admin
 
Posts: 415
Joined: Thu Dec 27, 2007 9:21 pm

Re: Digital sweeper

Postby wheene » Wed May 16, 2012 7:57 am

Here is the optimized file with the last bugfix. All works like a charm now. Should you encounter any bugs please tell me so I can fix it.

http://www.2shared.com/file/1VDoqs2J/mines3.html

replace the old mines3 file with this new one
wheene
 
Posts: 28
Joined: Sat Feb 04, 2012 1:51 pm

Re: Digital sweeper

Postby Ivan » Fri May 18, 2012 11:36 am

Works way faster than before!
Again, pretty cool game. I beat it on "easy" a few times. :) Nicely done.
Ivan
Site Admin
 
Posts: 415
Joined: Thu Dec 27, 2007 9:21 pm


Return to Showcase

Who is online

Users browsing this forum: No registered users and 0 guests

cron