views:

90

answers:

1

I was assigned to make an animated screensaver as a programming project for my Advanced Programming course. The objective is to have several moving components inside an undecorated, fullscreen frame, but I'm going step-by-step and doing it one component at a time.

Here's my source code so far: http://pastebin.com/dc722188

Feel free to comment out any part involving file operations, they're not relevant for now.

Now, the issue I have here is that apparently the program recognizes my LogoComponet as encompassing the entire frame (even though it's not supposed to), and thus the conditions for collision are triggered immediately causing my logo object to suddenly start having seizures. I have no idea what's causing this at all, an even manually setting the bounds for the component won't work, and the fact that this is due tomorrow isn't helping my case at all.

So, uh, help, please? .___.

A: 

First, the code you pasted has the constructor named improperly in the twoSquareComponent. The problem is in your animate method. When you make your checks to change direction you change the direction, but the next call moves back to where you where. You need some way to track current direction.

As an example if you cross the side and your dx is 10 and current x is 11 you move to 1 and then the next animate call puts you back at 11, and then previous to 1, etc. It just repeats this hence the seizure effect you describe. I'll leave this to you as it's homework :) . but that is your problem You probably want to store current direction, and not change until you go out of bounds again.

Good Luck

broschb