



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of using arraylist in java for managing a dynamic number of asteroids in a drawing tool project. It covers the basics of arraylist, including its resizable nature, methods like add(), get(), remove(), and size(), and the need to cast back to the more detailed type when retrieving objects from the arraylist. The document also discusses the concept of super and this in java, and how they can be used in the context of the asteroid class. Finally, it explains how to create and initialize an arraylist, and how to use it to draw and destroy asteroids.
Typology: Study Guides, Projects, Research
1 / 6
This page cannot be seen from the preview
Don't miss anything!




Asteroid(boolean
isLarge,
float
initialX,
float
initialY,
long
previousDrawTime)
{
//
set
the
initial
x
and
y
pos
xPos
=
initialX;
yPos
=
initialY;
//
get
a
random
orientation
for
this
asteroid
rotation
=
random(0,
TWO_PI);
//
get
the
asteroid's
velocity
in
x
and
y
directions
//
based
on
its
orientation
and
size
(bigger
moves
slower)
if
(isLarge)
{
velocityX
=
sin(rotation)*10;
velocityY
=
-cos(rotation)*10;
}
else
{
velocityX
=
sin(rotation)*25;
velocityY
=
-cos(rotation)*25;
} large
=
isLarge;
lastDrawMillis
=
previousDrawTime;
}
Asteroid()
{
this
(true,
random(0,
XSIZE),
random(0,
YSIZE),
0);
} Asteroid(boolean
isLarge,
float
initialX,
float
initialY,
long
previousDrawTime)
{
xPos
=
initialX;
yPos
=^
initialY;
rotation
=
random(0,
TWO_PI);
if
(isLarge)
{
velocityX
=
sin(rotation)*10;
velocityY
=
-cos(rotation)*10;
}
else
{
velocityX
=
sin(rotation)*25;
velocityY
=
-cos(rotation)*25;
} large
=
isLarge;
lastDrawMillis
=
previousDrawTime;
}