summaryrefslogtreecommitdiff
path: root/Year_2/IandM/02142018/Heart.pde
blob: 8ac93a61294d7846fdd29776f5974a182ab77ea2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class Heart {
  private boolean status;
  private int posx;
  private int posy;
  private float speedx;
  private float speedy;
  private int Q = 1948;

  public Heart(int posx, int posy) {
    this.status = true;
    this.posx = posx;
    this.posy = posy;
  }

  public boolean is_alive() {
    return this.status;
  }

  private float f() {
    return (this.Q%21)/80;
  }

  public void die() {
    this.status = false;
  }

  public void draw() {
    smooth();
    noStroke();
    if (this.is_alive()) {
      fill(#C41212);
    } else {
      fill(#DDDDDD);
    }
    this.speedx = random(-5, 6.0);
    this.speedy = random(3, 8.0);
    if (!this.is_alive()) {
      this.speedy += 0.1+this.f();
      this.posy += this.speedy;
    } else {
      this.posy -= this.speedy;
    }

    this.posx -= this.speedx;

    pushMatrix();
    translate(-30+this.posx, -5+this.posy);

    beginShape();
    vertex(50, 15);
    bezierVertex(50, -5, 90, 5, 50, 40);
    vertex(50, 15);
    bezierVertex(50, -5, 10, 5, 50, 40);
    endShape();

    popMatrix();
  }

  public int positionx() {
    return this.posx;
  }

  public int positiony() {
    return this.posy;
  }
}