Guten Morgen!
Ich habe mal die Library Slick ausprobiert, da Konsolenzeugs langweilig wurde.
Nun habe ich ein Problem.. Mein Code sollte eigentlich ein Rechteck erstellen - Wird aber nicht!
Spiel_Main:
Location:
Entity:
EntityPlayer:
Was geht da nicht? Und was kann man bereits in diesem Stand der Dinge verbessern (im code)?
Die Installation von Slick habe ich per Tutorial gemacht, aber den Rest dann einfach ohne - Ich habe das Gefühl, dass ich rein gar nichts lerne wenn ich nur auf ein Tutorial schaue.
Ich habe mal die Library Slick ausprobiert, da Konsolenzeugs langweilig wurde.
Nun habe ich ein Problem.. Mein Code sollte eigentlich ein Rechteck erstellen - Wird aber nicht!
Spiel_Main:
Java:
package game;
import java.util.ArrayList;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
public class Spiel_Main extends BasicGame {
public static final int
HEIGHT = 300,
WIDTH = 400;
public Spiel_Main() {
super("Spiel");
}
public ArrayList<Entity> entitys = new ArrayList<Entity>();
EntityPlayer player;
@Override
public void render(GameContainer gc, Graphics arg1) throws SlickException {
//player.setLocation(new Location(20,20));
}
@Override
public void init(GameContainer gc) throws SlickException {
player = new EntityPlayer(100, 100, 100, 100);
entitys.add(player);
}
@Override
public void update(GameContainer gc, int arg1) throws SlickException {
Input input = gc.getInput();
}
public static void main(String[] args) throws SlickException{
AppGameContainer spiel = new AppGameContainer(new Spiel_Main());
spiel.setDisplayMode(WIDTH, HEIGHT, false);
spiel.setVSync(true);
spiel.setShowFPS(true);
spiel.start();
}
}
Java:
package game;
public class Location {
private double x,y;
public Location(double x, double y){
setX(x);setY(y);
}
public double getX(){
return this.x;
}
public double getY(){
return this.y;
}
public void setX(double i){
this.x = i;
}
public void setY(double i){
this.y = i;
}
}
Java:
package game;
public class Entity {
private int width, height, speed;
Location loc;
public Entity(){
}
public int getWidth(){
return width;
}
public int getHeight(){
return height;
}
public int getSpeed(){
return speed;
}
public Location getLocation(){
return this.loc;
}
public void setWidth(int i){
this.width = i;
}
public void setHeight(int i){
this.height = i;
}
public void setSpeed(int i){
this.speed = i;
}
public void setLocation(Location l){
this.loc = l;
}
}
EntityPlayer:
Java:
package game;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.geom.Shape;
public class EntityPlayer extends Entity{
private Rectangle p_o;
public EntityPlayer(int w, int h, int x, int y){
//Variabeln des Konstruktors
Location l = new Location(x, y);
//Maße, Position und mehr setzen
setHeight(h);
setWidth(w);
//Spieler initialisieren
p_o = new Rectangle(Math.round(l.getX()), Math.round(l.getY()), getWidth(), getHeight());
System.out.println("Spieler initialisiert..");
setLocation(l);
}
public boolean collide(Shape s){
return this.p_o.intersects(s);
}
@Override
public void setLocation(Location l){
this.loc = l;
this.p_o.setLocation(Math.round(l.getX()), Math.round(l.getY()));
}
}
Was geht da nicht? Und was kann man bereits in diesem Stand der Dinge verbessern (im code)?
Die Installation von Slick habe ich per Tutorial gemacht, aber den Rest dann einfach ohne - Ich habe das Gefühl, dass ich rein gar nichts lerne wenn ich nur auf ein Tutorial schaue.
Zuletzt bearbeitet: