Android Open Source - diploma-assignment Player Monster






From Project

Back to project page diploma-assignment.

License

The source code is released under:

MIT License

If you think the Android project diploma-assignment listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.me.battlescreen;
/*from w  ww .  j a v  a 2  s.  co  m*/

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;

public class PlayerMonster extends Monster{
  
  protected Texture Element;
  protected int FRAMES;
  
  protected final int height;

  protected float currX;
  protected float currY;
  
  protected final float OFFSET;
  
  protected int frame;
  protected int health;
  protected int attack;
  protected int gold;

  protected Texture[] textures;
  protected int data[];

  protected BattleScreen screen;
  protected boolean hitted;
  protected boolean walking,attacking,dying;
  protected int ScreenFrameWidth;
  protected int ElFrLen;
  protected int change;
  protected int attackDistance;
  protected BattlePlayer player;
  
  public PlayerMonster(BattleScreen s,Texture[] t,int[] d,BattlePlayer p){
    super(p);
    screen=s;
    textures=t;
    data=d;
    change=0;
    player=p;
    height=data[5];
    attackDistance=height*textures[2].getWidth()/(textures[2].getHeight()*data[1]);
    changeToWalk();
    currX = data[3];
    currY = data[4];
    attack=data[6];
    health=data[7];
    gold=health/10;
    hitted=false;
    OFFSET=Constants.BACKWIDTH/(Constants.FRAMES*Constants.SECONDS_FOR_BACKGROUND);
  }
  
  @Override
  protected void changeToWalk(){
    FRAMES=data[0];
    Element=textures[0];
    changeWidths();
    dying=attacking=false;
    walking=true;
  }
  
  @Override
  protected void changeToAttacking(){
    attacking=true;
    Element=textures[2];
    FRAMES=data[1];
    changeWidths();
    walking=dying=false;
    
  }
  
  @Override
  protected void changeToDie(){
    dying=true;
    Element=textures[1];
    FRAMES=data[2];
    walking=attacking=false;
    screen.removeAttacking(this);
    screen.removeHittable(this);
    changeWidths();
  }
  
  @Override
  protected void changeWidths() {
    ScreenFrameWidth=(int)(height*Element.getWidth()/(Element.getHeight()*FRAMES));
    ElFrLen=Element.getWidth()/FRAMES;
    frame=0;
  }
  
  
  
  @Override
  public void draw(Batch batch,float delta){
    draw(batch,screen.getBg().getCoordsX());
  }
  
  @Override
  public void draw(Batch batch, int coordsX) {
    // TODO Auto-generated method stub
    if (frame == FRAMES){
      if (dying){
        screen.removeActor(this);
        return;
      }
      frame = 0;
    }
    if(walking){
      currX += OFFSET;
    }
    if(hitted){
      batch.setColor(Color.RED);
    }
    batch.draw(Element, currX-coordsX, currY, 0, 0, ScreenFrameWidth, height, 1, 1,
        0,frame*ElFrLen, 0,ElFrLen, Element.getHeight(), false, false);
    if(hitted){
      batch.setColor(Color.WHITE);
    }
    hitted=false;
    if(change%3==0)
      frame++;
    change++;
  }
  
  @Override
  public void arrowHit(float x1,float y1,float x2,float y2,
      int attack,boolean ballista){
    if(!dying){
      if (((x1>currX && x1 < currX+ScreenFrameWidth/2) && 
          (y1<currY+height && y1>currY)) ||
      ((x2>currX && x2<currX+ScreenFrameWidth/2) && 
          (y2<currY+height && y2>currY))){
        hitted(attack);
      }
    }
  }
  
  @Override
  public void hit(float x1,float x2,int attack) {
    if(!dying && (x1<currX+ScreenFrameWidth && x2>currX))
      hitted(attack);
  }
  
  @Override
  protected void hitted(int attack) {
    health-=attack;
    hitted=true;
    if(health<=0){
      changeToDie();
    }
  }
  
  @Override
  public float giveX() {
    return currX+ScreenFrameWidth;
  }
  
  

  @Override
  public boolean isAttacking() {
    // TODO Auto-generated method stub
    return attacking;
  }

  @Override
  public void checkForAttack(float x) {
    if(!dying){
      if (x<currX+attackDistance){
        if(!isAttacking())
          changeToAttacking();
      }else if(!walking && !dying) 
        changeToWalk();
    }
  }

  @Override
  public float getStart() {
    return currX;
  }

  @Override
  public float getEnd() {
    return currX+ScreenFrameWidth;
  }

  @Override
  public int getAttack() {
    return attack;
  }

  @Override
  public boolean timeToAttack() {
    return frame==FRAMES-1 && change%3==0;
  }

  @Override
  public BattlePlayer getPlayer() {
    // TODO Auto-generated method stub
    return player;
  }
  
  @Override
  public int getGold(){
    return gold;
  }
  
}




Java Source Code List

com.me.battlescreen.BallistaArrow.java
com.me.battlescreen.Ballista.java
com.me.battlescreen.BattlePlayer.java
com.me.battlescreen.BattleScreen.java
com.me.battlescreen.Bot.java
com.me.battlescreen.Castle.java
com.me.battlescreen.CleanBackground.java
com.me.battlescreen.ComputerPlayer.java
com.me.battlescreen.Constants.java
com.me.battlescreen.HumanPlayer.java
com.me.battlescreen.Monster.java
com.me.battlescreen.MyButton.java
com.me.battlescreen.MyLabel.java
com.me.battlescreen.OpponentMonster.java
com.me.battlescreen.PlayerMonster.java
com.me.battlescreen.TimeLabel.java
com.me.battlescreen.UnitButton.java
com.me.battlescreen.getTextures.java
com.me.battlescreen.iAttacking.java
com.me.battlescreen.iHittable.java
com.me.battlescreen.iUpdateable.java
com.me.main.MyGame.java
com.me.main.Player.java
com.me.mygdxgame.MainActivity.java
com.me.openingscreen.AbstractMenu.java
com.me.openingscreen.Constants.java
com.me.openingscreen.FirstMenu.java
com.me.openingscreen.FloatingBackground.java
com.me.openingscreen.OpeningScreen.java
com.me.openingscreen.PlayerMenu.java
com.me.openingscreen.ResetMenu.java
com.me.openingscreen.StatisticsMenu.java
com.me.openingscreen.UpgradeButton.java
com.me.openingscreen.UpgradeMenu.java