Welcome to my Programming Blog...

I am currently working on a couple of projects: An original game called "Implosion" which I am porting from Flash to the iPad, and a remake of Q*bert in Python (pygame), as part of the class I am teaching. Please feel free to use the "Labels" (at right) to follow a specific project or theme. If you are one of my Python students, I recommend that you check out the Python thread.

Tuesday, May 11, 2010

Platforms

A late update on the Q*bert front - yesterday, I got the platforms working - Q*bert can land on one of them and they will carry him to the top of the screen. It's working surprising smoothly. Next up - I need to create a green guy who jumps down the pyramid like the balls do and resets the cubes' colors. I also need to start thinking about how I will manage levels....

Saturday, May 8, 2010

It's always the little things....

As you may know, I am trying to teach myself two things at once for this iPhone App I am working on - blender, and the SIO2 code library that lets me put blender objects on the iPhone screen. (Actually, I'm aiming for the iPad.)

I've been wanting to make my 4-square selector shapes be translucent - that is, I'd like for them to have an Alpha level of about 50% or so. They will mostly appear behind the Chips, but when a chip drops, I'd like it to be seen, and there may be some artwork behind the chips that is important, also.

I watched the SIO2 tutorial #4 several times, and I even found a correction to the tutorial online since the tutorial hasn't kept up with a few updates. But even though I was doing what the tutorial said, I couldn't get objects to show up with any kind of transparency. I'd create an object that was opaque, and it would show up fine. I'd switch the color blending mode in blender to "Value" or (the new version) "Color," and it would disappear when I tried to view it in the iPhone simulator. What gives?

I was just about to start complaining that the Tutorial didn't work, the support forums weren't very helpful and the only book on SIO2 wasn't much help, when I realized that I hadn't actually looked in the book for this... sure enough, a quick peek in the index led me to a page that indicated the problem wasn't in Blender - it was a one line change I needed to make in my code in XCode. I was only rendering solid objects - I needed to tell it to render the solid objects and the objects with alpha transparency. I needed to change:

sio2ResourceRender( sio2->_SIO2resource, sio2->_SIO2window, 
                        sio2->_SIO2camera,
                        SIO2_RENDER_SOLID_OBJECT |
                        SIO2_RENDER_LAMP);

to

sio2ResourceRender( sio2->_SIO2resource, sio2->_SIO2window, 
                        sio2->_SIO2camera,
                        SIO2_RENDER_SOLID_OBJECT |
                        SIO2_RENDER_ALPHA_TESTED_OBJECT |
  SIO2_RENDER_TRANSPARENT_OBJECT|
    SIO2_RENDER_LAMP);

and everything instantly started working. Sigh.

Thursday, May 6, 2010

Platforms

I'm working on creating the two hovering platforms that sit on either side of the pyramid and carry Q*bert to the top of the pyramid if he jumps on them. Not too much to show for it right now, though. I am borrowing a lot from the Cubes - so that I can position the platforms the way I would a cube and so I can detect when Q*bert has landed on one.

The other thing I am doing is going back and reviewing whether I am documenting my functions. I realize that I have been a little sloppy, making up functions without putting leading comments before them to remind me what they do. And that's not setting a very good example!

starting with the four-squares

I need to find a way to make a shape that selects four of these chips. The shape is like a Tetris piece. Since this only glides around, it can be a 2-D piece. I could simply make a solid shape, but I have two problems with that - first, that it affects the visibility of at least one of the five chips I have already made, and second, that I am having trouble adjusting the opacity, so I can't see the chips fall behind it. (Or the status of the squares it covers, which will also be important.)
The other option is an outline of the shape - I am playing with either a very sharp-cornered shape, like the one at right, or a more rounded one, like the one at left.
In either case, I think they hug the green box a bit much, but I rather thought that shape was a little large, anyway. I'm not really thrilled with either option, so far.
In any case, I am learning more about blender as I experiment with the program. Now if I could just remember how I was able to create a mesh by clicking where I wanted points, rather than adjusting an existing shape....

Monday, May 3, 2010

... Foiled again!

If you are not familiar with the game of Q*bert, you may not know that he has a bit of a potty mouth. In the game, when he gets hit by a ball or enemy, a speech balloon appears above his head with some curse characters, and a sound file plays that is sort of a grumble. I have the visual part of it working now, when he gets hit by a ball.
I don't have the snakes getting him yet, just the balls - but it shouldn't be too hard. I wonder, though, whether the snakes will be too hard to dodge. I'll have to calibrate it a bit later.

... but will anyone listen?

You know, when you are a teacher, you have to expect (and accept) that some of the things you tell your students are going to in one ear and out the other. Teachers know that we are going to have to repeat ourselves or find new ways to get the ideas we are trying to express to stick. Every year, I talk to my AP students about the difference between primitives and objects and the ideas of pointers.

You would think I'd be paying attention, myself.

I got bogged down in a puzzle this weekend - I had Chip objects that had a set of coordinates for their current position, and another set of coordinates for their destination. I'd start them off the same, but if they were ever different from each other, they would move a tiny little bit towards the destination, until they arrived there. Except when I changed the destination coordinates, they would just jump to the new location - they wouldn't glide; they'd teleport!

If you understand pointers, you can probably tell what my problem was - but it took me a couple of hours to puzzle it out (and find some other bugs along the way, but that's another story). Because I had set the myLoc and myDest variables to point to the same object, when I changed the coordinates of myDest, it changed the coordinates of myLoc, too. When I went back and changed my setter methods to make clean copies of the (x, y, z) coordinates that weren't the same object, suddenly things startes working right.

I wonder what else I was saying that I didn't listen to? I'll bet I need to do a better job documenting my code....

Sunday, May 2, 2010

Chain, chain, chain....

Some good success this weekend - I have gotten the chain of chips to work properly. Each chip is part of a sequence now. If one of the chips is removed, the ones past it glide in and replace it, and a new chip is dropped into the mix. (Your view is from above.) Here's a quick video - every time I click, a random chip is dropped:

The way this works is that each Chip has a "follower" and a "leader" - it is essentially a node in a doubly-linked list. Each chip also has two sets of coordinates - where it is now and where it is moving to, as well as a boolean that indicates whether it is in the process of moving. When a chip is removed, it sends its location to its follower, which uses it as its destination, and starts the chip animating. It also removes itself from the doubly linked list, as you would expect - tying its follower and leader together.

This is a major hurdle in the game, and one of the first things that looks great in OpenGL that I couldn't do with the Quartz commands - check out how the chips flip around as they fall away!