Projeto

Geral

Perfil

Estatísticas
| Revisão:

root / first_draft / Sphere.pde @ 4

Histórico | Ver | Anotar | Download (2,12 KB)

1
class Sphere 
2
  {
3
  Universe universe;
4
  int id    = -1;	
5
  	
6
  float  x0 = 0;
7
  float  y0 = 0;
8
  float  z0 = 0;
9

    
10
  float v0x = 0;
11
  float v0y = 0;
12
  float v0z = 0;
13
  
14
  float x = 0;
15
  float y = 0;
16
  float z = 0;
17
  
18
  int red = 0;
19
  int green = 0;
20
  int blue = 0;
21
  
22
  int steps  = 0;
23
  int radius = 20;
24
  
25
  boolean destroyed = false;
26
  
27
  void be ()
28
    {
29
    x = x0;
30
    y = y0;
31
    z = z0;
32
    }
33
  
34
  void draw ()
35
    {
36
    
37
    fill (0, 125);
38
    stroke (0, 255, 0);
39
      
40
    if (destroyed)
41
      {
42
      return;
43
      }
44
//    translate (x, y, z);
45
//    fill (red, green, blue, 200);
46
//    sphere (radius);
47
    ellipse (x, y, radius * 2, radius * 2);
48
    
49
    
50
//    translate (-x, -y, -z);
51
    }
52
    
53

    
54
  void step ()
55
    {
56
    x = x0 + v0x * steps + 0.5 * universe.gravityX * steps * steps;
57
    y = y0 + v0y * steps + 0.5 * universe.gravityY * steps * steps;
58
    z = z0 + v0z * steps + 0.5 * universe.gravityZ * steps * steps;
59
    
60
    if (y >= 1200)
61
      {
62
      v0y = -(v0y + (universe.gravityY * steps));
63
      //x0 = x;
64
      //y = 999;
65
      y0 = y;
66
      x0 = x;
67
      z0 = z;
68
      steps = 0;
69
      //radius = 20;
70
      //z0 = z;
71
      }
72
    steps++;
73
    //radius++;
74
    }
75
    
76
  void split ()
77
    {
78
    println ("splitting " + id);
79
    radius = radius / 2;
80
    
81
    if (destroyed)
82
      {
83
      return;
84
      }
85

    
86
    if (radius < universe.threshold_radius)
87
      {
88
      destroyed = true;
89
      if (universe.gameover ())
90
        {
91
        //GAMEOVER = true;
92
        }
93
      return;
94
      }
95

    
96
    x0 = x + universe.bounceX;
97
    y0 = y;
98
    z0 = z;
99

    
100
    v0x = (v0x + (universe.gravityX * steps)) + 5;
101
    v0y = (v0y + (universe.gravityY * steps));
102
    v0z = (v0z + (universe.gravityZ * steps));
103

    
104
    
105
    steps = 0;
106

    
107
    
108
    Sphere s = new Sphere ();
109
    
110
    s.red   = red;
111
    s.green = green;
112
    s.blue  = blue;
113
    
114
    s.x0 = x0- (universe.bounceX * 2);
115
    s.y0 = y0;
116
    s.z0 = z0;
117
    
118
    s.v0x = v0x - (universe.bounceSpeed * 2);
119
    s.v0y = v0y;
120
    s.v0z = v0z;
121

    
122

    
123
    v0x = universe.bounceSpeed;
124
    
125
    s.radius = radius;
126
    
127
    universe.add (s);
128
    
129
    println (universe.elements.length);
130
    //steps++;
131
    //radius += 5;
132
    }  
133
    
134
  }