Révision | a2c236d367a9541c667e675b18a635d09c56f0a2 (tree) |
---|---|
l'heure | 2021-12-10 04:20:51 |
Auteur | sebastian_bugiu |
Commiter | sebastian_bugiu |
Various improvements.
@@ -15,12 +15,9 @@ | ||
15 | 15 | |
16 | 16 | public class MainMenuActivity extends ScreenAdapter { |
17 | 17 | |
18 | - private final SpaceRocket game; | |
19 | 18 | private final Stage stage; |
20 | 19 | |
21 | 20 | public MainMenuActivity(SpaceRocket game) { |
22 | - this.game = game; | |
23 | - | |
24 | 21 | stage = new Stage(new ScreenViewport()); |
25 | 22 | Gdx.input.setInputProcessor(stage); |
26 | 23 | } |
@@ -28,6 +25,7 @@ | ||
28 | 25 | @Override |
29 | 26 | public void show() { |
30 | 27 | super.show(); |
28 | + stage.clear(); | |
31 | 29 | Table table = new Table(); |
32 | 30 | table.setFillParent(true); |
33 | 31 | table.setDebug(true); |
@@ -59,17 +57,17 @@ | ||
59 | 57 | newGame.addListener(new ChangeListener() { |
60 | 58 | @Override |
61 | 59 | public void changed(ChangeEvent event, Actor actor) { |
62 | - game.changeScreen(SpaceRocket.Screen.SELECT_DIFFICULTY); | |
60 | + SpaceRocket.getGame().changeScreen(SpaceRocket.Screen.SELECT_DIFFICULTY); | |
63 | 61 | } |
64 | 62 | }); |
65 | 63 | |
66 | 64 | preferences.addListener(new ChangeListener() { |
67 | 65 | @Override |
68 | 66 | public void changed(ChangeEvent event, Actor actor) { |
69 | - game.changeScreen(SpaceRocket.Screen.OPTIONS); | |
67 | + SpaceRocket.getGame().changeScreen(SpaceRocket.Screen.OPTIONS); | |
70 | 68 | } |
71 | 69 | }); |
72 | - game.changeScreen(SpaceRocket.Screen.SELECT_DIFFICULTY); | |
70 | +// SpaceRocket.getGame().changeScreen(SpaceRocket.Screen.SELECT_DIFFICULTY); | |
73 | 71 | } |
74 | 72 | |
75 | 73 | @Override |
@@ -1,15 +1,111 @@ | ||
1 | 1 | package com.headwayent.spacerocket; |
2 | 2 | |
3 | +import com.badlogic.gdx.Gdx; | |
3 | 4 | import com.badlogic.gdx.ScreenAdapter; |
4 | -import com.headwayent.spacerocket.old.SpaceRocketSprite; | |
5 | +import com.badlogic.gdx.scenes.scene2d.Actor; | |
6 | +import com.badlogic.gdx.scenes.scene2d.Event; | |
7 | +import com.badlogic.gdx.scenes.scene2d.EventListener; | |
8 | +import com.badlogic.gdx.scenes.scene2d.Stage; | |
9 | +import com.badlogic.gdx.scenes.scene2d.ui.CheckBox; | |
10 | +import com.badlogic.gdx.scenes.scene2d.ui.Label; | |
11 | +import com.badlogic.gdx.scenes.scene2d.ui.SelectBox; | |
12 | +import com.badlogic.gdx.scenes.scene2d.ui.Skin; | |
13 | +import com.badlogic.gdx.scenes.scene2d.ui.Table; | |
14 | +import com.badlogic.gdx.scenes.scene2d.ui.TextButton; | |
15 | +import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; | |
16 | +import com.badlogic.gdx.utils.Align; | |
17 | +import com.badlogic.gdx.utils.ScreenUtils; | |
18 | +import com.badlogic.gdx.utils.viewport.ScreenViewport; | |
5 | 19 | |
6 | 20 | public class OptionsMenuActivity extends ScreenAdapter { |
7 | 21 | |
22 | + private final Stage stage; | |
23 | + private Label titleLabel; | |
24 | + private Label soundLabel; | |
25 | + private Label accelerometerLabel; | |
26 | + private Label shipMovementLabel; | |
27 | + | |
28 | + public OptionsMenuActivity() { | |
29 | + stage = new Stage(new ScreenViewport()); | |
30 | + | |
31 | + } | |
32 | + | |
8 | 33 | @Override |
9 | 34 | public void show() { |
10 | 35 | super.show(); |
36 | + stage.clear(); | |
37 | + Table table = new Table(); | |
38 | + table.setFillParent(true); | |
39 | + table.setDebug(true); | |
40 | + stage.addActor(table); | |
41 | + | |
42 | + Gdx.input.setInputProcessor(stage); | |
43 | + | |
44 | + Skin skin = new Skin(Gdx.files.internal("uiskin.json")); | |
45 | + | |
46 | + titleLabel = new Label("Options", skin); | |
47 | + soundLabel = new Label("Sound enabled", skin); | |
48 | + accelerometerLabel = new Label("Accelerometer for orientation", skin); | |
49 | + shipMovementLabel = new Label("Ship movement type", skin); | |
50 | + | |
51 | + final CheckBox soundCheckbox = new CheckBox(null, skin); | |
52 | + soundCheckbox.setChecked(Preferences.getInstance().isSoundEnabled()); | |
53 | + soundCheckbox.addListener(new EventListener() { | |
54 | + @Override | |
55 | + public boolean handle(Event event) { | |
56 | + Preferences.getInstance().setSoundsEnabled(soundCheckbox.isChecked()); | |
57 | + return false; | |
58 | + } | |
59 | + }); | |
60 | + | |
61 | + final SelectBox<String> shipMovementSelectBox = new SelectBox<>(skin); | |
62 | + final String[] strings = {"retain inertia", "slowly stop", "stop immediately"}; | |
63 | + shipMovementSelectBox.setItems(strings); | |
64 | + shipMovementSelectBox.setSelected(strings[Preferences.getInstance().getShipMovementType()]); | |
65 | + shipMovementSelectBox.addListener(new ChangeListener() { | |
66 | + @Override | |
67 | + public void changed(ChangeEvent event, Actor actor) { | |
68 | + String selected = shipMovementSelectBox.getSelected(); | |
69 | + for (int i = 0; i < strings.length; ++i) { | |
70 | + if (strings[i].equalsIgnoreCase(selected)) { | |
71 | + Preferences.getInstance().setShipMovementType(i); | |
72 | + break; | |
73 | + } | |
74 | + } | |
75 | + } | |
76 | + }); | |
77 | + | |
78 | + | |
79 | + final TextButton backButton = new TextButton("Back", skin); // the extra argument here "small" is used to set the button to the smaller version instead of the big default version | |
80 | + backButton.addListener(new ChangeListener() { | |
81 | + @Override | |
82 | + public void changed(ChangeEvent event, Actor actor) { | |
83 | + SpaceRocket.getGame().changeScreen(SpaceRocket.Screen.MAIN_MENU); | |
84 | + } | |
85 | + }); | |
86 | + | |
87 | + table.add(titleLabel).colspan(2); | |
88 | + table.row().pad(10, 10, 10, 10); | |
89 | + table.add(soundLabel).left(); | |
90 | + table.add(soundCheckbox); | |
91 | + table.row().pad(10, 10, 10, 10); | |
92 | + table.add(shipMovementLabel).left(); | |
93 | + table.add(shipMovementSelectBox); | |
94 | + table.row().pad(10, 10, 10, 10); | |
95 | + table.add(backButton).colspan(2); | |
96 | + | |
11 | 97 | |
12 | 98 | // sounds accel ship movement options (retain inertia, grind to a halt, stop immediately). |
13 | 99 | // Screen orientation? |
14 | 100 | } |
101 | + | |
102 | + @Override | |
103 | + public void render(float delta) { | |
104 | + super.render(delta); | |
105 | + ScreenUtils.clear(0, 0, 0, 1); | |
106 | + | |
107 | + // tell our stage to do actions and draw itself | |
108 | + stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f)); | |
109 | + stage.draw(); | |
110 | + } | |
15 | 111 | } |
@@ -47,7 +47,7 @@ | ||
47 | 47 | public static final float ACCELEROMETER_ERROR = 3.0f; |
48 | 48 | public static final float FLOAT_EPSILON = 0.00001f; |
49 | 49 | private static final float CORNER_X = 0, CORNER_Y = 0; |
50 | - private static final int NUM_LIVES = 10; | |
50 | + private static final int NUM_LIVES = 1000; | |
51 | 51 | private static final int HIDDEN_KEY_NUM_PRESSES = 10; |
52 | 52 | private static float FONT_HEIGHT; |
53 | 53 | private static float SCORE_WIDTH; |
@@ -92,8 +92,8 @@ | ||
92 | 92 | |
93 | 93 | public void reset() { |
94 | 94 | // System.out.println("Resetting " + name); |
95 | - if (name.contains("miniBossSprite")) { | |
96 | - System.out.println(); | |
95 | + if (name.contains("srrocket")) { | |
96 | + System.out.println("Resetting: " + name); | |
97 | 97 | } |
98 | 98 | setVisible(false); |
99 | 99 | if (animation != null) { |
@@ -9,6 +9,9 @@ | ||
9 | 9 | if (sprite.isVisible()) { |
10 | 10 | throw new IllegalStateException(sprite.getName() + " is still visible"); |
11 | 11 | } |
12 | + if (sprite.getName().contains("srrocket")) { | |
13 | + System.out.println("readding " + sprite.getName() + " spriteList size: " + spriteList.size()); | |
14 | + } | |
12 | 15 | // if (spriteList.contains(sprite)) { |
13 | 16 | // throw new IllegalArgumentException(sprite.getName() + " is already in the list"); |
14 | 17 | // } |
@@ -62,6 +62,12 @@ | ||
62 | 62 | private ExtendedSpritePool<RocketSprite> rocketTripleLeftPool = new ExtendedSpritePool<>(); |
63 | 63 | private ExtendedSpritePool<RocketSprite> rocketTripleRightPool = new ExtendedSpritePool<>(); |
64 | 64 | private ExtendedSpritePool<RocketSprite> rocketDoubleDamagePool = new ExtendedSpritePool<>(); |
65 | + private ExtendedSpritePool<RocketSprite> otherRocketLeftPool = new ExtendedSpritePool<>(); | |
66 | + private ExtendedSpritePool<RocketSprite> otherRocketRightPool = new ExtendedSpritePool<>(); | |
67 | + private ExtendedSpritePool<RocketSprite> otherRocketTripleCenterPool = new ExtendedSpritePool<>(); | |
68 | + private ExtendedSpritePool<RocketSprite> otherRocketTripleLeftPool = new ExtendedSpritePool<>(); | |
69 | + private ExtendedSpritePool<RocketSprite> otherRocketTripleRightPool = new ExtendedSpritePool<>(); | |
70 | + private ExtendedSpritePool<RocketSprite> otherRocketDoubleDamagePool = new ExtendedSpritePool<>(); | |
65 | 71 | private ExtendedSpritePool<ExplosionSprite> explosionPool = new ExtendedSpritePool<>(); |
66 | 72 | private ExtendedSpritePool<BossSprite> bossPool = new ExtendedSpritePool<>(); |
67 | 73 | private ExtendedSpritePool<PowerupSprite> powerupPool = new ExtendedSpritePool<>(); |
@@ -338,6 +344,24 @@ | ||
338 | 344 | append(srrocketRightSprite[i]); |
339 | 345 | rocketRightPool.add(srrocketRightSprite[i]); |
340 | 346 | } |
347 | + otherRocketLeftSprite = new RocketSprite[64]; | |
348 | + for (int i = 0; i < otherRocketLeftSprite.length; ++i) { | |
349 | + otherRocketLeftSprite[i] = new RocketSprite( | |
350 | + rocketLeftRegion, "otherRocketLeftSprite" + i, | |
351 | + x, width, y, height, true, 8); | |
352 | + otherRocketLeftSprite[i].setLastFrameStick(true); | |
353 | + append(otherRocketLeftSprite[i]); | |
354 | + otherRocketLeftPool.add(otherRocketLeftSprite[i]); | |
355 | + } | |
356 | + otherRocketRightSprite = new RocketSprite[64]; | |
357 | + for (int i = 0; i < otherRocketRightSprite.length; ++i) { | |
358 | + otherRocketRightSprite[i] = new RocketSprite( | |
359 | + rocketRightRegion, "otherRocketRightSprite" + i, | |
360 | + x, width, y, height, true, 8); | |
361 | + otherRocketRightSprite[i].setLastFrameStick(true); | |
362 | + append(otherRocketRightSprite[i]); | |
363 | + otherRocketRightPool.add(otherRocketRightSprite[i]); | |
364 | + } | |
341 | 365 | tripleRocketSpriteCenter = new RocketSprite[64]; |
342 | 366 | otherTripleRocketSpriteCenter = new RocketSprite[64]; |
343 | 367 | for (int i = 0; i < tripleRocketSpriteCenter.length; ++i) { |
@@ -349,7 +373,7 @@ | ||
349 | 373 | centerRocketMultiRegion, "otherTripleRocketSpriteCenter" + i, |
350 | 374 | x, width, y, height, true, 1); |
351 | 375 | append(otherTripleRocketSpriteCenter[i]); |
352 | - rocketTripleCenterPool.add(otherTripleRocketSpriteCenter[i]); | |
376 | + otherRocketTripleCenterPool.add(otherTripleRocketSpriteCenter[i]); | |
353 | 377 | } |
354 | 378 | tripleRocketSpriteLeft = new RocketSprite[64]; |
355 | 379 | otherTripleRocketSpriteLeft = new RocketSprite[64]; |
@@ -361,7 +385,7 @@ | ||
361 | 385 | otherTripleRocketSpriteLeft[i] = new RocketSprite(leftRocketMultiRegion, "otherTripleRocketSpriteLeft" + i, |
362 | 386 | x, width, y, height, true, 1); |
363 | 387 | append(otherTripleRocketSpriteLeft[i]); |
364 | - rocketTripleLeftPool.add(otherTripleRocketSpriteLeft[i]); | |
388 | + otherRocketTripleLeftPool.add(otherTripleRocketSpriteLeft[i]); | |
365 | 389 | } |
366 | 390 | tripleRocketSpriteRight = new RocketSprite[64]; |
367 | 391 | otherTripleRocketSpriteRight = new RocketSprite[64]; |
@@ -373,7 +397,7 @@ | ||
373 | 397 | otherTripleRocketSpriteRight[i] = new RocketSprite(rightRocketMultiRegion, "otherTripleRocketSpriteRight" + i, |
374 | 398 | x, width, y, height, true, 1); |
375 | 399 | append(otherTripleRocketSpriteRight[i]); |
376 | - rocketTripleRightPool.add(otherTripleRocketSpriteRight[i]); | |
400 | + otherRocketTripleRightPool.add(otherTripleRocketSpriteRight[i]); | |
377 | 401 | } |
378 | 402 | doubleDamageRocketSprite = new RocketSprite[64]; |
379 | 403 | otherDoubleDamageRocketSprite = new RocketSprite[64]; |
@@ -387,7 +411,7 @@ | ||
387 | 411 | x, width, y, height, true, 4); |
388 | 412 | otherDoubleDamageRocketSprite[i].setDoubleDamage(true); |
389 | 413 | append(otherDoubleDamageRocketSprite[i]); |
390 | - rocketDoubleDamagePool.add(otherDoubleDamageRocketSprite[i]); | |
414 | + otherRocketDoubleDamagePool.add(otherDoubleDamageRocketSprite[i]); | |
391 | 415 | } |
392 | 416 | enemyrocketSprite = new RocketSprite[64]; |
393 | 417 | for (int i = 0; i < enemyrocketSprite.length; ++i) { |
@@ -440,24 +464,6 @@ | ||
440 | 464 | enemyPool.add(enemy[i]); |
441 | 465 | } |
442 | 466 | |
443 | - otherRocketLeftSprite = new RocketSprite[64]; | |
444 | - for (int i = 0; i < otherRocketLeftSprite.length; ++i) { | |
445 | - otherRocketLeftSprite[i] = new RocketSprite( | |
446 | - rocketLeftRegion, "otherRocketLeftSprite" + i, | |
447 | - x, width, y, height, true, 8); | |
448 | - otherRocketLeftSprite[i].setLastFrameStick(true); | |
449 | - append(otherRocketLeftSprite[i]); | |
450 | - rocketLeftPool.add(otherRocketLeftSprite[i]); | |
451 | - } | |
452 | - otherRocketRightSprite = new RocketSprite[64]; | |
453 | - for (int i = 0; i < otherRocketRightSprite.length; ++i) { | |
454 | - otherRocketRightSprite[i] = new RocketSprite( | |
455 | - rocketRightRegion, "otherRocketRightSprite" + i, | |
456 | - x, width, y, height, true, 8); | |
457 | - otherRocketRightSprite[i].setLastFrameStick(true); | |
458 | - append(otherRocketRightSprite[i]); | |
459 | - rocketRightPool.add(otherRocketRightSprite[i]); | |
460 | - } | |
461 | 467 | miniBossSprite = new ExtendedSprite[4]; |
462 | 468 | for (int i = 0; i < miniBossSprite.length; ++i) { |
463 | 469 | miniBossSprite[i] = new ExtendedSprite(miniBossRegion[i], "miniBossSprite" + i, |
@@ -1681,6 +1687,30 @@ | ||
1681 | 1687 | return giveLifePool; |
1682 | 1688 | } |
1683 | 1689 | |
1690 | + public ExtendedSpritePool<RocketSprite> getOtherRocketLeftPool() { | |
1691 | + return otherRocketLeftPool; | |
1692 | + } | |
1693 | + | |
1694 | + public ExtendedSpritePool<RocketSprite> getOtherRocketRightPool() { | |
1695 | + return otherRocketRightPool; | |
1696 | + } | |
1697 | + | |
1698 | + public ExtendedSpritePool<RocketSprite> getOtherRocketTripleCenterPool() { | |
1699 | + return otherRocketTripleCenterPool; | |
1700 | + } | |
1701 | + | |
1702 | + public ExtendedSpritePool<RocketSprite> getOtherRocketTripleLeftPool() { | |
1703 | + return otherRocketTripleLeftPool; | |
1704 | + } | |
1705 | + | |
1706 | + public ExtendedSpritePool<RocketSprite> getOtherRocketTripleRightPool() { | |
1707 | + return otherRocketTripleRightPool; | |
1708 | + } | |
1709 | + | |
1710 | + public ExtendedSpritePool<RocketSprite> getOtherRocketDoubleDamagePool() { | |
1711 | + return otherRocketDoubleDamagePool; | |
1712 | + } | |
1713 | + | |
1684 | 1714 | public ExtendedSprite getArrowsSprite() { |
1685 | 1715 | return arrowsSprite; |
1686 | 1716 | } |
@@ -244,11 +244,6 @@ | ||
244 | 244 | for (int i = nlayers; --i >= 0;) { |
245 | 245 | ExtendedSprite comp = (ExtendedSprite) component[i]; |
246 | 246 | if (comp.isVisible()) { |
247 | - // IMPL NOTE: do this if outside Graphics clip region don't | |
248 | - // paint | |
249 | - // (comp.contains(x - comp.x, y - comp.y)) && | |
250 | - // paint will happen only in clipped region of view window | |
251 | - // comp.paint(g); | |
252 | 247 | comp.draw(batch); |
253 | 248 | } |
254 | 249 | } |
@@ -296,11 +296,15 @@ | ||
296 | 296 | if (rocketLeftSprite != null) { |
297 | 297 | rocketLeftSprite.launch(getX() + (getWidth() * 0.5f) - (rocketLeftSprite.getWidth() * 0.5f), |
298 | 298 | getY() - rocketLeftSprite.getHeight() - normalRocketDist); |
299 | + } else { | |
300 | + System.out.println("rocketLeftSprite == null"); | |
299 | 301 | } |
300 | 302 | RocketSprite rocketRightSprite = graphicsManager.getRocketRightPool().removeOne(); |
301 | 303 | if (rocketRightSprite != null) { |
302 | 304 | rocketRightSprite.launch(getX() + (getWidth() * 0.5f) - (rocketRightSprite.getWidth() * 0.5f), |
303 | 305 | getY() - rocketRightSprite.getHeight() - normalRocketDist); |
306 | + } else { | |
307 | + System.out.println("rocketRightSprite == null"); | |
304 | 308 | } |
305 | 309 | if (Preferences.getInstance().isSoundEnabled()) { |
306 | 310 | launchSnd.play(); |