Skip to content

Commit 839ba1e

Browse files
committed
made it work again, with senseful class hirarchie
1 parent bb5b27e commit 839ba1e

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,4 @@ local.properties
6666

6767
# Merge #
6868
*.orig
69+
/RemoteSystemsTempFiles/.project

ColorBubbles/src/ph/sm/colorbubbles/ColorBubbles.java

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
package ph.sm.colorbubbles;
44

5+
import java.util.LinkedList;
6+
57
import ch.aplu.android.*;
68
import android.graphics.Point;
79

@@ -13,6 +15,7 @@ public class ColorBubbles extends GameGrid implements GGFlingListener, GGActorCo
1315
protected GGPanel p;
1416
private int nbBalls = 6;
1517
protected int nbBubbles = 25;
18+
private LinkedList<Bubble> bubbles = new LinkedList<Bubble>();
1619
private int flingThreshold = 2;
1720
private int hits = 0;
1821
private int shots = 0;
@@ -38,6 +41,7 @@ public void main()
3841
{
3942
int type = (int)(Math.random() * 6);
4043
Bubble b = new Bubble(type);
44+
bubbles.add(b);
4145
b.setCollisionCircle(new Point(0, 0), 21);
4246
int d = (int)((double)pixelToVirtual(getNbHorzCells()) / (nbBubbles + 1));
4347
addActorNoRefresh(b, new Location(virtualToPixel((i + 1) * d), virtualToPixel(30)));
@@ -48,6 +52,11 @@ public void main()
4852
Ball ball = new Ball(this, i);
4953
Location loc = new Location(p.toPixelX(i - 2.5), p.toPixelY(0.5));
5054
addActorNoRefresh(ball, loc);
55+
56+
for (Bubble b : bubbles) {
57+
if (b.getType() == ball.getType())
58+
ball.addCollisionActor(b);
59+
}
5160
}
5261
doRun();
5362
status.setText("Fling a ball!");
@@ -65,9 +74,7 @@ public boolean flingEvent(Point start, Point end, GGVector velocity)
6574
{
6675
b.addActorCollisionListener(this);
6776
b.setCollisionCircle(new Point(0, 0), 21);
68-
for (Actor bubble : getActors(Bubble.class))
69-
b.addCollisionActor(bubble);
70-
((Ball)b).init(p.toUserX(b.getXStart()), p.toUserY(b.getYStart()), vx, vy);
77+
((Ball)b).shoot(vx, vy);
7178
shots++;
7279
return true;
7380
}
@@ -81,12 +88,9 @@ public boolean flingEvent(Point start, Point end, GGVector velocity)
8188

8289
public int collide(Actor actor1, Actor actor2)
8390
{
84-
if (((Ball)actor1).getType() == ((Bubble)actor2).getType())
85-
{
86-
playTone(1200, 20);
87-
actor2.removeSelf();
88-
hits++;
89-
}
91+
playTone(1200, 20);
92+
actor2.removeSelf();
93+
hits++;
9094
displayResult();
9195
return 0;
9296
}
@@ -111,21 +115,22 @@ public Ball(ColorBubbles app, int type)
111115
{
112116
super(type);
113117
this.app = app;
114-
setActEnabled(false);
115118
}
116119

117-
public void init(double x, double y, double vx, double vy)
120+
public void reset() {
121+
setActEnabled(false);
122+
x = app.p.toUserX(getXStart());
123+
y = app.p.toUserY(getYStart());
124+
}
125+
public void shoot(double vx, double vy)
118126
{
119-
this.x = x;
120-
this.y = y;
121127
this.vx = vx;
122128
this.vy = vy;
123129
setActEnabled(true);
124130
}
125131

126132
public void act()
127133
{
128-
//vy = vy - g * dt;
129134
x = x + vx * dt;
130135
y = y + vy * dt;
131136
setLocation(new Location(app.p.toPixelX(x), app.p.toPixelY(y)));
@@ -141,17 +146,16 @@ public void act()
141146
// -----------class Bubble -----------------
142147
class Bubble extends Actor
143148
{
144-
protected int type;
145149

146150
public Bubble(int type)
147151
{
148-
super("peg_" + type);
149-
this.type = type;
152+
super("peg", 6);
153+
show(type);
150154
}
151155

152156
public int getType()
153157
{
154-
return type;
158+
return getIdVisible();
155159
}
156160

157161
}

0 commit comments

Comments
 (0)