Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package minigame;
- import fhfl.miniGame.engine.MiniGame.Action;
- import fhfl.miniGame.engine.Sprite;
- public class Spieler extends Sprite
- {
- private int zaehler = 0;
- private int richtungWahl;
- private final int GRENZEHORI = 20;
- private final int GRENZEVERTI = 560;
- private final int BEWEGUNGSGESCH = 30;
- private final int SCROLLPOWER = 40;
- private final int SCROLLPOWERFIRE = 600;
- private int spielerPunkte = 0;
- private boolean nurEinMal = true;
- Spieler(int xKordi,int yKordi,MyMiniGame thegame)
- {
- super(yKordi, yKordi, thegame); // Kontruktor bekommt die gleichen Parameter wie die Sprite klasse, da wir von Sprite geerbt haben
- this.paintImage("playerone.jpg"); // Die Klasse bekommt eine Grafik zugeordnet
- }
- public void getroffen(Sprite otherSprite)
- {
- if(this.overlapsSprite(otherSprite)) // Wenn der Schuss getroffen hat +10 punkte
- {
- if(nurEinMal)
- {
- spielerPunkte +=10;
- otherSprite.dontShow(); // Schuss wird ausgeschaltet
- nurEinMal = false; // Damit der Schuss nur 1x zählt, sonst wird der Punktestand ständig erhöht.
- }
- }
- }
- protected int getSpielerPunkte()
- {
- return this.spielerPunkte;
- }
- protected void setSpielerPunkte(int punkte)
- {
- this.spielerPunkte = punkte;
- }
- protected int getZaehler()
- {
- return this.zaehler;
- }
- protected void Spielerbewegung(Action aktion,Sprite[] shot) //Spielerbewegung Left right usw.
- {
- switch(aktion)
- {
- case LEFT:
- if(this.getXPosition() < GRENZEHORI) // If Abfrage, ist die Position der Grafik nicht mehr im Spielfeld wird auf sein vorherigen Wert gesetzt
- {
- this.setPosition(getXPosition()+BEWEGUNGSGESCH, getYPosition());
- }
- this.animateTo(getXPosition()-BEWEGUNGSGESCH, getYPosition(), SCROLLPOWER); // hier wird die Grafik bewegt.
- richtungWahl = 1; // Benötigen wir um den Schuss in die richtige Richtung zu schießen
- break;
- case RIGHT:
- if(this.getXPosition() > GRENZEVERTI)
- {
- this.setPosition(getXPosition()-BEWEGUNGSGESCH, getYPosition());
- }
- this.animateTo(getXPosition()+BEWEGUNGSGESCH, getYPosition(), SCROLLPOWER);
- richtungWahl = 1;
- break;
- case GO:
- nurEinMal = true;
- zaehler++; // Damit wir mehrer Schusse aus dem Array nehmen
- shot[zaehler-1].dontShow();
- switch(richtungWahl)
- {
- case 1:
- shot[zaehler].setPosition(this.getXPosition(), this.getYPosition()); // Schuss beginnt beim Spieler
- shot[zaehler].animateTo(this.getXPosition(), this.getYPosition()-SCROLLPOWERFIRE, SCROLLPOWERFIRE); // Schuss wird in eine Richtung geschossen
- shot[zaehler].show(); // Wird angezeigt
- break;
- }
- break;
- default:
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement