Skip to content

Commit

Permalink
Updated Sprite & IA
Browse files Browse the repository at this point in the history
  • Loading branch information
thoniorf committed Dec 1, 2015
1 parent 5d03c8a commit ef63e64
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 88 deletions.
112 changes: 51 additions & 61 deletions src/it/batteringvalhalla/gamecore/IA/IAFocus.java
Original file line number Diff line number Diff line change
@@ -1,87 +1,77 @@
package it.batteringvalhalla.gamecore.IA;






import java.util.List;


import it.batteringvalhalla.gamecore.arena.Arena;
import it.batteringvalhalla.gamecore.object.actor.Actor;
import it.batteringvalhalla.gamecore.object.AbstractGameObject;
import it.batteringvalhalla.gamecore.object.actor.Direction;
import it.batteringvalhalla.gamecore.object.actor.Enemy;
import it.batteringvalhalla.gamecore.object.AbstractGameObject;

public class IAFocus extends AbstractIA {
private static final int timeMove = 2000;
private int timePause;
private int timePause;
private AbstractGameObject myEnemy;
private List<AbstractGameObject> players;
public IAFocus(Enemy npc, Arena arena,List<AbstractGameObject> players,Actor actor) {
private List<AbstractGameObject> players;

public IAFocus(Enemy npc, Arena arena, List<AbstractGameObject> players) {
super(npc, arena);
this.players= players;
timePause=1000;
}
this.players = players;
timePause = 1000;

}

protected AbstractGameObject getEnemyClose() {
AbstractGameObject tmp=null;

int radiusTmp,radiusPlayer;
for(int i=0;i<players.size();i++){
if(npc!=players.get(i)){
if(tmp!=null){
radiusTmp=Math.abs(tmp.getX()-npc.getX())+Math.abs(tmp.getY()-npc.getY());
radiusPlayer=Math.abs(players.get(i).getX()-npc.getX())+Math.abs(players.get(i).getY()-npc.getY());
if(radiusTmp>radiusPlayer)
tmp=players.get(i);
}
else
tmp=players.get(i);}}
AbstractGameObject tmp = null;

int radiusTmp, radiusPlayer;
for (int i = 0; i < players.size(); i++) {
if (npc != players.get(i)) {
if (tmp != null) {
radiusTmp = Math.abs(tmp.getX() - npc.getX()) + Math.abs(tmp.getY() - npc.getY());
radiusPlayer = Math.abs(players.get(i).getX() - npc.getX())
+ Math.abs(players.get(i).getY() - npc.getY());
if (radiusTmp > radiusPlayer)
tmp = players.get(i);
} else
tmp = players.get(i);
}
}
return tmp;
}


public void levelUp(){
if(timePause>199)
timePause-=200;

public void levelUp() {
if (timePause > 199)
timePause -= 200;
}
public void update(){
myEnemy=getEnemyClose();



@Override
public void update() {
myEnemy = getEnemyClose();

currentime = System.currentTimeMillis();

if(npc.getCollisionShape().intersects(myEnemy.getCollisionShape()))
{startime=Math.abs((long)timeMove-currentime);

}


if (currentime - startime <timeMove&&(this.canMove(npc.getX(), npc.getY()))){

if(Math.abs(myEnemy.getX()-npc.getX())>=Math.abs(myEnemy.getY()-npc.getY())){
if(myEnemy.getX()>npc.getX())

if (npc.getCollisionShape().intersects(myEnemy.getCollisionShape())) {
startime = Math.abs(timeMove - currentime);

}

if (currentime - startime < timeMove && (this.canMove(npc.getX(), npc.getY()))) {

if (Math.abs(myEnemy.getX() - npc.getX()) >= Math.abs(myEnemy.getY() - npc.getY())) {
if (myEnemy.getX() > npc.getX())
npc.setDirection(Direction.est);
else
npc.setDirection(Direction.ovest);
}
else {
if(myEnemy.getY()>npc.getY())
} else {
if (myEnemy.getY() > npc.getY())
npc.setDirection(Direction.sud);
else
else
npc.setDirection(Direction.nord);
}
}
else if (currentime-startime>=timeMove+timePause){
startime=currentime;
}

}

} else if (currentime - startime >= timeMove + timePause) {
startime = currentime;
}

}

}
81 changes: 54 additions & 27 deletions src/it/batteringvalhalla/gamecore/animation/Sprite.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,43 @@

public class Sprite {

private BufferedImage img;
private Integer counter;
private Integer currentFrame;
private Integer endFrame;
private BufferedImage frame;
private Integer framesPerRow;
private Integer frameWidth;
private Integer frameCol;
private Integer frameHeight;
private Integer endFrame;
private Integer frameSpeed;
private Integer currentFrame;
private Integer counter;
private Integer frameRow;
private Integer frameCol;
private Direction imgDir;
private Integer frameSpeed;
private Integer framesPerRow;
private Integer frameWidth;
private Integer currentoffsetx;
private Integer spriteoffsetxleft;
private Integer spriteoffsetxright;
private Integer spriteoffsety;
private Graphics2D g2;

public Integer getFrameRow() {
return frameRow;
}

public Integer getFrameCol() {
return frameCol;
}
private Integer imageHeight;
private Integer imageWidth;
private BufferedImage img;
private Direction imgDir;

public Sprite(Image img, Integer imageWidth, Integer imageHeight,
Integer frameWidth, Integer frameHeight, Integer frameSpeed,
Integer endFrame) {
Integer endFrame, Integer offxleft, Integer offxright, Integer offy) {
this.imgDir = Direction.est;
this.imageWidth = imageWidth;
this.imageHeight = imageHeight;
this.frameWidth = frameWidth;
this.frameHeight = frameHeight;
this.frameRow = new Integer(1);
this.frameCol = new Integer(1);
this.spriteoffsetxleft = offxleft;
this.spriteoffsetxright = offxright;
this.spriteoffsety = offy;
this.frameRow = new Integer(0);
this.frameCol = new Integer(0);
this.endFrame = endFrame;
this.frameSpeed = frameSpeed;
this.currentFrame = new Integer(1);
framesPerRow = new Integer(imageWidth / frameWidth);
this.counter = new Integer(0);
this.img = new BufferedImage(imageWidth, imageHeight,
BufferedImage.TYPE_INT_ARGB);
Expand All @@ -53,10 +57,36 @@ public Sprite(Image img, Integer imageWidth, Integer imageHeight,
g2.setComposite(AlphaComposite.Src);
g2.drawImage(img, 0, 0, null);
g2.dispose();
g2.setComposite(AlphaComposite.Src);
g2 = this.frame.createGraphics();
g2.dispose();
framesPerRow = new Integer(imageWidth / frameWidth);
}

public BufferedImage getFrame() {
return frame;
}

public Integer getOffsetX() {
return currentoffsetx;
}

public Integer getOffsetY() {
return spriteoffsety;
}

public Integer getFrameCol() {
return frameCol;
}

public Integer getFrameRow() {
return frameRow;
}

public Integer getImageHeight() {
return imageHeight;
}

public Integer getImageWidth() {
return imageWidth;
}

public void update(Direction dir) {
Expand All @@ -70,20 +100,17 @@ public void update(Direction dir) {
g2.setComposite(AlphaComposite.Src);
g2.drawImage(img.getSubimage(frameCol * frameWidth, frameRow
* frameHeight, frameWidth, frameHeight), 0, 0, null);

g2.dispose();
currentoffsetx = spriteoffsetxright;
if (dir == Direction.ovest || imgDir == Direction.ovest) {
AffineTransform tx = AffineTransform.getScaleInstance(-1, 1);
tx.translate(-frame.getWidth(null), 0);
AffineTransformOp op = new AffineTransformOp(tx,
AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
frame = op.filter(frame, null);
currentoffsetx = spriteoffsetxleft;
imgDir = ((dir == Direction.ovest && imgDir == Direction.est) || (dir == Direction.est && imgDir == Direction.ovest)) ? dir
: imgDir;
}
}

public BufferedImage getFrame() {
return frame;
}
}

0 comments on commit ef63e64

Please sign in to comment.