Wennst meinst.
Socius.java:
package Java.Soc;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
public class Socius extends JPanel implements Runnable, MouseListener, MouseMotionListener, MouseWheelListener{
public static void main(String[] args){
new Socius(600, 600);
}
JFrame f;
Thread t;
BufferedImage[] backg;
long delta = 0;
long last = 0;
long fps = 0;
public int klickx;
public int klicky;
public String FPS = "FPS: "+Long.toString(fps);
public int spPosaktX = 600;
public int spPosaktY = 0;
private boolean klick;
public int currentindex = 1;
private int currentbackgroundindex = 2;
public int screen = 1;
public BufferedImage[] anim;
private JProgressBar bar;
private int fortschritt = 4;
private boolean los;
private int bewegx;
private int bewegy;
private Inventar inv= new Inventar(550, 100, this);
private boolean mausradrunter;
private boolean mausradrauf;
private int[] slotszahl = new int[6];
private BufferedImage[] items = new BufferedImage[3];
private boolean invoffen = false;
public boolean testiminv = false;
private LaufEngine le = new LaufEngine();
public boolean neuerscreen;
public boolean sicherungiminv = false;
public boolean sichkastenoffen;
private BufferedImage[] fordg = new BufferedImage[10];
public int slotindex1;
public int slotindex2;
public boolean rechtsklick;
private int slotindex21;
private int slotindex11;
private static final long serialVersionUID = 1L;
Socius(int w, int h){
this.setPreferredSize(new Dimension(w, h));
this.setBackground(Color.BLACK);
f = new JFrame("Socius");
f.setLocation(100, 100);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(this);
f.setBackground(Color.BLACK);
f.pack();
f.setVisible(true);
t = new Thread(this);
f.addMouseListener(this);
f.addMouseWheelListener(this);
bar = new JProgressBar(0, 23);
bar.setStringPainted(true);
f.add(bar, BorderLayout.PAGE_START );
t.start();
laden();
}
private void laden() {
for(int i = 1;i<= 5;i++){
slotszahl** = i;
}
bar.setValue(1);
backg = new BufferedImage[9];
bar.setValue(2);
anim = new BufferedImage[17];
bar.setValue(3);
try {
for(int c = 1; c <= 16; c++){
anim``` = ImageIO.read(Socius.class.getResource("textures/animation/a"+c+".png"));
fortschritt++;
bar.setValue(fortschritt);
}
for(int c = 1; c <= 2; c++){
items ``` = ImageIO.read(Socius.class.getResource("textures/inventaritems/i"+c+".png"));
fortschritt++;
bar.setValue(fortschritt);
}
for(int c = 1; c <= 8; c++){
backg``` = ImageIO.read(Socius.class.getResource("textures/hintergrund/h"+c+".png"));
fortschritt++;
bar.setValue(fortschritt);
}
for(int c = 1; c <= 9; c++){
fordg ``` = ImageIO.read(Socius.class.getResource("textures/fordergrund/f"+c+".png"));
fortschritt++;
bar.setValue(fortschritt);
}
System.out.println("Bilderladen abgeschlossen");
} catch (IOException e) {
e.printStackTrace();
}
f.remove(bar);
bar.repaint();
f.setBackground(Color.BLACK);
currentindex = 1;
bar.setVisible(false);
f.repaint();
repaint();
los = true;
}
@Override
public void run() {
while(f.isVisible()){
if(los){
doLogic();
//checkscreen();
checkKlicks();
checkMausrad();
}
}
}
private void checkMausrad() {
if(mausradrunter){
inv.öffnen();
invoffen = true;
repaint();
}
else if(mausradrauf){
invoffen = false;
repaint();
inv.schliessen();
}
mausradrunter = false;
}
private void checkKlicks(){
if(klick){
switch(screen){
case 0:
break;
case 1:le.laufen1(this);
if(testiminv){
slotindex11 = inv.slotüberpr(inv.slotsfull);
slotindex1 = convertIndexToModel(inv.slotsfull, slotindex11);
}
if(neuerscreen){
spPosaktX = 100;
spPosaktY = 100;
currentindex = 1;
currentbackgroundindex = 3;
this.repaint();
neuerscreen = false;
}
break;
case 2:le.laufen2(this);
if(sicherungiminv){
slotindex21 = inv.slotüberpr(inv.slotsfull);
slotindex2 = convertIndexToModel(inv.slotsfull, slotindex21);
}
if(neuerscreen){
spPosaktX = 100;
spPosaktY = 0;
currentindex = 1;
currentbackgroundindex = 4;
this.repaint();
neuerscreen = false;
}
break;
case 3: le.laufen3(this);
if(neuerscreen){
spPosaktX = 100;
spPosaktY = 0;
currentindex = 1;
currentbackgroundindex = 5;
this.repaint();
neuerscreen = false;
}
}
klick = false;
}
}
@Override
protected void paintComponent(Graphics g){
g.drawImage(backg[currentbackgroundindex], 0, 0, this);
g.drawImage(anim[currentindex], spPosaktX, spPosaktY, this);
switch(screen){
case 0:
break;
case 1:if(testiminv == false){
g.drawImage(items[1], 800, 600, this);
}
break;
case 2:if(sichkastenoffen == false){
g.drawImage(fordg[2], 100, 600, this);
}
else if(sichkastenoffen){
g.drawImage(fordg[3], 100, 600, this);
if(sicherungiminv == false){
g.drawImage(fordg[4], 135, 705, this);
}
}
break;
}
inv.drawInventory(g);
if(invoffen){
inv.drawSlot(g);
}
if(testiminv && invoffen){
inv.drawSlotPicture(g, slotindex1, items[1]);
}
if(sicherungiminv && invoffen){
inv.drawSlotPicture(g, slotindex2, items[2]);
}
}
private void doLogic() {
}
@Override
public void mouseClicked(MouseEvent e) {
klickx = e.getX();
klicky = e.getY();
klick = true;
int mausbutton = e.getButton();
if(mausbutton == 3){
rechtsklick =true;
}
}
@Override
public void mouseEntered(MouseEvent arg0) {
}
@Override
public void mouseExited(MouseEvent arg0) {
}
@Override
public void mousePressed(MouseEvent arg0) {
}
@Override
public void mouseReleased(MouseEvent arg0) {
}
@Override
public void mouseDragged(MouseEvent arg0) {
}
@Override
public void mouseMoved(MouseEvent arg0) {
bewegx = arg0.getX();
bewegy = arg0.getX();
System.out.println(bewegx + bewegy);
}
@Override
public void mouseWheelMoved(MouseWheelEvent we) {
int iwi = we.getWheelRotation();
if(iwi == 1){
mausradrunter = true;
mausradrauf = false;
}
else{
mausradrunter = false;
mausradrauf = true;
}
}
public int convertIndexToModel(boolean[] slots, int viewIndex) {
int i = -1;
for (int modelIndex = 0; modelIndex < slots.length; modelIndex++) {
if (slots[modelIndex]) {
i++;
}
if (i == viewIndex) {
return modelIndex;
}
}
return i;
}
}
Inventar.java:
package Java.Soc;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JComponent;
public class Inventar extends JComponent implements Drawable, InventorySlot{
int x;
int y;
BufferedImage[] invbild = new BufferedImage[2];
private Socius s;
private int index = 0;
private int yziel;
private BufferedImage slotbild;
public boolean[] slotsfull = new boolean[26];
public Inventar(int x, int y, Socius s){
this.x = x;
this.yziel = y;
this.s = s;
laden();
}
private void laden() {
try {
slotbild = ImageIO.read(getClass().getResource("textures/fordergrund/f10.png"));
invbild[1] = ImageIO.read(getClass().getResource("textures/fordergrund/f11.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
private static final long serialVersionUID = 1L;
public void öffnen(){
index = 1;
y = 10;
s.repaint();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
y = 20;
s.repaint();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
y = 30;
s.repaint();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
y = 40;
s.repaint();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
y = 50;
s.repaint();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
y = 60;
s.repaint();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
y = 70;
s.repaint();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
y = 80;
s.repaint();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
y = 90;
s.repaint();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
y = yziel;
s.repaint();
}
public void schliessen(){
y = 90;
s.repaint();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
y = 80;
s.repaint();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
y = 70;
s.repaint();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
y = 60;
s.repaint();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
y = 50;
s.repaint();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
y = 40;
s.repaint();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
y = 30;
s.repaint();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
y = 20;
s.repaint();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
y = 10;
s.repaint();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
y = 0;
s.repaint();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
index = 0;
s.repaint();
}
@Override
public void drawInventory(Graphics g) {
g.drawImage(invbild[index], x, y, s);
}
@Override
public void drawSlot(Graphics g){
int yslot = yziel ;
for(int u = 1; u<= 5; u++){
for(int i = 0; i <= 4; i++){
int xslotn = x + slotbild.getWidth()*i;
int xslotf = xslotn;
g.drawImage(slotbild, xslotf, yslot, s);
s.repaint();
}
yslot = yziel +u*slotbild.getWidth();
}
}
@Override
public void drawSlotPicture(Graphics g, int slot, BufferedImage img) {
int slotnr = slot -1;
g.drawImage(img, this.x +slotnr*100, this.yziel, s);
if(s.screen == 1){
slotsfull[slot] = true;
}
else{
slotsfull[slot +1] = true;
}
}
@Override
public boolean slotFull(int slot) {
return slotsfull[slot];
}
@Override
public int slotüberpr(boolean slotvoll[]){
int s = 1;
boolean fertig = false;
while(s < 25 && fertig == false){
if(slotvoll[s] == false){
fertig = true;
break;
}
s++;
}
int indexfreeslot = s;
return indexfreeslot;
}
}