|
Title: Two cars, one table (0.3) Post by: caribou on February 07, 2011, 02:36:05 PM (http://i.imgur.com/H5rn0.png)
(non-projected version) Player 1 : UP = UPARROW LEFT = LEFTARROW RIGHT = RIGHTARROW DOWN = DOWNARROW FIRE = P Player 2 : UP = T LEFT = F RIGHT = H DOWN = G FIRE = W PAUSE = DEBUG > collision lines + fps + / - = Scale the cars, physics is not scaled You can use your own map 640*480 / PNG Download 0.3 (http://solidfiles.com/d/4e57a/) ------ Hello, I didn't intend to participate to this jam since i'm on another project but i stumbled upon this video (http://www.youtube.com/watch?v=oxjGRL7ZiLE). I find this idea awesome, so i started to play with some libraries a few days ago to see if that was doable in python and finally i'm having a "working" rough version of it playing on a static image, I have to make some serious tests with my webcam tomorrow with some proper lightings. I'll put some screenshots tomorrow. The versus part will be a kind of mariokart battle. As you may have noticed, the gameplay is not going to be original but the fun part for me is coding it and having cars moving around my table. :durr: Title: Re: Two cars, one table Post by: LiquidAsh on February 07, 2011, 03:01:41 PM That video is awesome. I already have a projector hanging from my ceiling, so I'll definietely have to play around with some similar concepts after the versus competition.
Title: Re: Two cars, one table Post by: sepharoth on February 07, 2011, 07:11:33 PM Hello, "screenshots" :biglaff:I didn't intend to participate to this jam since i'm on another project but i stumbled upon this video (http://www.youtube.com/watch?v=oxjGRL7ZiLE). I find this idea awesome, so i started to play with some libraries a few days ago to see if that was doable in python and finally i'm having a "working" rough version of it playing on a static image, I have to make some serious tests with my webcam tomorrow with some proper lightings. I'll put some screenshots tomorrow. The versus part will be a kind of mariokart battle. As you may have noticed, the gameplay is not going to be original but the fun part for me is coding it and having cars moving around my table. :durr: If you actually get this working, I will instantly worship you as god tier. Title: Re: Two cars, one table Post by: tzachs on February 08, 2011, 04:43:04 AM That video was beyond awesome!
I'm thinking that instead of racing, this technology can also make for an awesome multiplayer platformer, where the characters can jump on the objects and shoot down on the other characters, etc.. Title: Re: Two cars, one table Post by: caribou on February 08, 2011, 04:15:40 PM Day 1 : Exploring
The first day was mostly looking at tutorials and documentation about OpenCV, the library i'm using. It contains a lot of algorithms to process images/videos. Day 2 : Digging I found that i needed to use the Canny algorithm, here what i finally got on a static image : (http://i.imgur.com/IKCue.png) It looked ok at this time so the next step was to make a collision detection algorithm, i actually just looked for some point to square collisions. Day 3 : Fun (http://i.imgur.com/mANn2.png) I finally put a car (not my sprite) and some physics. As you can see, the car corners were at the original image position, driving between the pen and the lighter was tricky. So i fixed that corner thing and improved the smoothing collision algorithm. Day 4 : Facepalm Time to use the webcam. At first i was really enthusiast : I drew a track on some paper. (http://i.imgur.com/D3OEA.png) I got into some issues, since i had to scale down my car, the collision detection became really inaccurate because my -small- car went through these points, things which didn't happened before. And i'm not even talking about the bottom left corner of this picture, i guess my excuse is that it was too blurry for a nice recognition but still there were too many spots like that so i thought about considering those points as segments. I made a representation of it. (http://i.imgur.com/5Ctf5.png) It's stupid of course i was just iterating through a simple list of points, i couldn't make a collision detection with these long segments between the shapes then. I spent some time looking for another algorithm until i noticed that i should have rtfm better. OpenCV actually returns a sequence instance, from which you can use those nice methods h_next() and v_next() : h_next() jump to the next list of points on the same level and v_next() to the next level, the inner shape for example. (http://i.imgur.com/na5Xs.png) I'm quite happy with the result (even with this ugly bottom left corner). I just finished the rectangle to segment collision algorithm i'm now working on smoothing things a bit and handling collisions car behaviours. Now the facepalm part. Two things :facepalm: : - The screen i put on my video projector has an electronic piece missing. - I didn't notice one important thing since i don't work with a projector, the projected image will contain the car which is going to be captured by the webcam and detected as collision points preventing the car from moving. Those are the ideas i went for :
I'd love to contact the guy from the video to know how he handled this thing. I don't have a projector right now so it's going to be hard to debug, i'm looking on internet for an order of that missing piece hoping that the delays won't be too long. I still have time to make some researches about it but if it's getting too hard / too long i will stick on a non projected version for this competition, maybe with a kind of paint as a map editor. But the projector version will still be my main goal, i can't stop fantasizing on those kind of tables. (http://i.imgur.com/kLCRn.jpg) :-* Title: Re: Two cars, one table Post by: caribou on February 14, 2011, 09:58:17 AM Day 5 & 6 : Another one
I've added another collision detection layer on top of the previous one. (http://i.imgur.com/fSEqv.png) When there's a collision between the bounding boxes the 2nd collision detection algorithm is called which is basically about testing if the car is below or above the line, if not there's a collision. DAY 7 & 8 : Looking for a nice collision response. I didn't expect this part to be that painful, here is what i wanted to do: (http://i.imgur.com/z1Awd.png) I needed this green line. I was making line equations and atan stuff until i found that there were too many steps/greedy functions in that approach. Day 9 & 10 : R = V + 2N((-V).N) Vectors of course :facepalm: and especially this formula : R = V + 2N((-V).N) R is that green vector, finally. V is the car vector. N is the normal vector to the wall (also) red line. I found it via this pdf (http://docs.google.com/viewer?a=v&q=cache:xzTgMHFGEJsJ:www.cs.sjsu.edu/~teoh/teaching/previous/cs134_sp07/lectures/Lecture11_CollisionResponse.ppt+%22collision+response%22+%2Bprojection&hl=en&pid=bl&srcid=ADGEESikqjmOp3dWtX3Zi9lqP6tsdXq2y_326j2SstciKGKnnynoCFbUPO5lO0J9fkTCUCE3_XScjQ2UDOlS8GcHL1tmkidcgykRFJdpNpLMK2bwIoK9kIEnPUMhcwIRmrPaOHKpGoKC&sig=AHIEtbRdU4nlf_gATRlW7XC10w97bCCCWQ&pli=1). It's not enough. Even if i've got all the datas to make an accurate collision response (and i don't need that) I still have to make it smooth. What i did is saving my car position before looking for a collision, if a collision happens i apply the response vector to that old car position which makes the car pop back. Actually i could apply a smoothing algorithm, that would be fine but i'm having an issue : my car goes through the walls sometimes, i guess that it's a basic problem where the moving object make some too big steps and therefore didn't really notice the object between the two positions. I'm gonna check for an intersection between the actual position of my car and the old position. I shouldn't be able to drive through walls anymore and i could use that intersection point as a start for the response vector, making the thing a lot smoother. Title: Re: Two cars, one table Post by: X3N on February 16, 2011, 09:24:18 AM Enjoying the dev log.
Related: the game where you draw hills on a planet and an astronaut collects them (Link anyone?) Title: Re: Two cars, one table Post by: mikewest on February 16, 2011, 10:38:02 AM This looks seriously fantastic in concept. I wish you the best with the snags along the lines of implementation. Also, seconded to the great devlog comment. Cheers.
Title: Re: Two cars, one table Post by: charlestheoaf on February 16, 2011, 11:20:43 AM This looks pretty cool! The next time I go to visit the distant relatives with a projector, I'll take my computer a this game with me :handthumbsupR:
Title: Re: Two cars, one table Post by: caribou on February 18, 2011, 03:05:51 PM Thanks for the encouragements ! And especially at this time of the dev since i'm having boring issues with divisions by zero and floating numbers. :beg:
I'm on fixing these problems right now hoping it will be fine for monday, after that i'll dive into the game mechanics. If i'm on time this game will be very, very basic. Next devlog sunday, i hope. Title: Re: Two cars, one table Post by: caribou on February 26, 2011, 04:18:27 PM I had to pause the dev of this game for some webdesigning on a project which isn't mine, i already had a ridiculous amount of work to match the deadline so that's even worse now. But well, that was already too big from the beginning so i guess removing a few more features is not that painful.
Is making a car going backward a feature ? Day 11,12,13 : DOT PRODUCT !!!!!!!!!!!!!!!! These three days were mainly about looking for the right collision algorithm and implementing it. As you can see on the screenshots in the previous posts my obstacles are actually not plain shapes but just some segments, a lot of tiny segments. So here is the problem : (http://i.imgur.com/5VHsd.png) Since i'm just using a basic collision system, meaning "if car overlap segment then..." if my car is moving too fast, the steps start to be too big for my car to actually overlap that segment, it jump over like if there was nothing (B). So i'm keeping each position as an (oldx,oldy) variable in order to build a segment between (x,y) and (oldx,oldy). Then i just have to check if there's a collision between the two segments, the one from the obstacle and the one from my car. I dumped my shining three-level collision algorithm for a new one. I found one and spent too much time implementing it, i almost pasted it. It ended up not working and after a lot of debugging i decided to give up and try another simple-that-i-can-understand-algorithm. There's one called "the sweep line" :eyebrows: resource1 (http://cs.nyu.edu/~icpc/wiki/index.php/Polygonal_Intersection), resource2 (http://www.lems.brown.edu/~wq/projects/cs252.html). I didn't feel that one much. Another one is called SAT, Separating Axis Theorem and after googling a lot i want to point you that awesome tutorial (http://www.codezealot.org/archives/55) if you don't know it, resource2 (http://www.sevenson.com.au/actionscript/sat/). (http://i.imgur.com/d2Dil.png) That's pretty simple, you project each edge of your polygon on every axis (actually normals) and if each of your projections overlap, then there's a collision. I only have some segments so that was even easier to implement. (http://i.imgur.com/TKhOZ.png) Normal in red, projected points as white squares. Day 14 : d-1 almost the beginning I actually work with 3 files, my game, a simple version of it with a static list of points and an even rawer version, for debugging purposes. Part of this day was to move the update upwards, from file3 to file1 with all the stupid bugs in the way. How rewarding it was when i saw the stuff work as expected (file2) and how depressed i was a few minutes later when i saw it in the actual game (file1). My car still moved through the walls sometimes, a lot less than before but the game just can't be played that way. I think i would have given up if i hadn't found the solution in the next hour : (http://i.imgur.com/dCX32.png) The car starts at red circle, in direction of red vector and collides with the wall. A collision response is made : blue vector. It says, go to that arrow position, assuming that since it's a collision response that's valid but in that case it isn't, the car is behind the obstacle. That's actually hard to spot those kind of events since i'm having some really really small segments. So i'm making two collision detections : a first one when my car just collides an obstacle and another one with the position of the collision response from detection1 and saying that if my car is colliding again (on second collision detection) go back to the position before everything happened. That's not really elegant but it works. Todo : - Game mechanics ? (http://i.imgur.com/iZD0h.png) (rockets) - Finish that collision stuff, there's some rare cases where the car still go through obstacles, those cases are, i think, not dependant of my programming but i have a simple idea to fix it. - Stop using "since" in every sentence. I guess you have all heard of the algorithms i'm talking about. My intention is not to teach anything to anyone, i'm actually new at game programming and i'm just doing it for the sake of the devlog. Ok so at this time of the post i have 23 hours left until the deadline, LOCAL TIME. I don't even know how time i officially have. So 23 hours without sleeping and i'm going in my bed right now which means 14 hours. (http://youoffendmeyouoffendmyfamily.com/wordpress/wp-content/uploads/2011/02/Challenge-accepted.png) Just self-motivating. Title: Re: Two cars, one table Post by: sepharoth on February 26, 2011, 05:07:34 PM If you're going non-projector, I think it would still be cool to be able to give the game some random image off my hard drive to play as a map.
Title: Re: Two cars, one table Post by: caribou on February 27, 2011, 06:20:10 AM Ok I'll try to do that. :ninja:
I read more and more posts saying that they aren't going to meet the deadline. (http://i.imgur.com/iwkVF.jpg) Title: Re: Two cars, one table Post by: caribou on February 28, 2011, 01:28:24 AM Phew i've never coded that much in a row, almost 24 hours. :durr:
I wanted to meet the deadline so i skipped my night but i didn't expect to have a problem when making an *.exe, just at the end ! I just asked for help on stack overflow we'll see... So you'll have the half version of my game meaning only using a static picture. There's still some collision bugs, the collision response really sucks so don't try to slide on the walls much. I'll describe the thing later now i'm going to bed. I'm not adding my game to the finished projects thread since it's buggy, if tomorrow is still ok, maybe i'll add it. (http://i.imgur.com/H5rn0.png) Player 1 : UP = UPARROW LEFT = LEFTARROW RIGHT = RIGHTARROW DOWN = DOWNARROW FIRE = P Player 2 : UP = T LEFT = F RIGHT = H DOWN = G FIRE = W PAUSE = DEBUG > collision lines + fps You can use your own map 640*480 / PNG If the game is too slow it's certainly because that's badly coded but you can also try some simpler shapes. If you're using a really detailed image your fps will drop really quickly. WEBCAM MODE is crashing right now. 2 Cars, 1 Table 0.1 (zip) (http://solidfiles.com/d/7727/) Title: Re: [EARLY BUILD] Two cars, one table (0.1) Post by: caribou on March 01, 2011, 03:45:59 AM Ok i guess i won't add my game, i don't know how to fix the issue i'm having when exporting. :<
I'll try to add sounds for the next release though. Title: Re: [EARLY BUILD] Two cars, one table (0.1) Post by: caribou on March 01, 2011, 04:45:31 PM Ok no sound actually... Does anyone have some idle-engine-sound-loop ?
...But i finally managed to ship my game correctly, the webcam is now working ! I've found a bug with the collision response (again) this will be for the next release. Download Two cars, one table 0.2 (http://solidfiles.com/d/417c/) Title: Re: [Webcam working] Two cars, one table (0.2) Post by: caribou on March 02, 2011, 07:21:58 AM 0.2 is actually the same as 0.1...
The thing is that if you're playing with webcam enabled and quit the game, it will actually stay in your processes because I was not releasing the webcam capture. I fixed it in this version. Download 0.2.1 (http://solidfiles.com/d/b5b7/) Title: 0.3 Post by: caribou on March 05, 2011, 02:38:33 AM Ok, i lost motivation so here is the "last" update.
- FIXED an error when you're quitting the game while in the menu - FIXED a big bug in the collision response - you can drive backward faster Download 0.3 (http://solidfiles.com/d/4e57a/) Actually the real last thing i should add is a race mode, right now the battle mode is totally boring. I learned a lot from this jam, - Dead lines are great for motivation : i think i've made almost half of the game during the last 24 hours. The problem is that it's very hard to simulate this kind of pressure when there's no jam around :S - Premature optimization blablabla : related to above, and even if every programmer knows that thing i actually really experienced it in this jam, my code is ugly but at least i didn't spent hours on a stupid menu or trying to find the best way to implement an algorithm... - Vectors and the maths around it : i don't like to make some technical stuff much but when you do math with a game in mind it's almost fun. Also when performances are needed use vectors instead of trigonometry. An interesting article about the fastest way to find a distance between two points (http://www.emanueleferonato.com/2010/07/29/the-fastest-way-to-find-the-distance-between-two-points/). |