Array of Objects Name: _____________________________________________________ Period: _______ Date: _______________________ Day3:

advertisement
Topic: Array of Objects
Name: _____________________________________________________
Day3:
Period: _______ Date: _______________________
w/ MouseListener Interface
 I will implement the MouseListener interface.
Objectives


I will be able to detect when a point is within an object’s coordinates.
I will be able to increase the speed of the objects as the game progresses.

Values are set in initializeObjects( ) with random values after the object is
created.
Every time move() is called, the x and y coordinates are changed by deltaX and
deltaY
Speed of the objects are
stored in Shape:
- deltaX
- deltaY
Each Shape object (Circle,
Rectangle, CircleStar, etc) has
it’s own value for deltaX and
deltaY.
How would you increase the
speed of the objects every 10
seconds?

paintComponent()
{
//move objects
//draw objects
counter20msecs++;
if (counter20msecs % 50 == 0)
{
secondCounter++;
if (secondCounter % 10 == 0)
{
for (int k=0; k<myObjects.length; k++)
{
if (myObjects[k] != null)
myObjects[k].increaseSpeed();
}
}
}
Why % 50 ?
Why % 10 ?
Increase speed for all active
objects
}
In Shape.java
- add this method
ToDo:
public void increaseSpeed()
{
deltaX++;
deltaY++;
}
Increase the speed every 10 seconds. Test with 5 seconds.
End game after 120 seconds. Test with 60 seconds.
Download