Skip to content

Commit

Permalink
Enemy bat animation idle, iaBurra
Browse files Browse the repository at this point in the history
  • Loading branch information
elisandro-tnb committed Dec 17, 2021
1 parent 4eb6e89 commit ddf2416
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 7 deletions.
Binary file added res/bat_tex.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 35 additions & 3 deletions src/com/ks2002br/entities/Enemy.java
Expand Up @@ -5,6 +5,7 @@
import java.awt.*;
import java.util.LinkedList;

import com.ks2002br.frameworks.Animation;
import com.ks2002br.frameworks.GameObject;
import com.ks2002br.frameworks.ObjectId;
import com.ks2002br.game.Game;
Expand All @@ -15,22 +16,53 @@ public class Enemy extends GameObject {
private int tipo;
private Texturas tex = Game.getInstance();

private Animation animIdle;

private int posInit = 0;
private int dir = 1;
private int pixelsTemp = 64;

public Enemy(float x, float y, int t, ObjectId id) {
super(x, y, id);
this.tipo = t;

posInit = (int) x;

animIdle = new Animation(10,tex.bat_idle);

}

public void tick(LinkedList<GameObject> obj) {
x += spdX;
y += spdY;

animIdle.runAnimation();

iaBurra();

}

private void iaBurra() {

if(dir == 1) {
if(x <= posInit + pixelsTemp) spdX = 1; // 50 <= 50+64=114
else dir = -1;
}else {
if(x >= posInit) spdX = -1;
else dir = 1;
}

}

public void render(Graphics g) {
// g.setColor(Color.blue);
g.setColor(Color.red);
// g.fillRect((int) x, (int) y, 64, 64);
g.drawString("X = "+x+ " dir = "+dir, (int) x,(int) y);
//if(tipo== 0) g.drawImage(tex.enemy[0],(int) x,(int) y,null);
//if(tipo== 1) g.drawImage(tex.enemy[1],(int) x,(int) y, null);

if(tipo== 0) g.drawImage(tex.enemy[0],(int) x,(int) y,null);
if(tipo== 1) g.drawImage(tex.enemy[1],(int) x,(int) y, null);
//Animacao idle teste
animIdle.renderAnimation(g,(int) x, (int) y);

}

Expand Down
6 changes: 3 additions & 3 deletions src/com/ks2002br/graficos/CarregarImagem.java
Expand Up @@ -12,10 +12,10 @@ public class CarregarImagem {

private BufferedImage img;

public BufferedImage pegarImagem(String caminho) {
public BufferedImage pegarImagem(String path) {
try {
img = ImageIO.read(getClass().getResource(caminho));
System.out.println("[DEBUG CarregarImagem] CARREGANDO IMAGEM - COMPLETO!");
img = ImageIO.read(getClass().getResource(path));
System.out.println("[DEBUG CarregarImagem] CARREGANDO IMAGEM: "+path);
return img;
} catch (IOException | IllegalArgumentException e) {
System.err.println("[DEBUG CarregarImagem] Não foi localizado o arquivo pedido! Sistema sera encerrado! \n");
Expand Down
12 changes: 11 additions & 1 deletion src/com/ks2002br/graficos/Texturas.java
Expand Up @@ -5,8 +5,10 @@
public class Texturas {

private FolhaSprites blockSheet, enemySheet, playerSheet; //Instancia/referencia
private FolhaSprites batSheet;

private BufferedImage bloco_tex, enemy_tex, player_tex;
private BufferedImage bat_tex;

public BufferedImage[] block = new BufferedImage[4]; //SPRITES DOS BLOCOS
public BufferedImage[] enemy = new BufferedImage[2]; //SPRITES DOS BLOCOS
Expand All @@ -17,14 +19,16 @@ public class Texturas {
public BufferedImage[] playerLeft = new BufferedImage[8]; // SPRITES DO PLAYER ESQUERDA
public BufferedImage[] playerRight = new BufferedImage[8]; // SPRITES DO PLAYER DIREITA

public BufferedImage[] bat_idle = new BufferedImage[4];

public Texturas() {
CarregarImagem loader = new CarregarImagem();
try {

bloco_tex = loader.pegarImagem("/bloco_tex.png ");
enemy_tex = loader.pegarImagem("/enemy_tex.png ");
player_tex = loader.pegarImagem("/player_tex.png ");
player_tex = loader.pegarImagem("/player_tex.png ");
bat_tex = loader.pegarImagem("/bat_tex.png ");

System.out.println("[DEBUG TEXTURA] TEXTURAS CARREGADAS COM SUCESSO!");
} catch (Exception e) {
Expand All @@ -34,6 +38,7 @@ public Texturas() {
blockSheet = new FolhaSprites(bloco_tex);
enemySheet = new FolhaSprites(enemy_tex);
playerSheet = new FolhaSprites(player_tex);
batSheet = new FolhaSprites(bat_tex);

getTextures();

Expand Down Expand Up @@ -75,6 +80,11 @@ private void getTextures() {
player_idle[0] = playerSheet.pegarSpriteColRow(7, 2, 32,64); //FRAME 01
player_idle[1] = playerSheet.pegarSpriteColRow(8, 2, 32,64); //FRAME 02


for (int i = 0; i < bat_idle.length; i++) {
bat_idle[i] = batSheet.pegarSpriteColRow(i+1, 1, 32, 32);
}

}

//94
Expand Down

0 comments on commit ddf2416

Please sign in to comment.