• R/O
  • SSH

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Révision773ac24449fb2b8b88723bf9bf2b887bf27bf623 (tree)
l'heure2021-12-03 07:04:58
Auteursebastian_bugiu
Commitersebastian_bugiu

Message de Log

Various improvements. Animation texture region split seems to be working.

Change Summary

Modification

diff -r 9547586d5610 -r 773ac24449fb core/src/com/headwayent/spacerocket/Utility.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/core/src/com/headwayent/spacerocket/Utility.java Fri Dec 03 00:04:58 2021 +0200
@@ -0,0 +1,45 @@
1+package com.headwayent.spacerocket;
2+
3+import com.badlogic.gdx.graphics.g2d.TextureRegion;
4+
5+public class Utility {
6+
7+ public static TextureRegion[][] splitFlipped(TextureRegion region, int tileWidth, int tileHeight) {
8+ int x = region.getRegionX();
9+ int y = Math.round(region.getV2() * region.getTexture().getHeight());
10+ int width = region.getRegionWidth();
11+ int height = region.getRegionHeight();
12+
13+ int rows = height / tileHeight;
14+ int cols = width / tileWidth;
15+
16+ int startX = x;
17+ TextureRegion[][] tiles = new TextureRegion[rows][cols];
18+ for (int row = 0; row < rows; row++, y += tileHeight) {
19+ x = startX;
20+ for (int col = 0; col < cols; col++, x += tileWidth) {
21+ tiles[row][col] = new TextureRegion(region.getTexture(), x, y, tileWidth, tileHeight);
22+ tiles[row][col].flip(false, true);
23+ }
24+ }
25+
26+ return tiles;
27+ }
28+
29+ public static void printStackTrace() {
30+ System.out.println("Printing stack trace:");
31+ StackTraceElement[] elements = Thread.currentThread().getStackTrace();
32+ for (int i = 1; i < elements.length; i++) {
33+ StackTraceElement s = elements[i];
34+ System.out.println("\tat " + s.getClassName() + "." + s.getMethodName() + "(" + s.getFileName() + ":" + s.getLineNumber() + ")");
35+ }
36+ }
37+
38+ public static boolean hasTimePassed(long beginTime, long waitTime) {
39+ return System.currentTimeMillis() - beginTime > waitTime;
40+ }
41+
42+ public static long currentTimeMillis() {
43+ return System.currentTimeMillis();
44+ }
45+}
diff -r 9547586d5610 -r 773ac24449fb core/src/com/headwayent/spacerocket/old/ExtendedSprite.java
--- a/core/src/com/headwayent/spacerocket/old/ExtendedSprite.java Wed Dec 01 21:08:58 2021 +0200
+++ b/core/src/com/headwayent/spacerocket/old/ExtendedSprite.java Fri Dec 03 00:04:58 2021 +0200
@@ -9,6 +9,7 @@
99 import com.badlogic.gdx.graphics.g2d.TextureAtlas;
1010 import com.badlogic.gdx.graphics.g2d.TextureRegion;
1111 import com.headwayent.spacerocket.SpaceRocket;
12+import com.headwayent.spacerocket.Utility;
1213
1314 public class ExtendedSprite extends Sprite {
1415
@@ -41,18 +42,20 @@
4142 super(textureRegion);
4243 this.numFrames = frames;
4344 if (frames > 1) {
44- textureRegion.setRegionWidth(textureRegion.getRegionWidth() / frames);
45- setRegion(textureRegion);
46- setSize(textureRegion.getRegionWidth(), textureRegion.getRegionHeight());
47- TextureRegion[][] split = TextureRegion.split(textureRegion.getTexture(), textureRegion.getTexture().getWidth() / frames, 1);
45+ TextureRegion[][] split = Utility.splitFlipped(textureRegion, textureRegion.getRegionWidth() / frames, textureRegion.getRegionHeight());
46+ if (split[0].length != frames) {
47+ throw new IllegalArgumentException(frames + " frames split len: " + split[0].length);
48+ }
49+ setRegion(split[0][0]);
50+ setSize(split[0][0].getRegionWidth(), split[0][0].getRegionHeight());
4851 animation = new Animation<>(0.25f, split[0]);
49-// setRegion(split[0][0]);
5052 }
53+ setOrigin(0, 0);
5154 setBounds(leftBound, rightBound, upperBound, bottomBound);
5255 this.name = name;
5356 setVisible(false);
5457 }
55-
58+
5659 public void setBounds(float leftBound, float rightBound, float upperBound, float bottomBound) {
5760 this.leftBound = leftBound;
5861 this.rightBound = rightBound;
@@ -81,12 +84,14 @@
8184 }
8285
8386 public void reset() {
87+ System.out.println("Resetting " + name);
8488 setVisible(false);
8589 if (animation != null) {
8690 animationStateTime = 0;
8791 lastFrameReached = false;
8892 }
8993 if (pool != null) {
94+ System.out.println("Readding " + name + " to pool " + pool);
9095 pool.add(this);
9196 }
9297 }
@@ -216,6 +221,8 @@
216221
217222 public void setVisible(boolean visible) {
218223 this.visible = visible;
224+ System.out.println("visibility: " + visible + " name: " + name);
225+// Utility.printStackTrace();
219226 }
220227
221228 public boolean isHiddenAfterLastFrame() {
diff -r 9547586d5610 -r 773ac24449fb core/src/com/headwayent/spacerocket/old/ExtendedSpritePool.java
--- a/core/src/com/headwayent/spacerocket/old/ExtendedSpritePool.java Wed Dec 01 21:08:58 2021 +0200
+++ b/core/src/com/headwayent/spacerocket/old/ExtendedSpritePool.java Fri Dec 03 00:04:58 2021 +0200
@@ -9,8 +9,13 @@
99 if (sprite.isVisible()) {
1010 throw new IllegalStateException(sprite.getName() + " is still visible");
1111 }
12- sprite.setPool(this);
13- spriteList.add(sprite);
12+// if (spriteList.contains(sprite)) {
13+// throw new IllegalArgumentException(sprite.getName() + " is already in the list");
14+// }
15+ if (!spriteList.contains(sprite)) {
16+ sprite.setPool(this);
17+ spriteList.add(sprite);
18+ }
1419 }
1520
1621 public T removeOne() {
diff -r 9547586d5610 -r 773ac24449fb core/src/com/headwayent/spacerocket/old/GraphicsManager.java
--- a/core/src/com/headwayent/spacerocket/old/GraphicsManager.java Wed Dec 01 21:08:58 2021 +0200
+++ b/core/src/com/headwayent/spacerocket/old/GraphicsManager.java Fri Dec 03 00:04:58 2021 +0200
@@ -9,7 +9,6 @@
99 import com.headwayent.spacerocket.SpaceRocket;
1010
1111 import java.util.Random;
12-import java.util.concurrent.atomic.AtomicBoolean;
1312
1413 public class GraphicsManager extends LayerManager {
1514
@@ -884,11 +883,9 @@
884883
885884 if (explode) {
886885 Vector2 p = spaceRocket.getSPPos();
887- for (int j = 0; j < explosion.length; ++j) {
888- if (explosion[j].isVisible() == false) {
889- explosion[j].launch(p.x, p.y);
890- break;
891- }
886+ ExplosionSprite explosionSprite = getExplosionPool().removeOne();
887+ if (explosionSprite != null) {
888+ explosionSprite.launch(p.x, p.y);
892889 }
893890 }
894891 if (spaceCanvas.getStatus().livesRemaining == 0) {
@@ -1144,7 +1141,7 @@
11441141 spaceRocket.changeFrame(SpaceRocketSprite.TRIPLE_FIRE_FRAME);
11451142 break;
11461143 case 4: //Invincibility
1147- spaceRocket.EnableInvincibility();
1144+ spaceRocket.enableInvincibility();
11481145 break;
11491146 default:
11501147 System.out.println("Powerup Type error " + type);
@@ -1179,7 +1176,7 @@
11791176 otherSpaceRocket.changeFrame(SpaceRocketSprite.TRIPLE_FIRE_FRAME);
11801177 break;
11811178 case 3:
1182- otherSpaceRocket.EnableInvincibility();
1179+ otherSpaceRocket.enableInvincibility();
11831180 break;
11841181 default:
11851182 break;
@@ -1531,7 +1528,6 @@
15311528 flamesSprite[1].setVisible(false);
15321529 }
15331530 if ((otherSpaceRocket.isInvincibilityEnabled()) && (otherSpaceRocket.isVisible())) {
1534- otherSpaceRocket.DecrementInvincibilityTicks();
15351531 shieldSprite[1].setPosition(otherSpaceRocket.getX(), otherSpaceRocket.getY());
15361532 shieldSprite[1].setVisible(true);
15371533 // shieldSprite[1].nextFrame();
@@ -1597,12 +1593,10 @@
15971593 for (int j = 0; j < enemyrocketSprite.length; ++j) {
15981594 if ((rocket[i].isVisible()) && (enemyrocketSprite[j].isVisible())) {
15991595 if (rocket[i].checkCollision(enemyrocketSprite[j])) {
1600- for (int k = 0; k < explosion.length; ++k) {
1601- if (explosion[k].isVisible() == false) {
1602- explosion[k].launch(rocket[i].getX(),
1603- rocket[i].getY());
1604- break;
1605- }
1596+ ExplosionSprite explosionSprite = getExplosionPool().removeOne();
1597+ if (explosionSprite != null) {
1598+ explosionSprite.launch(rocket[i].getX(),
1599+ rocket[i].getY());
16061600 }
16071601 if (i < rocket.length - 1) {
16081602 ++i;
diff -r 9547586d5610 -r 773ac24449fb core/src/com/headwayent/spacerocket/old/RocketSprite.java
--- a/core/src/com/headwayent/spacerocket/old/RocketSprite.java Wed Dec 01 21:08:58 2021 +0200
+++ b/core/src/com/headwayent/spacerocket/old/RocketSprite.java Fri Dec 03 00:04:58 2021 +0200
@@ -4,10 +4,10 @@
44
55 import com.badlogic.gdx.graphics.g2d.TextureAtlas;
66 import com.badlogic.gdx.graphics.g2d.TextureRegion;
7+import com.headwayent.spacerocket.SpaceRocket;
78
89 public class RocketSprite extends ExtendedSprite {
910
10- private Random rand;
1111 private boolean upDirection;
1212 private boolean doubleDamage;
1313 public static final int _SR_SPEED = -12;
@@ -23,8 +23,6 @@
2323 super(textureRegion, name,
2424 leftBound, rightBound, upperBound, bottomBound, numFrames,
2525 true);
26- rand = new Random(System.currentTimeMillis());
27- setVisible(false);
2826 this.upDirection = upDirection;
2927 SR_SPEED = (ExtendedCanvas.getScreenWidth() > GraphicsManager.MIN_WIDTH ||
3028 ExtendedCanvas.getScreenHeight() > ExtendedCanvas.getScreenHeight()) ? _SR_SPEED : _SR_SPEED_SM;
@@ -51,29 +49,6 @@
5149 return ret;
5250 }
5351
54- /* public void SetPosition(int x, int y) {
55- XPos = x;
56- YPos = y;
57- }
58-
59- public int GetXPos() {
60- return XPos;
61- }
62-
63- public int GetYPos() {
64- return YPos;
65- }*/
66- /* public void SetVisible(boolean b) {
67- setVisible(b);
68- }*/
69- /* public void reset() {
70- setVisible(false);
71- released = true;
72- }*/
73- /* public boolean isReleased() {
74- return released;
75- }*/
76-
7752 @Override
7853 public void launch(float x, float y) {
7954 // this.upDirection = upDirection;
@@ -83,7 +58,7 @@
8358 if (upDirection) {
8459 speedY = SR_SPEED;
8560 } else {
86- speedY = rand.nextInt(ENEMY_SPEED) + (ENEMY_SPEED >> 2);
61+ speedY = SpaceRocket.getRandom().nextInt(ENEMY_SPEED) + (ENEMY_SPEED >> 2);
8762 }
8863 setSpeed(0, speedY);
8964 // released = true;
diff -r 9547586d5610 -r 773ac24449fb core/src/com/headwayent/spacerocket/old/SpaceRocketSprite.java
--- a/core/src/com/headwayent/spacerocket/old/SpaceRocketSprite.java Wed Dec 01 21:08:58 2021 +0200
+++ b/core/src/com/headwayent/spacerocket/old/SpaceRocketSprite.java Fri Dec 03 00:04:58 2021 +0200
@@ -6,13 +6,15 @@
66 import com.badlogic.gdx.math.Vector2;
77 import com.headwayent.spacerocket.Preferences;
88 import com.headwayent.spacerocket.SpaceRocket;
9+import com.headwayent.spacerocket.Utility;
910
1011 import java.util.concurrent.atomic.AtomicBoolean;
1112
1213
1314 public class SpaceRocketSprite extends ExtendedSprite {
1415 private float initialXPos, initialYPos;// XPos, YPos;
15- private int invincibilityTicks;
16+ private long invincibilityTime;
17+ private long currentInvincibilityTime;
1618 private static final int FIRE_DELAY = 500;
1719 public static int SR_ACC_SPEED;
1820 public static int SR_MAX_SPEED;
@@ -36,7 +38,7 @@
3638 public static final int TRIPLE_FIRE_FRAME = 2;
3739 public static final int INVINCIBILITY_FRAME = 0;
3840 private static final int NUM_FRAMES = 3;
39- private static final int INVINCIBILITY_TICKS = 90;
41+ private static final long INVINCIBILITY_TICKS = 5000;
4042 private static final int _DOUBLE_DAMAGE_SPEED = -7;
4143 private static final int _DOUBLE_DAMAGE_SPEED_SM = -4;
4244 private static int DOUBLE_DAMAGE_SPEED;
@@ -150,7 +152,7 @@
150152
151153 s.resetExplode();
152154 }
153- if ((invincibilityTicks == 0)) {
155+ if (Utility.hasTimePassed(currentInvincibilityTime, invincibilityTime)) {
154156 // if(gfxMgmt.getStatus().LivesRemaining - 1 > 0) {
155157 spPos.x = this.getX();
156158 spPos.y = this.getY();
@@ -190,8 +192,13 @@
190192 return ret;
191193 }
192194
193- public void EnableInvincibility() {
194- invincibilityTicks = INVINCIBILITY_TICKS;
195+ public void enableInvincibility() {
196+ enableInvincibilityInternal(INVINCIBILITY_TICKS);
197+ }
198+
199+ private void enableInvincibilityInternal(long invincibilityTicks) {
200+ invincibilityTime = invincibilityTicks;
201+ currentInvincibilityTime = Utility.currentTimeMillis();
195202 }
196203
197204 public void reset() {
@@ -201,7 +208,7 @@
201208 speedX = 0;
202209 speedY = 0;
203210 currentDelay = 0;
204- invincibilityTicks = 30;
211+ enableInvincibilityInternal(2000);
205212 lives = NUM_LIVES;
206213 changeFrame(STD_FRAME);
207214 shouldReset = true;
@@ -264,11 +271,7 @@
264271 }
265272
266273 public boolean isInvincibilityEnabled() {
267- if (invincibilityTicks > 0) {
268- return true;
269- } else {
270- return false;
271- }
274+ return !Utility.hasTimePassed(currentInvincibilityTime, invincibilityTime);
272275 }
273276
274277 synchronized public void move(boolean useDelta) {
@@ -285,12 +288,6 @@
285288 }
286289 }
287290
288- synchronized public void DecrementInvincibilityTicks() {
289- if (invincibilityTicks > 0) {
290- --invincibilityTicks;
291- }
292- }
293-
294291 synchronized public void launchRocket() {
295292 if ((System.currentTimeMillis() - currentDelay) > FIRE_DELAY) {
296293 currentDelay = System.currentTimeMillis();
@@ -425,9 +422,6 @@
425422 }
426423
427424 void advance(int left, int up, int shoot) {
428- if (invincibilityTicks > 0) {
429- --invincibilityTicks;
430- }
431425 synchronized (this) {
432426 if (left == -1) {
433427 if (speedX - SR_ACC_SPEED < -SR_MAX_SPEED) {