no way to compare when less than two revisions
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Letzte Überarbeitung | |||
— | schule:klassen:2019:10abc:sidescroller2 [2020/03/31 21:47] – angelegt martin | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
+ | ====== Projekt: Sidescroller-Game (Stand nach der 2. Hausaufgabe) ====== | ||
+ | Hier die Programmdateien Stand 26.03.2020: | ||
+ | |||
+ | ==== Die Klasse Sidescroller ==== | ||
+ | <code java> | ||
+ | World w = new World(800, 600); | ||
+ | |||
+ | new Sidescroller(); | ||
+ | |||
+ | |||
+ | class Sidescroller extends Actor { | ||
+ | |||
+ | | ||
+ | Group bullets = new Group(); | ||
+ | Group enemies = new Group(); | ||
+ | |||
+ | int points = 0; | ||
+ | Text pointsText = new Text(5, 5, 40, "0 Punkte" | ||
+ | |||
+ | int lives = 3; | ||
+ | Text livesText = new Text(795, 5, 40, lives + " Leben" | ||
+ | |||
+ | | ||
+ | super(); | ||
+ | // Hier startet das Programm | ||
+ | raumschiff = new Raumschiff(this); | ||
+ | livesText.setAlignment(Alignment.right); | ||
+ | } | ||
+ | |||
+ | | ||
+ | Bullet b = new Bullet(x, y, vx, vy, radius); | ||
+ | bullets.add(b); | ||
+ | } | ||
+ | |||
+ | | ||
+ | generateEnemies(); | ||
+ | checkCollisionsBulletsWithEnemies(); | ||
+ | } | ||
+ | |||
+ | | ||
+ | if(Math.random() < 0.05) { | ||
+ | Enemy e = new Enemy(); | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | |||
+ | | ||
+ | | ||
+ | CollisionPair[] pairs = bullets.getCollisionPairs(enemies, | ||
+ | |||
+ | for(int i = 0; i < pairs.length; | ||
+ | |||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | |||
+ | | ||
+ | |||
+ | new Explosion(r.getCenterX(), | ||
+ | |||
+ | | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | | ||
+ | pointsText.setText(points + " Punkte" | ||
+ | livesText.setText(lives + " Leben" | ||
+ | } | ||
+ | |||
+ | | ||
+ | points = points + p; | ||
+ | updateText(); | ||
+ | | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Die Klasse Raumschiff ==== | ||
+ | <code java> | ||
+ | |||
+ | class Raumschiff extends Sprite { | ||
+ | |||
+ | | ||
+ | | ||
+ | int timeSinceLastBullet = 0; | ||
+ | |||
+ | | ||
+ | |||
+ | super(80, 270, SpriteLibrary.Ship_Adrian, | ||
+ | scale(2); | ||
+ | sidescroller = s; | ||
+ | |||
+ | } | ||
+ | |||
+ | | ||
+ | |||
+ | if(isKeyDown(Key.ArrowUp)) { | ||
+ | | ||
+ | move(0, -v); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | if(isKeyDown(Key.ArrowDown)) { | ||
+ | | ||
+ | move(0, v); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | if(isKeyDown(Key.ArrowRight)) { | ||
+ | | ||
+ | move(v, 0); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | if(isKeyDown(Key.ArrowLeft)) { | ||
+ | | ||
+ | move(-v, 0); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | timeSinceLastBullet++; | ||
+ | if(isKeyDown(" | ||
+ | | ||
+ | System.playSound(Sound.shoot); | ||
+ | if(timeSinceLastBullet > 30) { | ||
+ | | ||
+ | } else { | ||
+ | | ||
+ | } | ||
+ | timeSinceLastBullet = 0; | ||
+ | } | ||
+ | |||
+ | } | ||
+ | | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Die Klasse Bullet ==== | ||
+ | <code java> | ||
+ | |||
+ | |||
+ | class Bullet extends Circle { | ||
+ | |||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | super(x, y, radius); | ||
+ | vx = vx1; | ||
+ | vy = vy1; | ||
+ | setFillColor(Color.white); | ||
+ | |||
+ | } | ||
+ | |||
+ | | ||
+ | move(vx, vy); | ||
+ | if(isOutsideView()) { | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Die Klasse Enemy ==== | ||
+ | <code java> | ||
+ | class Enemy extends Rectangle { | ||
+ | |||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | |||
+ | super(850, Math.random() * 600, Math.random() * 250 + 50, Math.random() * 250 + 50); | ||
+ | | ||
+ | vy = Math.random()*5 - 2.5; | ||
+ | vx = -Math.random() * 5 - 5; | ||
+ | vw = Math.random() * 10 - 5; | ||
+ | |||
+ | int red = Math.floor(Math.random() * 200 + 56); | ||
+ | int green = Math.floor(Math.random() * 200 + 56); | ||
+ | int blue = Math.floor(Math.random() * 200 + 56); | ||
+ | |||
+ | setFillColor(Color.fromRGBA(red, | ||
+ | |||
+ | |||
+ | } | ||
+ | |||
+ | | ||
+ | move(vx, vy); | ||
+ | rotate(vw); | ||
+ | |||
+ | if(getCenterX() < - 1000) { | ||
+ | | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | } | ||
+ | </ |