Jogo Em Java Erro e Implementação

1 resposta
T

Olá.
Estou fazendo um jogo, mas estou encontrando dificuldades e gostaria da ajuda de vocês.
Ele está dando erros e eu queria ajuda para implementar esse código adicionando um sistema pontuação que está faltando.
Vou postar o código das classes para vocês analisarem, além do mais, acredito que esteja faltando códigos na classe SpaceInvaders, e a única classe que o NetBeans não acusa erro, é a classe Sprite.

Classe SpaceInvaders

package spaceinvaders;


public class SpaceInvaders {

    
    public static void main(String[] args) {
        new game();
         
           
    }
}

Classe Alien

public class Alien extends Entity {
    
    private double moveSpeed = 75;
    
    private Game game;
    
    

public Alien(Game game,String ref, int x, int y){
    super(ref,x,y);
    
    this.game = game;
    dx = -moveSpeed;
}


public void move(long delta){
    
    if ((dx < 0) && (x< 10)){
        game.updateLogic();
        
    }
    
    if ((dx > 0) && (x > 750)){
        game.upateLogic();
    
    }

    super.move(delta);
    
    }

public void doLogic();

    dx = -dx;
    y += 10;
    
    
    if (y > 570){
            game.notifyDeath();
    }
    
}

public void collideWith(Entity other){

    }

Classe Entity

import java.awt.Graphics;
import java.awt.Rectangle;

public abstract class Entity {
    
    protected double x;
    
    protected double y;
    
    protected Sprite sprite;
    
    protected double dx;
    
    protected double dy;
    
    private Rectangle me = new Rectangle();
    
    private Rectangle him = new Rectangle();
    
    
    public Entity(String ref, int x, int y){
        this.sprite = SpriteStore.get().getSprite(ref);
        this.x = x;
        this.y = y;
        
        
        
    public void move(long delta) {
        
        x += (delta * dx) / 1000;
        y += (delta * dy) / 1000;
        
    }
    
    public void setHorizontalMovement(double dx){
        this.dx = dx;;
        
    }
    
    public void setVerticalMovement(double dy){
        this.dy = dy;
        
    }
    
    public double getHorizontalMovement(){
        return dx;
        
    }
    
    public double getVerticalMovement(){
        return dy;
        
    }
    
    public void draw(Graphics g){
        sprite.draw(g,(int) x,(int) y);
        
    }
    
    public void doLogic(){
    }
    
    public int getX(){
        return (int) x;
        
    }
    
    public int getY(){
        return (int) y;
        
    }
    
    public boolean collidesWhit(Entity other){
        me.setBounds((int) x,(int) y,sprite.getWidth(),sprite.getHeight());
        him.setBounds((int) other.x,(int) other.y,other.sprite.getWidth(),other.sprite.getHeight());
        
        return me.intersects(him);
        
    }
    
    public abstract void collideWith(Entity other);
    
}

Classe Nave

public class Nave extends Entity {
    
    private Game game;
    
    
public Nave (Game game,String ref,int x, int y){
    super(ref,x,y);
    
    this.game = game;
    
}

public void move(long delta){
    if ((dx < 0) && (x < 10)){
        return;
        
    }
    
    if ((dx > 0) && (x > 750)){
        return;
        
    }
    
    super.move(delta);
    
}

public void collidedWith(Entity other){
    
    if (other instanceof Alien){
        game.notifyDeath();
    }
}
    
}

Classe Sprite

import java.awt.Graphics;
import java.awt.Image;


public class Sprite {
    
    private Image image;
    
    
    public Sprite(Image image){
        this.image = image;
        
    }
    
    public int getWidth(){
        return image.getWidth(null);
    }
    
    public int getHeight(){
        return image.getWidth(null);
    }
    
    public void draw(Graphics g,int x,int y){
        g.drawImage(image, x, y, null);
        
    }
}

Classe SpriteStore

import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;

import javax.imageio.ImageIO;

public class SpriteStore {
    private static SpriteStore single = new SpriteStore();
    
    
    public static SpriteStore get(){
        return single;
    }
    
    private HashMap sprites = new HashMap();
    
    public Sprite getSprite(String ref) {
        
        if (sprites.get(ref) !=null){
            return (Sprite) sprites.get(ref);
        }
        
        BufferedImage sourceImage = null;
        
        try {
            
                URL url = this.getClass().getClassLoader().getResource(ref);
                
                if (url == null){
                    fail("Can't find ref:"+ref);
                }
                
                sourceImage = ImageIO.read(url);
		} catch (IOException e) {
			fail("Failed to load: "+ref);
		}
        
        GraphicsConfiguration gc = GraphicsEnviroment.getLocalGraphicsEnviroment().getDefaultScreenDevice().getDefaultConfiguration();
        Image image = gc.createCompatibleImage(sourceImage.getWidth(),sourceImage.getHeight(),Transparency.BITMASK);
        
        image.getGraphics().drawImage(sourceImage, 0, 0, null);
        
        
        Sprite sprite = new Sprite(image);
        sprites.put(ref,sprite);
        
        return sprite;
    }
    
    private void fail(String message){
        
        System.err.println(message);
        System.exit(0);
       
    }
    
}

Classe Tiro

public class Tiro extends Entity {
    
    private Game game;
    
    private boolean used = false;
    
    
    public Tiro(Game game,String sprite,int x,int y){
     super(sprite,x,y);
     
     this.game = game;
     
     dy = moveSpeed;
     
 }
 
 public void move(long delta) {
     super.move(delta);
     
     if (y < -100){
         game.removeEntity(this);
     }
     
 }
 
 public void collideWith(Entity other){
     
     if (used){
         return;
     }
     
     if (other instanceof Alien){
         
         game.removeEntity(this);
         game.removeEntity(other);
         
         game.notifyAlienKilled();
         used = true;
        }
    }
     
}

1 Resposta

T

Consegui resolver os erros, agora só falta o sistema de pontuação.
Se alguém puder me ajudar a implantar o sistema de pontuação eu agradeço.

Criado 17 de outubro de 2013
Ultima resposta 18 de out. de 2013
Respostas 1
Participantes 1