Page 1 of 1

Video puzzle

Posted: Sun Jun 19, 2016 12:10 am
by Xugro
Hi folks,

I made a small and buggy video puzzle game. The goal is to drag and drop the pieces into the right position. The problem: the content of the puzzle pieces is changing :D.

To play the game you have to drag and drop a ogg-theora video into the game. You can find a small one (~15MB) here:
http://lachy.id.au/log/2007/06/webjam3

Known problems:
  • It sometimes crashes.
  • It does not like non video input.
  • Videos bigger than 800x600 are problematic.
  • It lags sometimes (on my machine).
Have fun!

Edit: The new version works without problems.

Re: (buggy) video puzzle

Posted: Sun Jun 19, 2016 7:02 am
by 4aiman
This is COOL!!!!!!!!!!

Known problems:
  • Video does not loop
  • It lags sometimes
  • Clicking outside any piece crashes the game (100%): you need to add extra check on line #83:

    Code: Select all

     if pos[active_piece] then
  • Videos larger than 60Mb are problematic
Keep it up!

Re: (buggy) video puzzle

Posted: Sun Jun 19, 2016 11:24 am
by Ranguna259
This is actually pretty funny, even more if we use the video that you posted :P
But it is really slow and produces a lot of errors, I tried to tackle a few of them.
video thing.love
(1.92 KiB) Downloaded 171 times
With this version I fixed:
  • A bug when the player pressed on the screen before the video had been loaded.
  • Another bug when the player tried to press on a place with no pieces.
  • The lag problem.
Please unpack the .love file and search for lines that start with:

Code: Select all

--C
They are comments that I wrote so you can see what you did wrong.

You could also use less globals. Maybe organize all the variables inside a local table ?
Other than that, the code looks good, the snapping function is cool.
Anyway, this is really funny, keep it up. :nyu:

Re: (buggy) video puzzle

Posted: Sun Jun 19, 2016 2:02 pm
by 4aiman
One more thing: a check for a stream format should be added. I.e. the app crashes when a wrong file format is dropped into it.

Re: (buggy) video puzzle

Posted: Mon Jun 20, 2016 2:31 am
by pgimeno
Very cool idea, nice work!
4aiman wrote:Known problems:
  • Video does not loop
That's arguably a feature: if the video ends, your time is up :)

A problem I've found is that if all pieces are locked, but some are in wrong positions, it won't let you rearrange them to fix that. EDIT: Found why. The condition of win() should be amended by replacing the 'and' with an 'or', and swapping i and j after it. So, 'and (pos[(j-1)*number_of_rows+i][2]' becomes 'or (pos[(i-1)*number_of_rows+j][2]'

I've taken a look at the code. I was surprised that it used canvases instead of quads. I was told that switching canvases is a costly operation.

Re: (buggy) video puzzle

Posted: Sun Dec 25, 2016 7:57 pm
by Xugro
Here is a new and faster version of the code. Take a look at the source if you like. The code should be easy to read.
4aiman wrote:One more thing: a check for a stream format should be added. I.e. the app crashes when a wrong file format is dropped into it.
That is still a thing I do not know how to do. Take a look at line 22 of main.lua. That's the best I could do, but even that does not work. Does anybody have a tip for me?

Re: (buggy) video puzzle

Posted: Sun Dec 25, 2016 10:45 pm
by bob_fossil
Xugro wrote:That is still a thing I do not know how to do. Take a look at line 22 of main.lua. That's the best I could do, but even that does not work. Does anybody have a tip for me?
The following function does some basic sanity tests to the file object you get from love.filedropped to see if it is in the supported format:

Code: Select all

function is_theora(file)

	local ok = false

	if not file then
		return ok
	end

	local filename = file:getFilename()
	-- Check for file ending with '.ogg'
	if not string.match(filename, ".+%.ogg$") then
		return ok
	end
		
	if file:open("r") then
		-- Read in the header.
		local header_size = 35
		local data = file:read(header_size)
		if #data==header_size then
			-- https://en.wikipedia.org/wiki/Ogg#File_format
			--
			-- Got expected header size.
			-- Get the magic number 'OggS' at offset 0.
			local magic = string.sub(data, 1, 4)
			-- Get the segment table at offset 28.
			-- Should be 'theora'.
			local segment = string.sub(data, 30, 36)
			if magic=="OggS" and segment=="theora" then
				ok = true
			end
		end
		file:close()
	end
	
	return ok
end
So you could call this function inside love.filedropped to verify the video file. Seems to work with the video file in the first post. You still need to make some changes or display an error message if an incorrect video file is dropped onto the window.

Re: (buggy) video puzzle

Posted: Mon Dec 26, 2016 9:07 am
by Xugro
bob_fossil wrote:The following function does some basic sanity tests to the file object you get from love.filedropped to see if it is in the supported format:
Thank you very much! :)

I hoped that there was an easier way to check this, but your solution should work pretty good.
bob_fossil wrote:You still need to make some changes or display an error message if an incorrect video file is dropped onto the window.
Done! :)

Re: (buggy) video puzzle

Posted: Mon Dec 26, 2016 11:02 pm
by bob_fossil
Xugro wrote:Thank you very much! :)

I hoped that there was an easier way to check this, but your solution should work pretty good.
You're welcome. Perhaps you can change the title of this thread now? :)

Re: (buggy) video puzzle

Posted: Tue Dec 27, 2016 1:29 pm
by Xugro
bob_fossil wrote:Perhaps you can change the title of this thread now? :)
Done! :)

And I updated the first post to contain the newest version.