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; /* w w w . jav a 2 s .c o m*/ import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.scenes.scene2d.Actor; public class Ballista extends Actor{ private float angle=0.0f; private boolean attacking; private int frame; private BattleScreen screen; private Texture mine; private Texture arrow; private final float X,Y; private int mineFrLen; public Ballista(BattleScreen s,Texture t,Texture a,int h, int coordinateY){ mine=t; arrow=a; mineFrLen=t.getWidth()/Constants.BALLISTA_FRAMES; screen=s; this.setHeight(h); int width=(int) (h*t.getWidth()/(t.getHeight()*Constants.BALLISTA_FRAMES)); this.setWidth(width); X=-(int)((width)*Constants.DISPLACEMENT_X_BALLISTA); Y=coordinateY; attacking=false; frame=0; Constants.ARROW_VELOCITY=(int) ((Constants.BACKWIDTH*0.7f) /(Constants.ARROW_TIME*Math.cos(Constants.MAX_ANGLE_BALLISTA*Math.PI/180))); Constants.GRAVITY=(float) ((-(Y+this.getHeight()/2)-Math.sin(Math.PI/4) *Constants.ARROW_VELOCITY*Constants.ARROW_TIME)/(Constants.ARROW_TIME *Constants.ARROW_TIME/2)); } public void changeAttack(){ attacking=!attacking; frame=0; } public void changeAngle(int i){ if(Math.abs(angle+i)<Constants.MAX_ANGLE_BALLISTA) angle=angle+i; } @Override public void draw(Batch batch,float parentAlpha){ this.drawMine(batch,screen.getBg().getCoordsX()); } private void drawMine(Batch batch,int currX){ if(!attacking || frame==Constants.BALLISTA_FRAMES){ if(frame==Constants.BALLISTA_FRAMES) screen.addArrow(new BallistaArrow(screen,Constants.ARROW_VELOCITY,X+this.getWidth()/ 12,Y+this.getHeight()/2,angle,arrow)); frame=0; } batch.draw(mine, X-currX, Y,this.getWidth()/2, 0, this.getWidth(), this.getHeight(), 1, 1, angle,frame*mineFrLen, 0,mineFrLen, mine.getHeight(), false, false); frame++; } }