Révision | 1b989c04d2141aa0ece861857da161b0ee18eb30 (tree) |
---|---|
l'heure | 2022-01-08 01:31:30 |
Auteur | sebastian_bugiu |
Commiter | sebastian_bugiu |
The arrows now act like a joystick.
@@ -30,7 +30,7 @@ | ||
30 | 30 | applicationId "com.headwayent.spacerocket" |
31 | 31 | minSdkVersion 14 |
32 | 32 | targetSdkVersion 32 |
33 | - versionCode 1 | |
33 | + versionCode 3 | |
34 | 34 | versionName "1.0" |
35 | 35 | } |
36 | 36 | buildTypes { |
@@ -1,14 +1,17 @@ | ||
1 | 1 | package com.headwayent.spacerocket; |
2 | 2 | |
3 | 3 | import com.badlogic.gdx.InputProcessor; |
4 | +import com.badlogic.gdx.math.Vector2; | |
4 | 5 | import com.headwayent.spacerocket.old.ExtendedCanvas; |
5 | 6 | import com.headwayent.spacerocket.old.ExtendedSprite; |
6 | 7 | import com.headwayent.spacerocket.old.GraphicsManager; |
7 | 8 | |
8 | 9 | public class InGameInputProcessor implements InputProcessor { |
9 | 10 | |
11 | + private static float IGNORED_OFFSET = 7.0f; | |
10 | 12 | private int firePointer = -1; |
11 | 13 | private int arrowsPointer = -1; |
14 | + private Vector2 arrowPointerInitialPos = new Vector2(); | |
12 | 15 | private boolean fireSet; |
13 | 16 | private boolean firePressed; |
14 | 17 | private boolean arrowsPressed; |
@@ -16,7 +19,11 @@ | ||
16 | 19 | arrowsRightPressed, |
17 | 20 | arrowsUpPressed, |
18 | 21 | arrowsDownPressed; |
19 | - | |
22 | + private float xLeftArrows; | |
23 | + private float xRightArrows; | |
24 | + private float yTopArrows; | |
25 | + private float yBottomArrows; | |
26 | + | |
20 | 27 | @Override |
21 | 28 | public boolean keyDown(int keycode) { |
22 | 29 | // ExtendedCanvas sc = game.getCanvas(); |
@@ -209,10 +216,10 @@ | ||
209 | 216 | // } else if (!fireSprite.isVisible()) { |
210 | 217 | // return false; |
211 | 218 | // } |
212 | - float xLeftArrows = arrowsSprite.getX(); | |
213 | - float xRightArrows = xLeftArrows + arrowsSprite.getWidth(); | |
214 | - float yTopArrows = arrowsSprite.getY(); | |
215 | - float yBottomArrows = yTopArrows + arrowsSprite.getHeight(); | |
219 | + xLeftArrows = arrowsSprite.getX(); | |
220 | + xRightArrows = xLeftArrows + arrowsSprite.getWidth(); | |
221 | + yTopArrows = arrowsSprite.getY(); | |
222 | + yBottomArrows = yTopArrows + arrowsSprite.getHeight(); | |
216 | 223 | float xLeftFire = fireSprite.getX(); |
217 | 224 | float xRightFire = xLeftFire + fireSprite.getWidth(); |
218 | 225 | float yTopFire = fireSprite.getY(); |
@@ -233,29 +240,30 @@ | ||
233 | 240 | firePressed = true; |
234 | 241 | } else if ((xPos > xLeftArrows) && (xPos < xRightArrows) && |
235 | 242 | (yPos > yTopArrows) && (yPos < yBottomArrows)) { |
236 | - boolean upperDiagonal = isLeft( | |
237 | - xRightArrows, yBottomArrows, | |
238 | - xLeftArrows, yTopArrows, | |
239 | - xPos, yPos); | |
240 | - boolean lowerDiagonal = isLeft( | |
241 | - xRightArrows, yTopArrows, | |
242 | - xLeftArrows, yBottomArrows, | |
243 | - xPos, yPos); | |
244 | - | |
243 | + arrowPointerInitialPos.set(screenX, screenY); | |
244 | +// boolean upperDiagonal = isLeft( | |
245 | +// xRightArrows, yBottomArrows, | |
246 | +// xLeftArrows, yTopArrows, | |
247 | +// xPos, yPos); | |
248 | +// boolean lowerDiagonal = isLeft( | |
249 | +// xRightArrows, yTopArrows, | |
250 | +// xLeftArrows, yBottomArrows, | |
251 | +// xPos, yPos); | |
252 | +// | |
245 | 253 | arrowsPointer = pointer; |
246 | - if ((upperDiagonal) && (lowerDiagonal)) { | |
247 | - game.getCanvas().recordKeyPressed(ExtendedCanvas.UP); | |
248 | - arrowsUpPressed = true; | |
249 | - } else if ((upperDiagonal) && (!lowerDiagonal)) { | |
250 | - game.getCanvas().recordKeyPressed(ExtendedCanvas.RIGHT); | |
251 | - arrowsRightPressed = true; | |
252 | - } else if ((!upperDiagonal) && (!lowerDiagonal)) { | |
253 | - game.getCanvas().recordKeyPressed(ExtendedCanvas.DOWN); | |
254 | - arrowsDownPressed = true; | |
255 | - } else if ((!upperDiagonal) && (lowerDiagonal)) { | |
256 | - game.getCanvas().recordKeyPressed(ExtendedCanvas.LEFT); | |
257 | - arrowsLeftPressed = true; | |
258 | - } | |
254 | +// if ((upperDiagonal) && (lowerDiagonal)) { | |
255 | +// game.getCanvas().recordKeyPressed(ExtendedCanvas.UP); | |
256 | +// arrowsUpPressed = true; | |
257 | +// } else if ((upperDiagonal) && (!lowerDiagonal)) { | |
258 | +// game.getCanvas().recordKeyPressed(ExtendedCanvas.RIGHT); | |
259 | +// arrowsRightPressed = true; | |
260 | +// } else if ((!upperDiagonal) && (!lowerDiagonal)) { | |
261 | +// game.getCanvas().recordKeyPressed(ExtendedCanvas.DOWN); | |
262 | +// arrowsDownPressed = true; | |
263 | +// } else if ((!upperDiagonal) && (lowerDiagonal)) { | |
264 | +// game.getCanvas().recordKeyPressed(ExtendedCanvas.LEFT); | |
265 | +// arrowsLeftPressed = true; | |
266 | +// } | |
259 | 267 | |
260 | 268 | // gfx.getArrowsSprite().setImage(gfx.getArrowsPressedBitmap(), |
261 | 269 | // gfx.getArrowsPressedBitmap().getWidth(), |
@@ -328,6 +336,7 @@ | ||
328 | 336 | game.getCanvas().recordKeyReleased(ExtendedCanvas.RIGHT); |
329 | 337 | game.getCanvas().recordKeyReleased(ExtendedCanvas.DOWN); |
330 | 338 | game.getCanvas().recordKeyReleased(ExtendedCanvas.LEFT); |
339 | + gfx.resetArrowSpritePosition(); | |
331 | 340 | } |
332 | 341 | return true; |
333 | 342 | } |
@@ -337,10 +346,6 @@ | ||
337 | 346 | SpaceRocket game = SpaceRocket.getGame(); |
338 | 347 | ExtendedSprite arrowsSprite = game.getCanvas().getGraphicsManager().getArrowsSprite(); |
339 | 348 | ExtendedSprite fireSprite = game.getCanvas().getGraphicsManager().getFireSprite(); |
340 | - float xLeftArrows = arrowsSprite.getX(); | |
341 | - float xRightArrows = xLeftArrows + arrowsSprite.getWidth(); | |
342 | - float yTopArrows = arrowsSprite.getY(); | |
343 | - float yBottomArrows = yTopArrows + arrowsSprite.getHeight(); | |
344 | 349 | float xLeftFire = fireSprite.getX(); |
345 | 350 | float xRightFire = xLeftFire + fireSprite.getWidth(); |
346 | 351 | float yTopFire = fireSprite.getY(); |
@@ -351,41 +356,67 @@ | ||
351 | 356 | if (arrowsPointer == pointer) { |
352 | 357 | if ((xPos > xLeftArrows) && (xPos < xRightArrows) && |
353 | 358 | (yPos > yTopArrows) && (yPos < yBottomArrows)) { |
354 | - boolean upperDiagonal = isLeft( | |
355 | - xRightArrows, yBottomArrows, | |
356 | - xLeftArrows, yTopArrows, | |
357 | - xPos, yPos); | |
358 | - boolean lowerDiagonal = isLeft( | |
359 | - xRightArrows, yTopArrows, | |
360 | - xLeftArrows, yBottomArrows, | |
361 | - xPos, yPos); | |
362 | - | |
363 | - if ((upperDiagonal) && (lowerDiagonal)) { | |
364 | - game.getCanvas().recordKeyPressed(ExtendedCanvas.UP); | |
365 | - arrowsUpPressed = true; | |
366 | - } else if ((upperDiagonal) && (!lowerDiagonal)) { | |
359 | + float xDiff = screenX - arrowPointerInitialPos.x; | |
360 | + float yDiff = screenY - arrowPointerInitialPos.y; | |
361 | + xDiff = Utility.clamp(xDiff, -GraphicsManager.ARROWS_X_OFFSET, GraphicsManager.ARROWS_X_OFFSET); | |
362 | + yDiff = Utility.clamp(yDiff, -GraphicsManager.ARROWS_X_OFFSET, GraphicsManager.ARROWS_X_OFFSET); | |
363 | + gfx.resetArrowSpritePosition(); | |
364 | + gfx.getArrowsSprite().move(xDiff, yDiff); | |
365 | + if (xDiff > IGNORED_OFFSET) { | |
366 | + game.getCanvas().recordKeyReleased(ExtendedCanvas.LEFT); | |
367 | 367 | game.getCanvas().recordKeyPressed(ExtendedCanvas.RIGHT); |
368 | - arrowsRightPressed = true; | |
369 | - } else if ((!upperDiagonal) && (!lowerDiagonal)) { | |
368 | + } else if (xDiff < -IGNORED_OFFSET) { | |
369 | + game.getCanvas().recordKeyReleased(ExtendedCanvas.RIGHT); | |
370 | + game.getCanvas().recordKeyPressed(ExtendedCanvas.LEFT); | |
371 | + } else { | |
372 | + game.getCanvas().recordKeyReleased(ExtendedCanvas.LEFT); | |
373 | + game.getCanvas().recordKeyReleased(ExtendedCanvas.RIGHT); | |
374 | + } | |
375 | + if (yDiff > IGNORED_OFFSET) { | |
376 | + game.getCanvas().recordKeyReleased(ExtendedCanvas.UP); | |
370 | 377 | game.getCanvas().recordKeyPressed(ExtendedCanvas.DOWN); |
371 | - arrowsDownPressed = true; | |
372 | - } else if ((!upperDiagonal) && (lowerDiagonal)) { | |
373 | - game.getCanvas().recordKeyPressed(ExtendedCanvas.LEFT); | |
374 | - arrowsLeftPressed = true; | |
378 | + } else if (yDiff < -IGNORED_OFFSET) { | |
379 | + game.getCanvas().recordKeyReleased(ExtendedCanvas.DOWN); | |
380 | + game.getCanvas().recordKeyPressed(ExtendedCanvas.UP); | |
381 | + } else { | |
382 | + game.getCanvas().recordKeyReleased(ExtendedCanvas.UP); | |
383 | + game.getCanvas().recordKeyReleased(ExtendedCanvas.DOWN); | |
375 | 384 | } |
376 | - | |
377 | -// gfx.getArrowsSprite().setImage(gfx.getArrowsPressedBitmap(), | |
378 | -// gfx.getArrowsPressedBitmap().getWidth(), | |
379 | -// gfx.getArrowsPressedBitmap().getHeight()); | |
380 | - if ((upperDiagonal) && (lowerDiagonal)) { | |
381 | - game.getCanvas().recordKeyReleased(ExtendedCanvas.UP); | |
382 | - } else if ((upperDiagonal) && (!lowerDiagonal)) { | |
383 | - game.getCanvas().recordKeyReleased(ExtendedCanvas.RIGHT); | |
384 | - } else if ((!upperDiagonal) && (!lowerDiagonal)) { | |
385 | - game.getCanvas().recordKeyReleased(ExtendedCanvas.DOWN); | |
386 | - } else if ((!upperDiagonal) && (lowerDiagonal)) { | |
387 | - game.getCanvas().recordKeyReleased(ExtendedCanvas.LEFT); | |
388 | - } | |
385 | +// boolean upperDiagonal = isLeft( | |
386 | +// xRightArrows, yBottomArrows, | |
387 | +// xLeftArrows, yTopArrows, | |
388 | +// xPos, yPos); | |
389 | +// boolean lowerDiagonal = isLeft( | |
390 | +// xRightArrows, yTopArrows, | |
391 | +// xLeftArrows, yBottomArrows, | |
392 | +// xPos, yPos); | |
393 | +// | |
394 | +// if ((upperDiagonal) && (lowerDiagonal)) { | |
395 | +// game.getCanvas().recordKeyPressed(ExtendedCanvas.UP); | |
396 | +// arrowsUpPressed = true; | |
397 | +// } else if ((upperDiagonal) && (!lowerDiagonal)) { | |
398 | +// game.getCanvas().recordKeyPressed(ExtendedCanvas.RIGHT); | |
399 | +// arrowsRightPressed = true; | |
400 | +// } else if ((!upperDiagonal) && (!lowerDiagonal)) { | |
401 | +// game.getCanvas().recordKeyPressed(ExtendedCanvas.DOWN); | |
402 | +// arrowsDownPressed = true; | |
403 | +// } else if ((!upperDiagonal) && (lowerDiagonal)) { | |
404 | +// game.getCanvas().recordKeyPressed(ExtendedCanvas.LEFT); | |
405 | +// arrowsLeftPressed = true; | |
406 | +// } | |
407 | +// | |
408 | +//// gfx.getArrowsSprite().setImage(gfx.getArrowsPressedBitmap(), | |
409 | +//// gfx.getArrowsPressedBitmap().getWidth(), | |
410 | +//// gfx.getArrowsPressedBitmap().getHeight()); | |
411 | +// if ((upperDiagonal) && (lowerDiagonal)) { | |
412 | +// game.getCanvas().recordKeyReleased(ExtendedCanvas.UP); | |
413 | +// } else if ((upperDiagonal) && (!lowerDiagonal)) { | |
414 | +// game.getCanvas().recordKeyReleased(ExtendedCanvas.RIGHT); | |
415 | +// } else if ((!upperDiagonal) && (!lowerDiagonal)) { | |
416 | +// game.getCanvas().recordKeyReleased(ExtendedCanvas.DOWN); | |
417 | +// } else if ((!upperDiagonal) && (lowerDiagonal)) { | |
418 | +// game.getCanvas().recordKeyReleased(ExtendedCanvas.LEFT); | |
419 | +// } | |
389 | 420 | } |
390 | 421 | } |
391 | 422 | return true; |
@@ -60,7 +60,7 @@ | ||
60 | 60 | } |
61 | 61 | |
62 | 62 | public int getShipMovementType() { |
63 | - return prefs.getInteger(SHIP_MOVEMENT_TYPE, 3); | |
63 | + return prefs.getInteger(SHIP_MOVEMENT_TYPE, 2); | |
64 | 64 | } |
65 | 65 | |
66 | 66 | public void setShipMovementType(int shipMovementType) { |
@@ -47,4 +47,8 @@ | ||
47 | 47 | public static boolean intersects(Sprite s0, Sprite s1) { |
48 | 48 | return s0.getX() < s1.getX() + s1.getWidth() && s0.getX() + s0.getWidth() > s1.getX() && s0.getY() < s1.getY() + s1.getHeight() && s0.getY() + s0.getHeight() > s1.getY(); |
49 | 49 | } |
50 | + | |
51 | + public static float clamp(float val, float min, float max) { | |
52 | + return Math.max(min, Math.min(max, val)); | |
53 | + } | |
50 | 54 | } |
@@ -50,6 +50,7 @@ | ||
50 | 50 | private static final int PLANET_NUM = 8; |
51 | 51 | public static final int ENEMY_LAUNCH_MISSILE_RAND = 100; |
52 | 52 | public static final int STAR_SPRITE_LAUNCH_RAND = 50; |
53 | + public static final int ARROWS_X_OFFSET = 20; | |
53 | 54 | private final TextureAtlas.AtlasRegion spaceRocketRegion; |
54 | 55 | private final TextureAtlas.AtlasRegion otherSpaceRocketRegion; |
55 | 56 | private final TextureAtlas.AtlasRegion touchArrowsPressedRegion; |
@@ -768,13 +769,17 @@ | ||
768 | 769 | ExtendedCanvas.getScreenHeight() - atmosphereSprite.getHeight()); |
769 | 770 | } |
770 | 771 | } |
772 | + | |
773 | + public void resetArrowSpritePosition() { | |
774 | + float arrowsX = ExtendedCanvas.getScreenWidth() - ARROWS_X_OFFSET - touchArrowsPressedRegion.getRegionWidth(); | |
775 | + float arrowsY = ExtendedCanvas.getScreenHeight() - 100 - touchArrowsPressedRegion.getRegionHeight(); | |
776 | + arrowsSprite.setPosition(arrowsX, arrowsY); | |
777 | + } | |
771 | 778 | |
772 | 779 | public void setControlsVisible(boolean visible) { |
773 | 780 | float fireX = 10; |
774 | 781 | float fireY = ExtendedCanvas.getScreenHeight() - 100 - touchFireRegion.getRegionHeight(); |
775 | - float arrowsX = ExtendedCanvas.getScreenWidth() - 10 - touchArrowsPressedRegion.getRegionWidth(); | |
776 | - float arrowsY = ExtendedCanvas.getScreenHeight() - 100 - touchArrowsPressedRegion.getRegionHeight(); | |
777 | - arrowsSprite.setPosition(arrowsX, arrowsY); | |
782 | + resetArrowSpritePosition(); | |
778 | 783 | fireSprite.setPosition(fireX, fireY); |
779 | 784 | if (!Preferences.getInstance().isAccelerometerEnabled()) { |
780 | 785 | arrowsSprite.setVisible(visible); |
@@ -1,6 +1,6 @@ | ||
1 | -app.version=1.0 | |
1 | +app.version=1.1 | |
2 | 2 | app.id=com.headwayent.spacerocket |
3 | 3 | app.mainclass=com.headwayent.spacerocket.IOSLauncher |
4 | 4 | app.executable=IOSLauncher |
5 | -app.build=1 | |
5 | +app.build=3 | |
6 | 6 | app.name=Hotshot 2D |