Skip to content

Commit

Permalink
Criando itens coletaveis
Browse files Browse the repository at this point in the history
  • Loading branch information
elisandro-tnb committed Dec 23, 2021
1 parent ddf2416 commit 2ff6003
Show file tree
Hide file tree
Showing 13 changed files with 284 additions and 4 deletions.
Binary file added res/itens_tex.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/mapa-01.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions src/com/ks2002br/entities/itens/Ammo.java
@@ -0,0 +1,38 @@
package com.ks2002br.entities.itens;

import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.LinkedList;

import com.ks2002br.frameworks.GameObject;
import com.ks2002br.frameworks.ObjectId;
import com.ks2002br.game.Game;
import com.ks2002br.graficos.Texturas;

public class Ammo extends GameObject {

private Texturas tex = Game.getInstance();

public Ammo(float x, float y, int type, ObjectId id) {
super(x, y, type, id);
}

@Override
public void tick(LinkedList<GameObject> obj) {
}

@Override
public void render(Graphics g) {

if(type == 1) g.drawImage(tex.item[5], (int) x, (int) y, null);
if(type == 2) g.drawImage(tex.item[6], (int) x, (int) y, null);

}

@Override
public Rectangle getBounds() {

return new Rectangle((int) x, (int) y, 32, 32);
}

}
37 changes: 37 additions & 0 deletions src/com/ks2002br/entities/itens/Gun.java
@@ -0,0 +1,37 @@
package com.ks2002br.entities.itens;

import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.LinkedList;

import com.ks2002br.frameworks.GameObject;
import com.ks2002br.frameworks.ObjectId;
import com.ks2002br.game.Game;
import com.ks2002br.graficos.Texturas;

public class Gun extends GameObject {

private Texturas tex = Game.getInstance();

public Gun(float x, float y, int type, ObjectId id) {
super(x, y, type, id);
}

@Override
public void tick(LinkedList<GameObject> obj) {
}

@Override
public void render(Graphics g) {

if(type == 1) g.drawImage(tex.item[4], (int) x, (int) y,null);

}

@Override
public Rectangle getBounds() {

return new Rectangle((int) x, (int) y, 32, 32);
}

}
37 changes: 37 additions & 0 deletions src/com/ks2002br/entities/itens/Key.java
@@ -0,0 +1,37 @@
package com.ks2002br.entities.itens;

import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.LinkedList;

import com.ks2002br.frameworks.GameObject;
import com.ks2002br.frameworks.ObjectId;
import com.ks2002br.game.Game;
import com.ks2002br.graficos.Texturas;

public class Key extends GameObject {

private Texturas tex = Game.getInstance();

public Key(float x, float y, ObjectId id) {
super(x, y, id);
}

@Override
public void tick(LinkedList<GameObject> obj) {
}

@Override
public void render(Graphics g) {

g.drawImage(tex.item[7], (int) x, (int) y,null);

}

@Override
public Rectangle getBounds() {

return new Rectangle((int) x, (int) y, 32, 32);
}

}
38 changes: 38 additions & 0 deletions src/com/ks2002br/entities/itens/KeyCard.java
@@ -0,0 +1,38 @@
package com.ks2002br.entities.itens;

import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.LinkedList;

import com.ks2002br.frameworks.GameObject;
import com.ks2002br.frameworks.ObjectId;
import com.ks2002br.game.Game;
import com.ks2002br.graficos.Texturas;

public class KeyCard extends GameObject {

private Texturas tex = Game.getInstance();

public KeyCard(float x, float y, int type, ObjectId id) {
super(x, y, type, id);
}

@Override
public void tick(LinkedList<GameObject> obj) {
}

@Override
public void render(Graphics g) {

if(type == 1) g.drawImage(tex.item[8], (int) x, (int) y, null);
if(type == 2) g.drawImage(tex.item[9], (int) x, (int) y, null);

}

@Override
public Rectangle getBounds() {

return new Rectangle((int) x, (int) y, 32, 32);
}

}
36 changes: 36 additions & 0 deletions src/com/ks2002br/entities/itens/Medkit.java
@@ -0,0 +1,36 @@
package com.ks2002br.entities.itens;

import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.LinkedList;

import com.ks2002br.frameworks.GameObject;
import com.ks2002br.frameworks.ObjectId;
import com.ks2002br.game.Game;
import com.ks2002br.graficos.Texturas;

public class Medkit extends GameObject {

private Texturas tex = Game.getInstance();

public Medkit(float x, float y, int type, ObjectId id) {
super(x, y, type, id);
}

@Override
public void tick(LinkedList<GameObject> obj) {
}

@Override
public void render(Graphics g) {
if(type == 1) g.drawImage(tex.item[0], (int) x, (int) y,null);
if(type == 2) g.drawImage(tex.item[1], (int) x, (int) y,null);
}

@Override
public Rectangle getBounds() {

return new Rectangle((int) x, (int) y, 32, 32);
}

}
36 changes: 36 additions & 0 deletions src/com/ks2002br/entities/itens/Potion.java
@@ -0,0 +1,36 @@
package com.ks2002br.entities.itens;

import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.LinkedList;

import com.ks2002br.frameworks.GameObject;
import com.ks2002br.frameworks.ObjectId;
import com.ks2002br.game.Game;
import com.ks2002br.graficos.Texturas;

public class Potion extends GameObject {

private Texturas tex = Game.getInstance();

public Potion(float x, float y, int type, ObjectId id) {
super(x, y, type, id);
}

@Override
public void tick(LinkedList<GameObject> obj) {
}

@Override
public void render(Graphics g) {
if(type == 1) g.drawImage(tex.item[2], (int) x, (int) y,null);
if(type == 2) g.drawImage(tex.item[3], (int) x, (int) y,null);
}

@Override
public Rectangle getBounds() {

return new Rectangle((int) x, (int) y, 32, 32);
}

}
17 changes: 17 additions & 0 deletions src/com/ks2002br/frameworks/GameObject.java
Expand Up @@ -15,13 +15,22 @@ public abstract class GameObject {

protected boolean falling = true; //CAINDO
protected boolean jumping = false; // PULO

protected int type;

// construtor
public GameObject(float x, float y, ObjectId id) {
this.x = x;
this.y = y;
this.id = id;
}

public GameObject(float x, float y, int type, ObjectId id) {
this.x = x;
this.y = y;
this.type = type;
this.id = id;
}

public abstract void tick(LinkedList<GameObject> obj);

Expand Down Expand Up @@ -84,6 +93,14 @@ public boolean isJumping() {
public void setJumping(boolean jumping) {
this.jumping = jumping;
}

public int getType() {
return type;
}

public void setType(int type) {
this.type = type;
}



Expand Down
3 changes: 2 additions & 1 deletion src/com/ks2002br/frameworks/ObjectId.java
Expand Up @@ -4,6 +4,7 @@
*/
public enum ObjectId {

PLAYER, ENEMY, ARMA, BALA, SOLIDO, BLOCO;
PLAYER, ENEMY, GUN, AMMO, SOLIDO, BLOCO,
MEDKIT,POTION,KEY,KEY_CARD, BOX_AMMO;

}
2 changes: 1 addition & 1 deletion src/com/ks2002br/game/Game.java
Expand Up @@ -146,7 +146,7 @@ private void render() {

Graphics g = image.getGraphics();
// RENDER DO GAME - PINTANDO A TELA DE FUNCO
g.setColor(new Color(0, 0, 0));
g.setColor(new Color(80,158,216));
g.fillRect(0, 0, LARGURA, ALTURA);
g = bs.getDrawGraphics();
g.drawImage(image, 0, 0, LARGURA * ESCALA, ALTURA * ESCALA, null);
Expand Down
19 changes: 17 additions & 2 deletions src/com/ks2002br/graficos/Texturas.java
Expand Up @@ -5,10 +5,10 @@
public class Texturas {

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

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

public BufferedImage[] block = new BufferedImage[4]; //SPRITES DOS BLOCOS
public BufferedImage[] enemy = new BufferedImage[2]; //SPRITES DOS BLOCOS
Expand All @@ -20,6 +20,7 @@ public class Texturas {
public BufferedImage[] playerRight = new BufferedImage[8]; // SPRITES DO PLAYER DIREITA

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

public Texturas() {
CarregarImagem loader = new CarregarImagem();
Expand All @@ -29,6 +30,7 @@ public Texturas() {
enemy_tex = loader.pegarImagem("/enemy_tex.png ");
player_tex = loader.pegarImagem("/player_tex.png ");
bat_tex = loader.pegarImagem("/bat_tex.png ");
item_tex = loader.pegarImagem("/itens_tex.png ");

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

getTextures();

Expand Down Expand Up @@ -85,6 +88,18 @@ private void getTextures() {
bat_idle[i] = batSheet.pegarSpriteColRow(i+1, 1, 32, 32);
}

// ITENS COLETAVEIS
item[0] = itemSheet.pegarSpritePosXPosY( 0, 0, 32, 32); // MEDKIT GRANDE
item[1] = itemSheet.pegarSpritePosXPosY( 32, 0, 32, 32); // MEDKIT PEQUENO
item[2] = itemSheet.pegarSpritePosXPosY( 64, 0, 32, 32); // POCAO VERMELHA
item[3] = itemSheet.pegarSpritePosXPosY( 96, 0, 32, 32); // POCAO AZUL
item[4] = itemSheet.pegarSpritePosXPosY( 0, 32, 32, 32); // ARMA
item[5] = itemSheet.pegarSpritePosXPosY( 32, 32, 32, 32); // CAIXA MUNICAO
item[6] = itemSheet.pegarSpritePosXPosY( 64, 32, 32, 32); // MUNICAO
item[7] = itemSheet.pegarSpritePosXPosY( 96, 32, 32, 32); // CHAVE
item[8] = itemSheet.pegarSpritePosXPosY( 0, 64, 32, 32); // KEYCARD RED
item[9] = itemSheet.pegarSpritePosXPosY( 32, 64, 32, 32); // KEYCARD YELLOW

}

//94
Expand Down
25 changes: 25 additions & 0 deletions src/com/ks2002br/world/World.java
Expand Up @@ -4,6 +4,12 @@

import com.ks2002br.entities.Enemy;
import com.ks2002br.entities.Player;
import com.ks2002br.entities.itens.Ammo;
import com.ks2002br.entities.itens.Gun;
import com.ks2002br.entities.itens.Key;
import com.ks2002br.entities.itens.KeyCard;
import com.ks2002br.entities.itens.Medkit;
import com.ks2002br.entities.itens.Potion;
import com.ks2002br.frameworks.Bloco;
import com.ks2002br.frameworks.GameController;
import com.ks2002br.frameworks.ObjectId;
Expand Down Expand Up @@ -37,6 +43,25 @@ public void carregarLevel() {

else if(pixel == 0xFFFF6A00 )Game.gc.addObj(new Enemy(xx*32,yy*32,0,ObjectId.ENEMY)); //INIMIGO
else if(pixel == 0xFF0026FF)Game.gc.addObj(new Enemy(xx*32,yy*32,1,ObjectId.ENEMY));


//Criando os itens


else if(pixel == 0xFF0028FF)Game.gc.addObj(new Medkit(xx*32,yy*32,1,ObjectId.MEDKIT));
else if(pixel == 0xFF002CFF)Game.gc.addObj(new Medkit(xx*32,yy*32,2,ObjectId.MEDKIT));

else if(pixel == 0xFF0032FF)Game.gc.addObj(new Potion(xx*32,yy*32,1,ObjectId.POTION));
else if(pixel == 0xFF003AFF)Game.gc.addObj(new Potion(xx*32,yy*32,2,ObjectId.POTION));

else if(pixel == 0xFF0040FF)Game.gc.addObj(new Gun(xx*32,yy*32,1,ObjectId.GUN));
else if(pixel == 0xFF0046FF)Game.gc.addObj(new Ammo(xx*32,yy*32,2,ObjectId.BOX_AMMO));
else if(pixel == 0xFF0050FF)Game.gc.addObj(new Ammo(xx*32,yy*32,1,ObjectId.AMMO));

else if(pixel == 0xFF005AFF)Game.gc.addObj(new Key(xx*32,yy*32,ObjectId.KEY));
else if(pixel == 0xFF0062FF)Game.gc.addObj(new KeyCard(xx*32,yy*32,1,ObjectId.KEY_CARD));
else if(pixel == 0xFF006EFF)Game.gc.addObj(new KeyCard(xx*32,yy*32,2,ObjectId.KEY_CARD));

}

}
Expand Down

0 comments on commit 2ff6003

Please sign in to comment.