Back to project page diploma-assignment.
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.
package com.me.battlescreen; // ww w . ja v a2 s .co m import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.scenes.scene2d.Actor; public class Castle extends Actor implements IHittable{ private Texture texture; private int height,width; private float X,Y; private BattleScreen screen; private BattlePlayer player; private int health; private boolean hitted; private boolean opponent; public Castle(BattleScreen s,BattlePlayer p,Texture t,int h, int coordinateY,boolean opp,int health){ screen=s; player=p; height=h; opponent=opp; width=(int)(height*t.getWidth()/t.getHeight()); texture=t; X=0; Y=coordinateY; this.setWidth(width); this.setHeight(height); hitted=false; this.health=health; } public void setX(float x){ X=x; } @Override public void draw(Batch batch,float parentAlpha){ this.drawMine(batch,screen.getBg().getCoordsX()); } public void drawMine(Batch batch, int currX) { if(hitted){ batch.setColor(Color.RED); } batch.draw(texture,X-currX,Y,this.getWidth(),this.getHeight()); batch.setColor(Color.WHITE); hitted=false; } @Override public void hit(float x1, float x2, int attack) { // TODO Auto-generated method stub if((x1<X+width && x2>X) || (x1<X+width && x2>X)) hitted(attack); } @Override public float giveX() { // TODO Auto-generated method stub if(opponent) return X; else return X+width; } @Override public void arrowHit(float x1, float y1, float x2, float y2, int attack,boolean ballista) { // TODO Auto-generated method stub if(!ballista){ if (((x1>X && x1 < X+width/2) && (y1<Y+height && y1>Y)) || ((x2>X && x2<X+width/2) && (y2<Y+height && y2>Y))){ hitted(attack); } } } private void hitted(int attack) { // TODO Auto-generated method stub if(health>=0){ health-=attack; if(health<=0){ if(opponent) screen.setWinner(true); screen.endGame(); } hitted=true; } } @Override public boolean enemy(BattlePlayer p) { // TODO Auto-generated method stub return player!=p; } @Override public BattlePlayer getPlayer() { // TODO Auto-generated method stub return player; } }