Mini LD#40 – Struggling with webcam input

Posted by
February 25th, 2013 9:26 am

I’ve been crashing and burning hard on my goal to create 25 games this year (made plenty of prototypes on schedule but always seem to run out of steam when it’s time to make the game look like more than a bunch of colored rectangles), so I hoped that Mini LD#40’s smaller time limit might help me with Game #4. I’m calling it Hell Terror Cave of Darkness.

You play as a guy who fell in a dark cave and have to escape by moving and jumping, but the cave is filled with ghosts and monsters. You die if you come into too much contact with either one. The only way to kill/repel ghosts is to turn on your flashlight–which will be controlled via webcam input! (Monsters will avoid you in the dark but are agitated by light and will attack.) Controls are WASD and a light source, or a light source and arrow keys depending on your handedness. A lamp, an iPhone, a bike light, anything will do. (Alternately, if you’re playing in a bright room, you could shade the camera with your hand to control the darkness.) Is it unwieldy? Probably, but it gives me an excuse to learn about coding with webcams! I’ve learned something every time I tackle a weird, ambitious prototype.

I wrote some code using Pygame and VideoCapture that detects light concentrated into the center of the camera using a brightness formula, and built a game world that lights up and darkens accordingly. My problem is that the webcam operations and character movement don’t mesh well–the game grinds to an unplayable standstill whenever the webcam is running, regardless of whether or not the video is actually displayed on screen, regardless of the rate at which brightness is calculated from the webcam, and regardless of the amount of player input.

I’ve tried adjusting the number of pixels analyzed, the frequency of the analysis, etc., but this problem is really stumping me. I can’t figure out if my crappy notebook PC is part of the problem, and I’m not sure how to tell the webcam to run in a more conservative manner.

I’ve made a good run at this Mini LD, but time is running out fast and I might have to abandon ship if I can’t sort this problem out soon.


3 Responses to “Mini LD#40 – Struggling with webcam input”

  1. spokenbluntly22 says:

    Did you figure it out??

Leave a Reply

You must be logged in to post a comment.

[cache: storing page]