Advertisement
Zidinjo

Fimn

Jun 27th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.92 KB | None | 0 0
  1. package minigame;
  2. import fhfl.miniGame.engine.MiniGame.Action;
  3. import fhfl.miniGame.engine.Sprite;
  4.  
  5. public class Spieler extends Sprite
  6. {
  7.  
  8.   private int zaehler = 0;
  9.   private int richtungWahl;
  10.   private final int GRENZEHORI = 20;
  11.   private final int GRENZEVERTI = 560;
  12.   private final int BEWEGUNGSGESCH = 30;
  13.   private final int SCROLLPOWER = 40;
  14.   private final int SCROLLPOWERFIRE = 600;
  15.   private int spielerPunkte = 0;
  16.   private boolean nurEinMal = true;
  17.  
  18.   Spieler(int xKordi,int yKordi,MyMiniGame thegame)
  19.   {
  20.     super(yKordi, yKordi, thegame); // Kontruktor bekommt die gleichen Parameter wie die Sprite klasse, da wir von Sprite geerbt haben
  21.     this.paintImage("playerone.jpg"); // Die Klasse bekommt eine Grafik zugeordnet
  22.   }
  23.  
  24.   public void getroffen(Sprite otherSprite)
  25.   {
  26.    
  27.     if(this.overlapsSprite(otherSprite)) // Wenn der Schuss getroffen hat +10 punkte
  28.     {
  29.       if(nurEinMal)
  30.       {
  31.         spielerPunkte +=10;
  32.         otherSprite.dontShow(); // Schuss wird ausgeschaltet
  33.         nurEinMal = false; // Damit der Schuss nur 1x zählt, sonst wird der Punktestand ständig erhöht.
  34.       }
  35.      
  36.     }
  37.   }
  38.  
  39.   protected int getSpielerPunkte()
  40.   {
  41.     return this.spielerPunkte;
  42.   }
  43.  
  44.   protected void setSpielerPunkte(int punkte)
  45.   {
  46.     this.spielerPunkte = punkte;
  47.   }
  48.  
  49.   protected int getZaehler()
  50.   {
  51.     return this.zaehler;
  52.   }
  53.  
  54.   protected void Spielerbewegung(Action aktion,Sprite[] shot) //Spielerbewegung Left right usw.
  55.   {
  56.     switch(aktion)
  57.     {
  58.       case LEFT:
  59.         if(this.getXPosition() < GRENZEHORI) // If Abfrage, ist die Position der Grafik nicht mehr im Spielfeld wird auf sein vorherigen Wert gesetzt
  60.         {
  61.           this.setPosition(getXPosition()+BEWEGUNGSGESCH, getYPosition());
  62.         }
  63.         this.animateTo(getXPosition()-BEWEGUNGSGESCH, getYPosition(), SCROLLPOWER); // hier wird die Grafik bewegt.
  64.         richtungWahl = 1; // Benötigen wir um den Schuss in die richtige Richtung zu schießen
  65.         break;
  66.       case RIGHT:
  67.         if(this.getXPosition() > GRENZEVERTI)
  68.         {
  69.           this.setPosition(getXPosition()-BEWEGUNGSGESCH, getYPosition());
  70.         }
  71.         this.animateTo(getXPosition()+BEWEGUNGSGESCH, getYPosition(), SCROLLPOWER);
  72.         richtungWahl = 1;
  73.         break;
  74.       case GO:
  75.           nurEinMal = true;
  76.           zaehler++; // Damit wir mehrer Schusse aus dem Array nehmen
  77.           shot[zaehler-1].dontShow();
  78.           switch(richtungWahl)
  79.           {
  80.            case 1:
  81.              shot[zaehler].setPosition(this.getXPosition(), this.getYPosition()); // Schuss beginnt beim Spieler
  82.              shot[zaehler].animateTo(this.getXPosition(), this.getYPosition()-SCROLLPOWERFIRE, SCROLLPOWERFIRE); // Schuss wird in eine Richtung geschossen
  83.              shot[zaehler].show(); // Wird angezeigt
  84.              break;
  85.           }
  86.         break;
  87.       default:
  88.         break;
  89.     }
  90.   }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement