Skip to content

Commit

Permalink
eyes are blinking
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip M authored and Philip M committed Aug 1, 2018
1 parent 820a064 commit b6b5333
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 27 deletions.
Binary file modified Steve/productions/production/Steve/DrawPanel.class
Binary file not shown.
Binary file modified Steve/productions/production/Steve/Frame$1.class
Binary file not shown.
Binary file modified Steve/productions/production/Steve/Frame$KeyHandler.class
Binary file not shown.
Binary file modified Steve/productions/production/Steve/Frame.class
Binary file not shown.
Binary file modified Steve/productions/production/Steve/Repo.class
Binary file not shown.
Binary file modified Steve/productions/production/Steve/Steve.class
Binary file not shown.
8 changes: 1 addition & 7 deletions Steve/src/DrawPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,11 @@ public void paintComponent(Graphics g)
//Blink
if (this.eyes.isBlink())
{
g.setColor(Color.BLACK);
g.setColor(eyes.getColor());
} else {
g.setColor(this.eyes.getColor());
}

try {
Thread.sleep(2);
} catch (InterruptedException e) {
e.printStackTrace();
}

//Left
g2.drawRoundRect(this.leftEye.getLeftXPos(),this.leftEye.getLeftYPos(), this.leftEye.getWidthleft(), this.leftEye.getHeightleft(), this.eyes.getCurve(), this.eyes.getCurve());
g2.fillRoundRect(this.leftEye.getLeftXPos(),this.leftEye.getLeftYPos(), this.leftEye.getWidthleft(), this.leftEye.getHeightleft(), this.eyes.getCurve(), this.eyes.getCurve());
Expand Down
10 changes: 10 additions & 0 deletions Steve/src/Frame.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class Frame extends JFrame

private boolean click;

private int counter = 0;

protected DrawPanel drawPanel;

public Frame(LeftEye leftEye, RightEye rightEye, Eyes eyes)
Expand Down Expand Up @@ -68,6 +70,14 @@ public void setClick(boolean click)
this.click = click;
}

public int getCounter() {
return counter;
}

public void setCounter(int counter) {
this.counter = counter;
}

private class KeyHandler implements MouseMotionListener, MouseListener
{

Expand Down
37 changes: 28 additions & 9 deletions Steve/src/Repo.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@

public class Repo
{
public int blink(Eyes eyes, int counter)
public void blink(Eyes eyes, Frame frame)
{
counter++;
if (eyes.isBlink() && counter > 100) {
eyes.setBlink(false);
counter = 0;
} else if (counter > 1100) {
int counter = frame.getCounter();

if (!eyes.isBlink() && ((counter % 1100) == 0))
{
eyes.setBlink(true);
counter = 0;
eyes.setColor(0,0,0);

try {
Thread.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
else if (counter > 1100)
{
eyes.setBlink(false);
}

return counter;
counter++;
frame.setCounter(counter);
}

public void angry(Frame frame, Eyes eyes)
{
if(frame.isClick())
{
eyes.setColor(255,30,30);
} else {
eyes.setColor(10, 200, 255);
}
}
}
16 changes: 5 additions & 11 deletions Steve/src/Steve.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ public static void main (String[] args)

while(true)
{
int counter = 0;

//resizing height
if((leftEye.getLeftYPos() > 90 || leftEye.getLeftYPos() < 30) && (rightEye.getRightYPos() > 90 || rightEye.getRightYPos() < 30))
{
Expand Down Expand Up @@ -144,17 +142,13 @@ public static void main (String[] args)
frame.repaintDrawPanel();
}

//blinking
repo.blink(eyes, counter);

//looking angry
if(frame.isClick())
{
eyes.setColor(255,30,30);
} else {
eyes.setColor(10, 200, 255);
}
repo.angry(frame, eyes);

//blinking
repo.blink(eyes, frame);

//repainting the JPanel
frame.repaintDrawPanel();

try {
Expand Down

0 comments on commit b6b5333

Please sign in to comment.