Java Reference
In-Depth Information
82
if(i < 4) // occasionally flip the sprite for variety
83
ghost.setTransform(Sprite.TRANS_MIRROR);
84
layerManager.append(ghost);
}
85
}
86
87
lastGenTime = System.currentTimeMillis();
}
88
}
89
90
91
private void moveGhosts() {
92
int fallSpeed = 10;
93
int numGhosts = layerManager.getSize() - 1; // exclude the pong
94
for(int i = numGhosts; i >= 1; i--) {
95
Sprite ghost = (Sprite) layerManager.getLayerAt(i);
96
ghost.move(0, fallSpeed);
97
if(ghost.collidesWith(pong, true)) {
98
points += 10;
99
layerManager.remove(ghost);
100
try
{
101
tonePlayer.start();
102
}
103
catch(Exception e) {
104
e.printStackTrace();
105
}
106
}
107
else if(ghost.getY() > this.getHeight()) {
108
points -= 10;
109
layerManager.remove(ghost);
}
110
}
111
}
112
113
114
private void movePong() {
115
int keyState = getKeyStates();
116
int dx = 15;
if( (keyState & GameCanvas.LEFT_PRESSED) != 0) {
117
118
pongX -= dx;
119
if(pongX < 0) pongX = 0;
120
}
121
else if( (keyState & GameCanvas.RIGHT_PRESSED) != 0) {
122
pongX += dx;
123
if(pongX > (getWidth() - pongWidth))
124
pongX = getWidth() - pongWidth;
125
}
126
pong.setPosition(pongX, pongY);
127
}
128
129
// shut down on right softkey (S60 & UIQ)
130
public void keyPressed(int keyCode) {
131
if(keyCode == -7
||
keyCode == -20) {
132
midlet.die();
133
}
134
}
135
136
public int genRandom(int min, int max) {
137
return (Math.abs(random.nextInt()) % max) + min;
}
138
}
139
 
Search WWH ::




Custom Search