spaceshooter:start
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende Überarbeitung | |||
spaceshooter:start [2023/03/03 07:40] – [Gedanken bei der Erstellung des Klassendiagramms] Martin Pabst | spaceshooter:start [2023/06/11 15:22] (aktuell) – [Gedanken bei der Erstellung des Klassendiagramms] Martin Pabst | ||
---|---|---|---|
Zeile 31: | Zeile 31: | ||
Beachte die Zusätze "{ abstract }" im Klassendiagramm erstmal nicht. Du wirst weiter unten erfahren, was es damit auf sich hat. | Beachte die Zusätze "{ abstract }" im Klassendiagramm erstmal nicht. Du wirst weiter unten erfahren, was es damit auf sich hat. | ||
</ | </ | ||
+ | |||
+ | ===== Einfachere Variante... ===== | ||
+ | < | ||
+ | <div class=" | ||
+ | |||
+ | <script type=" | ||
+ | new Main(); | ||
+ | |||
+ | class Main extends Actor { | ||
+ | |||
+ | | ||
+ | | ||
+ | |||
+ | Text caption; | ||
+ | |||
+ | int score = 0; | ||
+ | Text scoreDisplay; | ||
+ | |||
+ | int lastTimeSpacePressed; | ||
+ | |||
+ | | ||
+ | |||
+ | caption = new Text(400, 200, 60, "Space shooter" | ||
+ | caption.setAlignment(Alignment.center); | ||
+ | |||
+ | scoreDisplay = new Text(10, 10, 32, " | ||
+ | |||
+ | spaceship = new Spaceship(400, | ||
+ | | ||
+ | setState(" | ||
+ | } | ||
+ | |||
+ | | ||
+ | if(state == " | ||
+ | |||
+ | | ||
+ | new Target(this); | ||
+ | } | ||
+ | |||
+ | | ||
+ | new Powerup(this); | ||
+ | } | ||
+ | |||
+ | } else if(isKeyDown(" | ||
+ | | ||
+ | | ||
+ | case " | ||
+ | | ||
+ | | ||
+ | case " | ||
+ | | ||
+ | | ||
+ | default : | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | } | ||
+ | |||
+ | | ||
+ | | ||
+ | switch(newState) { | ||
+ | case " | ||
+ | caption.setVisible(true); | ||
+ | spaceship.setVisible(false); | ||
+ | caption.setText(" | ||
+ | break; | ||
+ | case " | ||
+ | score = 0; | ||
+ | displayScore(); | ||
+ | caption.setVisible(false); | ||
+ | spaceship.setVisible(true); | ||
+ | break; | ||
+ | case " | ||
+ | caption.setVisible(true); | ||
+ | spaceship.setVisible(false); | ||
+ | caption.setText(" | ||
+ | break; | ||
+ | | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | state = newState; | ||
+ | } | ||
+ | |||
+ | | ||
+ | score += delta; | ||
+ | displayScore(); | ||
+ | } | ||
+ | |||
+ | | ||
+ | scoreDisplay.setText(score); | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | <script type=" | ||
+ | class Spaceship extends Sprite { | ||
+ | |||
+ | int spaceLastPressedTime = 0; | ||
+ | Main main; | ||
+ | |||
+ | Gun gun; | ||
+ | |||
+ | | ||
+ | super(x, y, SpriteLibrary.Space_Shooter_2, | ||
+ | this.main = main; | ||
+ | this.gun = new SimpleGun(); | ||
+ | scale(2); | ||
+ | } | ||
+ | |||
+ | | ||
+ | if(main.state != " | ||
+ | | ||
+ | if(isKeyDown(Key.ArrowLeft)) { | ||
+ | | ||
+ | } | ||
+ | |||
+ | if(isKeyDown(Key.ArrowRight)) { | ||
+ | | ||
+ | } | ||
+ | |||
+ | int time = System.currentTimeMillis(); | ||
+ | |||
+ | if(isKeyDown(" | ||
+ | | ||
+ | | ||
+ | } | ||
+ | |||
+ | if(getFirstCollidingSprite(9) != null) { | ||
+ | | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | }</ | ||
+ | <script type=" | ||
+ | class Bullet extends Circle { | ||
+ | |||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | super(x, y, 10); | ||
+ | this.vx = vx; | ||
+ | this.vy = vy; | ||
+ | this.sendToBack(); | ||
+ | this.setFillColor(0xff0000); | ||
+ | } | ||
+ | |||
+ | | ||
+ | move(vx, vy); | ||
+ | if(isOutsideView()) { | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | }</ | ||
+ | <script type=" | ||
+ | interface Gun { | ||
+ | |||
+ | | ||
+ | |||
+ | | ||
+ | |||
+ | } | ||
+ | |||
+ | class SimpleGun implements Gun { | ||
+ | |||
+ | public void shoot(double x, double y, Main main) { | ||
+ | new Bullet(x, y, 0, -10); | ||
+ | } | ||
+ | |||
+ | public double getTimeToReload() { | ||
+ | return 700; // 700 ms | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | class TripleGun implements Gun { | ||
+ | public void shoot(double x, double y, Main main) { | ||
+ | new Bullet(x, y, -7, -7); | ||
+ | new Bullet(x, y, 0, -10); | ||
+ | new Bullet(x, y, 7, -7); | ||
+ | } | ||
+ | |||
+ | public double getTimeToReload() { | ||
+ | return 500; // 700 ms | ||
+ | } | ||
+ | |||
+ | }</ | ||
+ | <script type=" | ||
+ | public class Target extends Sprite { | ||
+ | |||
+ | | ||
+ | | ||
+ | Main main; | ||
+ | |||
+ | | ||
+ | super(Random.randint(0, | ||
+ | this.vx = Random.randint(-5, | ||
+ | this.vy = Random.randint(3, | ||
+ | this.main = main; | ||
+ | } | ||
+ | |||
+ | | ||
+ | |||
+ | move(vx, vy); | ||
+ | |||
+ | if(getCenterY() > 620) { | ||
+ | | ||
+ | | ||
+ | } | ||
+ | |||
+ | if(collidesWithFillColor(0xff0000)) { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | <script type=" | ||
+ | public class Powerup extends Sprite { | ||
+ | |||
+ | | ||
+ | | ||
+ | Main main; | ||
+ | |||
+ | | ||
+ | super(Random.randint(0, | ||
+ | this.vx = Random.randint(-5, | ||
+ | this.vy = Random.randint(3, | ||
+ | this.main = main; | ||
+ | } | ||
+ | |||
+ | | ||
+ | |||
+ | move(vx, vy); | ||
+ | rotate(3); | ||
+ | |||
+ | if(getCenterY() > 620) { | ||
+ | | ||
+ | | ||
+ | } | ||
+ | |||
+ | if(getFirstCollidingSprite(4) != null) { | ||
+ | | ||
+ | | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | </ | ||
spaceshooter/start.1677829220.txt.gz · Zuletzt geändert: 2023/03/03 07:40 von Martin Pabst