Readme
Readme
EX5)
For this exercise i had to use int x,y for the click coordinates(which is a
point);
All i had to do was to set the values for x and y when the mouse is
clicked
(x = e.getX() and y=e.getY();)
Then i had to find a way to determine the number of click(when the
mouse is clicked twice -> draw the line). So i created a boolean
twoPoints which is false by default.
The approach i used is a basic one:
if(twoPoints == false) {
nextPoint = e.getPoint();
twoPoints = true;
}else {
previousPoint = nextPoint;
nextPoint = e.getPoint();
line (previousP.x,previousP.y,nextP.x,nextP.y,g,10,10);
}
When the first click is pressed next Point takes the coordinates (x,y) and
two Points
becomes true; When the second click is pressed previousPoints takes the
values of nextPoint and nextPoints takes the values (x,y) from the mouse
click. Only second time the line Bresenham method is called to draw the
line between the 2 points.
The exercise can also be done using a counter and check the counter for
parity (something like
if (counter %2 == 0) {drawBresenhamLine();} else {};
EX6)
Insted of drag, in order to avoid calling repaint(), i used mousePressed
and mouseReleased methods. I took x1,y1 from mousePressed and x2,y2
from mouseReleased.
In MouseReleased i call the method line(x1,y1,x2,y2). I do that because
in mouseReleased x1,y1 are defined from mousePressed.
EX7)
I generated some animated stages in paint.net and then i populated a List
of BufferedImages(8 frames for right, 8 frames for left). I created an
interface Animation which comes with some basic methods. Then a class
StickMan which implements that inferface in order to have
@OverrideMethods. I also defined a method checkBoundsX which
keeps the character inside the screen for X Axis. Then the rest is done in
paintMethod which works on two cases when boolean right in true or
when boolean left is true; These values are set from the keyboard when
arrows are pressed. Then I take all 8 frames for right and all 8 frames for
left in order and make a cycle of frames per right/left keys.
***Time Spent and Difficulty
I don't know exactly the number of hours, but for the first 6 exercises
I've spent one hours i think. They are quite simple, except the
Bresenham Algorithm which have to be implemented, after that,
everything is ok.
The Bonus exercise was a little difficult because in the first stage i tried
to create a frame(sprite) using only forms(polygon,circle etc), but i
realisez that is quite hard because is a lot of work especially for
incrementing the x coordinates for movements.
The code for a single frame was like this:
static int[] arrHead = {150,50,215,100};
static int[] arrEyes1 = {239 , 235, 10, 10};
static int[] arrEyes2 = {275 , 240, 10, 10};
static int[] arrMouth = {245 , 270, 270, 273};
g2d.fillPolygon(arrBodyX, arrBodyY,
arrBodyX.length);
//HANDS
//left hand
g2d.setColor(Color.BLACK);
g2d.fillPolygon(arrHandsLX, arrHandsLY,
arrHandsLX.length);
//right hand
g2d.fillPolygon(arrHandsRX, arrHandsRY,
arrHandsRX.length);
//LEGS
g2d.fillPolygon(arrLegsLX, arrLegsLY,
arrLegsLX.length);
g2d.fillPolygon(arrLegsRX, arrLegsRY,
arrLegsRX.length);
So i realised that i have to work too much for a minimum of 8 frames for
right movements.
Then i discovered some tools like openGL, slick library, spritesheet and
an algorithm which takes a spriteSheet formed of X frames and divides
it by width. With some AppGameContainer, renderMethod and 2-3
functions everything worked fine.
But in the end i decided to use simple things like a set of 8
frames(sprites images) for every movement and display them in some
order. In order to create the animation i change the image quickly and
modified the x coordinates for that image, in this way the animation
effect is made. I could probably add some random obstacles, effects,
music, etc, but that's maybe for the next homework :).