Sur le site officiel du jeu ( http://hardresetgame.com/ ), on peu apercevoir ce code défilé en haut à gauche de l'écran... (voir ci-dessous)
J'ai pas tout lu, mais peut-etre y a t'il des indices quand à la sortie du jeu, ou autre chose ?
Bref, le voici (attention, TRèS LONG !)
public class HardReset extends BaseResetEngine {
@Override
public void onBackPressed() {
this.stopGame();
this.finish();
System.exit(0);
super.onBackPressed();
}
@Override
protected void onDestroy() {
this.stopGame();
Static.STOP = false;
Static.GAME_STOP = false;
super.onDestroy();
}
private class ClockTask extends TimerTask {
@Override
public void run() {
if (Static.PAUSE)
return;
if (Static.STOP) {
Static.STOP = false;
bigbulletAnimation(true);
return;
}
if (Static.GAME_STOP) {
stopenemys();
stopBigbullet();
}
if (updateScore > 0) {
if (updateScore == 1)
storage.updateHighScore(score);
updateScore--;
}
if (BULLETCount < Static.BULLET_MAX_COUNT) {
if (!isBULLET && BULLETTime > Static.BULLET_RESPAWN_TIME) {
// get random BULLET
BULLETType = BULLETType.getByDots();
if (BULLETType != null) {
setCountdown(Static.BULLET_TIME);
isBULLET = true;
BULLETCount++;
// set random BULLET respawn time
Static.BULLET_RESPAWN_TIME = Math.max(6, new Random().nextInt(30));
BULLET = new Sprite(
Static.BULLET_LOCATION.x * Static.BLOCK_SIZE + 2,
Static.BULLET_LOCATION.y * Static.BLOCK_SIZE,
textures.get(20 +
BULLETType.getValue().getIndex()).getTextureRegion
());
scene.attachChild(BULLET);
}
}
if (!isBULLET)
BULLETTime++;
}
time++;
Static.GAME_TIME++;
int size = countdownRectangles.size();
if (size > 0 && scene != null) {
// dont show BULLET when big bullet is eaten
BULLETTime = 0;
countdownRectangles.get(size - 1).setVisible(false);
countdownRectangles.remove(size - 1);
// remove BULLET at countdown end
if (countdownRectangles.size() == 0) {
setkilledenemys(false);
isBULLET = false;
if (BULLET != null)
BULLET.setVisible(false);
}
}
if (removeElement && elementsToRemove.size() > 0) {
elementsToRemove.get(elementsToRemove.size() - 1).setVisible(false);
elementsToRemove.remove(elementsToRemove.size() - 1);
removeElement = false;
}
if (elementsToRemove.size() > 0)
removeElement = true;
}
}
@Override
protected void onCreate(Bundle pSavedInstanceState) {
super.onCreate(pSavedInstanceState);
// set portrait orientation
this.setRequestedOrientation(ActivityInfo.SCREEN_O
RIENTATION_PORTRAIT);
this.loading = new LoadingView(this);
this.addContentView(this.loading,
new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
this.loadingVisible = true;
}
@Override
public void onLoadComplete() { }
@Override
protected void onUpdate(float sElapsed) {
if (Static.PAUSE || !this.enemyStarted)
return;
if (Static.STOP) {
this.stopAnimation();
this.animationStarted = false;
return;
}
if (!this.animationStarted) {
this.animationStarted = true;
this.startkilled();
}
if (this.killed && !this.killedOn) {
this.killedAnimation();
this.setMovementAnimation();
this.killedOn = true;
}
if (this.isSacred() && step++ % 2 != 0) {
return;
}
if (count++ % 12 != 0) {
this.setPosition(this.getX() + vector.x * 2f,
this.getY() + vector.y * 2f);
super.onManagedUpdate(pSecondsElapsed);
return;
}
if (!this.isGateOpened() && (this.getType() == enemyType.CSX)) {
this.tVector = this.getDirectionedVector(this.locationX, this.locationY, this.vector);
if (this.checkItem(locationX + vector.x, locationY, LocationType.WALL)) {
if (this.tVector != null)
this.vector = this.tVector;
else {
this.moves = this.getMoves(this.locationX, this.locationY, this.vector);
int movesSize = moves.size();
this.vector = this.moves.get(new Random().nextInt(movesSize));
}
}
else if (this.tVector != null)
this.vector = this.tVector;
this.changeMovement(this.vector, true);
}
else {
if (this.checkItem(locationX + vector.x, locationY + vector.y ,
LocationType.WALL) || Math.random() > 0.5) {
this.moves = this.getMoves(this.locationX, this.locationY, this.vector);
int movesSize = moves.size();
if (movesSize > 0) {
this.vector = this.moves.get(new Random().nextInt(movesSize));
this.changeMovement(this.vector, true);
}
}
for (int j = -1; j <= 1; j++)
for (int i = -1; i <= 1; i++) {
if (Math.abs(j) == Math.abs(i) || (j == 0 && i == 0))
continue;
maskPoint = new Point(x + i, y + j);
if (this.LEVEL[y + j][x + i] == 1)
possibleMoves.add(maskPoint);
}
if (length++ > maxLength)
return;
for (Point m : possibleMoves) {
maskPoint = calculateVector(start, m);
if (xWeight >= yWeight) {
if (maskPoint.x == xDirection) {
this.generateRoute(new Point(x + xDirection, y));
return;
}
}
else {
if (maskPoint.y == yDirection) {
this.generateRoute(new Point(x, y + yDirection));
return;
}
}
}
for (Point m : possibleMoves) {
this.generateRoute(m);
return;
}
}
this.setPosition(
this.approximate(this.locationX * Static.BLOCK_SIZE),
this.approximate(this.locationY * Static.BLOCK_SIZE));
this.locationX += this.vector.x;
this.locationY += this.vector.y;
// close gate
if ((this.locationX == 9 || this.locationX == 11) && this.locationY == 10)
this.LEVEL[11][10] = 0;
super.onUpdate(sElapsed);
}
@Override
public Engine onLoadEngine() {
this.camera = new Camera(0, 0, Static.CAMERA_WIDTH, Static.CAMERA_HEIGHT);
this.textures = new Textures();
EngineOptions options = new EngineOptions(
true,
ScreenOrientation.PORTRAIT,
new RatioResolutionPolicy(Static.CAMERA_WIDTH, Static.CAMERA_HEIGHT),
this.camera);
return new Engine(options);
}
@Override
public void onLoadResources() {
Texture HardResetTexture;
Texture bulletTexture;
// 0 - HardReset
this.textures.add(new TextureObject(
TextureType.ANIMATED,
HardResetTexture = new Texture(128, 32,
TextureOptions.BILINEAR),
null,
TextureRegionFactory.createResource(HardResetTextu
re,
R.drawable.HardReset, 0, 0, 3, 1)
));
for (TextureObject textureObject : this.textures) {
if (textureObject == null)
continue;
this.bulletEngine.getTextureManager().
loadTexture(textureObject.getTexture());
}
}
@Override
public Scene onLoadScene() {
final FPSCounter fpsCounter = new FPSCounter();
this.scene = new Scene();
this.scene.setBackground(new ColorBackground(0, 0, 0));
this.characterApi = new CharacterApi(scene, getTiledTextureRegion());
this.background = new AnimatedSprite(0, 0, 480, getTiledTextureRegion());
scene.registerUpdateHandler(new IUpdateHandler() {
@Override
public void reset() { }
@Override
public void onUpdate(float pSecondsElapsed) {
if (loadingVisible) {
// hide loading
runOnUiThread(new Runnable() {
public void run() {
loading.setVisibility(View.GONE);
loading = null;
}
});
loadingVisible = false;
}
// next level
if (resetScene) {
// save score
Static.SCORE = score;
storage.updateHighScore(score);
Intent i;
if (Static.LEVEL_INDEX - 1 == 2)
i = new Intent(getBaseContext(), Biggie.class);
else if (Static.LEVEL_INDEX - 1 == 5)
i = new Intent(getBaseContext(), Afraid.class);
else if (Static.LEVEL_INDEX - 1 == 9)
i = new Intent(getBaseContext(), Squirrel.class);
else {
// restart intent
i = getIntent();
i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
}
finish();
startActivity(i);
return;
}
if (Static.PAUSE)
return;
// eated bullet
for (bullet bullet : bulletList)
if (!bullet.isEated() && HardReset.collidesWith(bullet)) {
bullet.setEated(true);
//bullet.setVisible(false);
bullet.setColor(0f, 0f, 0f);
//scene.detachChild(bullet);
score += Static.bullet_VALUE;
bulletEated++;
Static.bullet_EATEN++;
scoreUpdated = true;
Static.DOTS_EATEN++;
bulletList.remove(bullet);
break;
}
// eated big bullet if BULLET is off
if (!isBULLET) {
for (Bigbullet bigbullet : bigbulletList)
if (!bigbullet.isEated() && HardReset.collidesWith(bigbullet)) {
bigbullet.setEated(true);
bigbullet.setVisible(false);
scene.detachChild(bigbullet);
score += Static.BIG_bullet_VALUE;
bulletEated++;
Static.BIGbullet_EATEN++;
scoreUpdated = true;
bigbulletList.remove(bigbullet);
enemyEaten = 0;
setkilledenemys(true);
setCountdown(Static.BIG_bullet_TIME);
break;
}
}
// enemy
for (enemySmart enemy : enemyList) {
if (HardResetLocationChanged && enemy.getType() == enemyType.BLINKY) {
enemy.setHardResetLocation(HardResetLocation);
HardResetLocationChanged = false;
}
if (enemy.isStarted() && !enemy.isGateOpened())
gateOpenCount++;
if (HardReset.collidesWith(enemy)) {
if (!enemy.isVisible())
continue;
if (enemy.isSacred()) {
drawFloatingNumber(enemyEaten + 2,
(int)enemy.getX(), (int)enemy.getY() - 16);
score += Static.enemy_VALUES[enemyEaten];
scoreUpdated = true;
enemy.setVisible(false);
enemy.openGate();
Static.STOP = true;
bulletEngine.vibrate(Static.enemy_EATEN_VIBRATE);
enemyEaten++;
Static.enemy_EATEN++;
final Eye eye = new Eye(
enemy.getX(), enemy.getY(),
Static.EYE_WIDTH, Static.EYE_HEIGHT,
textures.get(32).getTiledTextureRegion());
scene.attachChild(eye);
// find enemy home (cell)
eye.findHome(enemy);
eye.setHomeFoundEvent(new HomeFoundEventListener() {
@Override
public void onHomeFound(enemySmart enemy) {
// hide eye
eye.setVisible(false);
// show unkilled enemy in cage
enemy.setVisible(true);
enemy.setkilled(false);
enemy.setLocation(Static.enemy_EATEN_LOCATION.LOCA
TION.y);
enemy.setPosition(
Static.enemy_EATEN_LOCATION.x * Static.BLOCK_SIZE + 4,
Static.enemy_EATEN_LOCATION.y * Static.BLOCK_SIZE + 4);
}
});
}
else {
HardReset.stop();
HardReset.setVisible(false);
HardReset.setCurrentTileIndex(0);
HardResetDied();
}
}
}
gate.setVisible(gateOpenCount != Static.enemy_COUNT);
gateOpenCount = 0;
(suite)
// BULLET
if (isBULLET && BULLET != null && HardReset.collidesWith(BULLET)) {
isBULLET = false;
BULLET.setVisible(false);
clearCountdown();
Static.STOP = true;
bigbulletAnimation(false);
drawFloatingNumber(BULLETType.getValue().getIndex(
) + 1,
(int)BULLET.getX(), (int)BULLET.getY() - 16);
score += BULLETType.getValue().getValue();
scoreUpdated = true;
bulletEngine.vibrate(Static.BULLET_VIBRATE);
Static.BULLET_EATEN++;
}
if (scoreUpdated) {
scoreUpdated = false;
drawScore();
if (score > Static.HIGH_SCORE) {
drawHighScore(score);
updateScore = 2;
}
if (!Static.ADDITIONAL_LIVE_ADDED && score >= Static.ADDITIONAL_LIVE_SCORE) {
// add live
Sprite s = new Sprite(10 + 34 * Static.HardReset_LIVES, 690,
textures.get(31).getTextureRegion());
scene.attachChild(s);
livesList.add(s);
Static.HardReset_LIVES++;
Static.ADDITIONAL_LIVE_ADDED = true;
}
}
if (bulletEated >= bulletCount) {
if (!background.isAnimationRunning() && !backgroundAnimation) {
background.animate(
new long[] { 200, 200, 200, 200, 200, 200, 200 },
new int[] { 0, 1, 0, 1, 0, 1, 0 }, 0);
backgroundAnimation = true;
Static.STOP = true;
Static.PAUSE = true;
Static.LEVEL_INDEX++;
Static.LEVELS_COMPLETED++;
Static.enemy_MOVEMENT_SPEED += Static.enemy_MOVEMENT_INCREASE;
Static.enemy_REAL_MOVEMENT_SPEED += Static.enemy_MOVEMENT_INCREASE;
saveStatistics();
Timer endTimer = new Timer();
endTimer.schedule(new TimerTask() {
@Override
public void run() {
resetScene = true;
}
}, Static.LEVEL_END_TIMEOUT);
}
}
}
});
this.loadScene();
return this.scene;
}
private void beginGame() {
// draw ready sign
this.ready = new Sprite(188, 347, this.textures.get(5).getTextureRegion());
scene.attachChild(this.ready);
// start
Timer startTimer = new Timer();
startTimer.schedule(new TimerTask() {
@Override
public void run() {
start();
// start big bullet animation
bigbulletAnimation(true);
// remove ready sign
ready.setVisible(false);
// start enemys
startGhots();
}
}, Static.START_DELAY);
}
private void loadScene() {
this.scene.attachChild(this.background);
this.HardReset = new HardReset(
Static.HardReset_POSITION_X * Static.BLOCK_SIZE,
Static.HardReset_POSITION_Y * Static.BLOCK_SIZE,
this.textures.get(0).getTiledTextureRegion());
this.HardReset.setZIndex(9);
this.HardReset.setLocationChange(new LocationChangeEventListener() {
@Override
public void onLocationChange(int x, int y) {
HardResetLocation.set(x, y);
HardResetLocationChanged = true;
}
});
scene.attachChild(this.HardReset);
this.gate = new Rectangle(220, 262, 40, 4);
this.gate.setColor(0f, 0f, 0f);
this.gate.setVisible(this.isGateOpen);
this.scene.attachChild(this.gate);
this.drawLevel();
this.beginGame();
// draw hud
int top = 630;
int left = 10;
int offset = Static.CHARACTER_OFFSET;
this.characterApi.drawCharacter(left, top, Character.H, Static.COLOR_DARK_RED);
left = 300;
this.characterApi.drawCharacter(left, top, Character.DIGIT_ONE, Static.COLOR_DARK_RED);
// draw high score
Static.HIGH_SCORE = this.storage.getHighScore();
this.drawHighScore(Static.HIGH_SCORE);
// draw current score
this.drawScore();
// draw lives
this.showLives();
}
private void drawLevel() {
// draw bullet, enemys
bullet bullet = null;
Bigbullet bigbullet = null;
enemySmart enemy;
int enemyIndex = 0;
this.bulletCount = 0;
this.bulletEated = 0;
TiledTextureRegion bigbulletTexture = this.textures.get(2).getTiledTextureRegion();
for (int y = 0; y < Static.GRID_HEIGHT; y++)
for (int x = 0; x < Static.GRID_WIDTH; x++) {
if (this.isNew && Level.LEVEL[y][x] == 2)
bullet = new bullet(x * Static.BLOCK_SIZE + 8, y * Static.BLOCK_SIZE + 8, 5, 5);
else if (this.isNew && Level.LEVEL[y][x] == 3)
bigbullet = new Bigbullet(x * Static.BLOCK_SIZE + 4, y * Static.BLOCK_SIZE + 4,
Static.bullet_SIZE, Static.bullet_SIZE, bigbulletTexture);
else if (Level.LEVEL[y][x] == 5) {
enemy = new enemySmart(x * Static.BLOCK_SIZE + 4, y * Static.BLOCK_SIZE + 4,
Static.BLOCK_SIZE, Static.BLOCK_SIZE,
this.textures.get(16 + enemyIndex).getTiledTextureRegion());
enemy.setLocation(x, y);
enemy.setType(enemyIndex);
enemy.setZIndex(10);
enemyList.add(enemy);
scene.attachChild(enemy);
enemyIndex++;
}
if (this.isNew) {
if (bullet != null) {
bullet.setEated(false);
bullet.setZIndex(1);
bulletList.add(bullet);
scene.attachChild(bullet);
this.bulletCount++;
}
else if (bigbullet != null) {
bigbullet.setEated(false);
bigbullet.setZIndex(1);
bigbulletList.add(bigbullet);
scene.attachChild(bigbullet);
this.bulletCount++;
}
}
bullet = null;
bigbullet = null;
}
this.isNew = false;
this.scene.sortChildren();
}
private void HardResetDied() {
// save score
storage.updateHighScore(score);
Static.HardReset_DIED++;
if (Static.HardReset_LIVES > 0) {
bulletEngine.vibrate(Static.HardReset_LIVE_VIBRATE
);
this.livesList.get(Static.HardReset_LIVES - 1).setVisible(false);
Static.HardReset_LIVES--;
Static.PAUSE = true;
Timer dieTimer = new Timer();
dieTimer.schedule(new TimerTask() {
@Override
public void run() {
// continue...
stopenemys();
bigbulletAnimation(false);
beginGame();
HardReset.setVisible(true);
int enemyIndex = 0;
for (int y = 0; y < Static.GRID_HEIGHT; y++)
for (int x = 0; x < Static.GRID_WIDTH; x++)
if (Level.LEVEL[y][x] == 5)
enemyList.get(enemyIndex++).setLocation(x, y);
}
}, Static.HardReset_DIED_TIMEOUT);
this.HardReset.setPosition(
Static.HardReset_POSITION_X * Static.BLOCK_SIZE,
Static.HardReset_POSITION_Y * Static.BLOCK_SIZE);
}
else {
Timer endTimer = new Timer();
endTimer.schedule(new TimerTask() {
@Override
public void run() {
if (!Static.GAME_OVER) {
// endgame, show game end screen
Static.GAME_OVER = true;
Intent endIntent = new Intent(getBaseContext(), End.class);
finish();
startActivity(endIntent);
}
}
}, Static.GAMEEND_TIMEOUT);
bulletEngine.vibrate(Static.HardReset_DIED_VIBRATE
);
Static.PAUSE = true;
this.saveStatistics();
}
}
private void start() {
this.started = true;
this.backgroundAnimation = false;
Static.PAUSE = false;
}
private void showLives() {
Sprite s;
for (int i = 0; i < Static.HardReset_LIVES; i++) {
s = new Sprite(10 + 34 * i, 690, this.textures.get(31).getTextureRegion());
scene.attachChild(s);
this.livesList.add(s);
}
}
private void setkilledenemys(boolean killed) {
for (enemySmart g : enemyList)
g.setkilled(killed);
}
private void startGhots() {
for (enemySmart enemy : enemyList)
enemy.startenemy();
}
private void stopenemys() {
for (enemySmart enemy : enemyList) {
enemy.stopenemy();
enemy.setCurrentTileIndex(0, 0);
enemy.stop();
}
}
private void stopBigbullet() {
for (Bigbullet bullet : bigbulletList) {
bullet.setCurrentTileIndex(0, 0);
bullet.stopAnimation();
}
}
private void stopGame() {
this.HardReset.stopAnimation();
this.HardReset.stop();
this.HardReset.setCurrentTileIndex(0);
Static.GAME_STOP = true;
this.clock.cancel();
this.bulletEngine.clearUpdateHandlers();
this.bulletEngine.stop();
}
private void bigbulletAnimation(boolean isStarted) {
for (Bigbullet bigbullet : bigbulletList) {
if (isStarted)
bigbullet.animate(Static.BIG_bullet_ANIMATION_SPEE
D);
else
bigbullet.stopAnimation();
}
}
private void drawHighScore(int score) {
if (this.highScoreSprites.size() > 0)
for (Sprite s : this.highScoreSprites)
this.scene.detachChild(s);
this.drawNumber(score, 153, 652, this.highScoreSprites);
}
private void drawScore() {
if (this.scoreSprites.size() > 0)
for (Sprite s : this.scoreSprites)
this.scene.detachChild(s);
this.drawNumber(this.score, 353, 652, this.scoreSprites);
}
private void drawFloatingNumber(int numberIndex, int left, int top) {
Sprite number = new Sprite(left, top, this.textures.get(25 + numberIndex).getTextureRegion());
this.scene.attachChild(number);
this.elementsToRemove.add(number);
}
private void drawNumber(int number, int left, int top, ArrayListrite> list) {
Sprite scoreSprite;
String scoreString = String.valueOf(number);
int length = scoreString.length();
int value = 0;
for (int i = length - 1; i >= 0; i--) {
value =
Integer.parseInt(java.lang.Character.toString(scor
eString.charAt(i)));
scoreSprite = new Sprite(
i * Static.CHARACTER_OFFSET + left - (length * Static.CHARACTER_OFFSET),
top,
textures.get(6 + value).getTextureRegion());
scene.attachChild(scoreSprite);
if (list != null)
list.add(scoreSprite);
}
}
private void clearCountdown() {
int size = 0;
while ((size = this.countdownRectangles.size()) > 0) {
this.countdownRectangles.get(size - 1).setVisible(false);
this.countdownRectangles.remove(size - 1);
}
}
private void setCountdown(int count) {
Rectangle r;
for (int i = 0; i < count; i++) {
r = new Rectangle(10 + i * 20, 618, 5, 5);
r.setColor(180, 0, 20);
this.scene.attachChild(r);
this.countdownRectangles.add(r);
}
}
private void saveStatistics() {
runOnUiThread(new Runnable() {
public void run() {
int value = storage.getStatistic(StatisticsType.GAME_TIME);
value += Static.GAME_TIME;
storage.updateStatistic(value, StatisticsType.GAME_TIME);
value =
storage.getStatistic(StatisticsType.bullet_EATEN);
value += Static.bullet_EATEN;
storage.updateStatistic(value, StatisticsType.bullet_EATEN);
Static.GAME_TIME = 0;
}
});
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (!(this.HardReset == null || !this.isStarted() || Static.STOP || Static.GAME_STOP)) {
if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
this.HardReset.setRotation(180f);
this.HardReset.moveLeft();
}
else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
this.HardReset.setRotation(0f);
this.HardReset.moveRight();
}
else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
this.HardReset.setRotation(-90f);
this.HardReset.moveUp();
}
else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
this.HardReset.setRotation(90f);
this.HardReset.moveDown();
}
else if (keyCode == KeyEvent.KEYCODE_BACK) {
this.saveStatistics();
}
}
if (keyCode == KeyEvent.KEYCODE_MENU) {
Static.PAUSE = !Static.PAUSE;
}
return super.onKeyDown(keyCode, event);
}
}
J'lis et je regarde ce que j'arrive à en tirer.
Ca ressemble au code source d'une partie du moteur qui gère le combat, avec l'interaction du joueur à la fin.. ![]()
Un code source n'est pas écris en C++, si ?
Enfin je pensais que c'était ecrit spécialement pour la page internet...
Un moteur de jeu n'est pas forcément écrit en c++, tu peux avoir un mélange de plusieurs langage.
Ok, merci pour la précision, en tout cas j'ai rien trouver d'intéréssant dans le code...