Hi leute !
ich habe ein ganz krasses problem und es mag euch lächerlich erscheinen.
ich bin gerade dabei ein java applet game zu schreiben und bin bisher gut weitergekommen:
http://www2.inf.fh-brs.de/~dkrueg2s/funky/bin/mygame.html
als nächsten schritt wollte ich ein auswahlmenü machen, dass mann vorher den charakter wählt. Das funktioniert aus irgendeinem grund nich so wie ich mir das vorstelle. hab schon viel probiert und ich dachte ich poste hier mal meinen stuff vllt. sieht ja jemand direkt was da falsch ist: http://www2.inf.fh-brs.de/~dkrueg2s/funky/funky.rar
sorry für die nich kommentierung und wenn ihr noch anregungen habt oder wenn ihr noch was code von unterklassen braucht...POSTEN ;D
mfg OyO
ich habe ein ganz krasses problem und es mag euch lächerlich erscheinen.
ich bin gerade dabei ein java applet game zu schreiben und bin bisher gut weitergekommen:
http://www2.inf.fh-brs.de/~dkrueg2s/funky/bin/mygame.html
als nächsten schritt wollte ich ein auswahlmenü machen, dass mann vorher den charakter wählt. Das funktioniert aus irgendeinem grund nich so wie ich mir das vorstelle. hab schon viel probiert und ich dachte ich poste hier mal meinen stuff vllt. sieht ja jemand direkt was da falsch ist: http://www2.inf.fh-brs.de/~dkrueg2s/funky/funky.rar
Java:
import java.applet.*;
import java.awt.*;
public class funkymain extends Applet implements Runnable
{
weapon[]w;
weapon[]w2;
player player1;
player player2;
player ritter;
player koenig;
weapon p1weapon1;
weapon p2weapon1;
Transparentfilter T;
Hmenu HM;
private Image dbImage;
private Thread th;
private Graphics dbg;
private Image pimg;
private Image pimg2;
private Image pimg3;
private Image pimg4;
private Image wimg1;
private Image p2img;
private Image p2img2;
private Image p2img3;
private Image p2img4;
private Image w2img1;
private boolean activeH;
private static int speed = 10;
public void init()
{
setBackground(Color.BLACK);
w = new weapon[4];
w2 = new weapon[4];
ritter = new player (50, 50, 20,200,100,w);
koenig = new player (400,400,10,200,200,w2);
T = new Transparentfilter(Color.WHITE);
HM = new Hmenu(100,100);
p1weapon1 = new fireball(2);
p2weapon1 = new Sword(2);
w2[0]=p1weapon1;
w[0]= p2weapon1;
activeH=true;
// fetch images
getImages();
HM.setImages(pimg2,p2img2,pimg3,pimg4,wimg1);
ritter.setImages(pimg,pimg2,pimg3,pimg4,wimg1);
koenig.setImages(pimg,pimg2,pimg3,pimg4,wimg1);
}
private void getImages()
{
MediaTracker tracker = new MediaTracker(this);
pimg = getImage(getCodeBase(), "images/up1.gif");
tracker.addImage(pimg, 1);
pimg2 = getImage(getCodeBase(), "images/down1.gif");
tracker.addImage(pimg2, 2);
pimg3 = getImage(getCodeBase(), "images/left1.gif");
tracker.addImage(pimg3, 3);
pimg4 = getImage(getCodeBase(), "images/right1.gif");
tracker.addImage(pimg4, 4);
wimg1 = getImage(getCodeBase(), "images/Sword.gif");
tracker.addImage(wimg1, 5);
p2img = getImage(getCodeBase(), "images/Kup1.gif");
tracker.addImage(p2img, 6);
p2img2 = getImage(getCodeBase(), "images/Kdown1.gif");
tracker.addImage(p2img2, 7);
p2img3 = getImage(getCodeBase(), "images/Kleft1.gif");
tracker.addImage(p2img3, 8);
p2img4 = getImage(getCodeBase(), "images/Kright1.gif");
tracker.addImage(p2img4, 9);
w2img1 = getImage(getCodeBase(), "images/dark-fireball.gif");
tracker.addImage(w2img1, 10);
try
{
tracker.waitForAll();
}
catch (Exception exception)
{
}
}
/** Methode starts Thread */
public void start ()
{
// create new thread
th = new Thread (this);
// start thread
th.start ();
}
public void run ()
{
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
while (true)
{
while(activeH){
HM.move();
HM.leftm=false;
HM.rightm=false;
repaint();
getImages();
if(HM.chosen1){
switch(HM.getcur()){
case '1':
//kann ich dass so machen oder liegt der fehler hier ?
player1 = ritter.clone();
break;
case '2':
player1 = koenig.clone();
break;
}
}
if(HM.chosen2){
switch(HM.getcur()){
case '1':;
player2 = ritter.clone();
break;
case '2':
player2 = koenig.clone();
break;
}
}
if(HM.chosen1&&HM.chosen2){
activeH=false;
}
}
while(!activeH){
player1.move();
player2.move();
w[0].dodmg(player2);
w2[0].dodmg(player1);
repaint();
player1.set_right(false);
player1.set_up(false);
player1.set_down(false);
player1.set_left(false);
player1.setUsew1(false);
player2.set_right(false);
player2.set_up(false);
player2.set_down(false);
player2.set_left(false);
player2.setUsew1(false);
}
try
{
// Stoppen des Threads für in Klammern angegebene Millisekunden
Thread.sleep (speed);
}
catch (InterruptedException ex)
{
// do nothing
}
// Zurücksetzen der ThreadPriority auf Maximalwert
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
}
}
// event handling for keys down
public boolean keyDown (Event e, int key)
{
if(key == Event.LEFT&& activeH){
HM.leftm= true;
}
if(key == Event.RIGHT&& activeH){
HM.rightm= true;
}
if(key == 107&& activeH){
HM.chosen1=true;
}
if(key == 102&& activeH){
HM.chosen2=true;
}
if(key == Event.LEFT&& !activeH) {
player1.set_left(true);
player1.lookleft = true;
player1.looktop = false;
player1.lookdown = false;
player1.lookright = false;
}
if(key == Event.UP&& !activeH) {
player1.set_up(true);
player1.lookleft = false;
player1.looktop = true;
player1.lookdown = false;
player1.lookright = false;
}
if(key == Event.DOWN&& !activeH) {
player1.set_down(true);
player1.lookleft = false;
player1.looktop = false;
player1.lookdown = true;
player1.lookright = false;
}
if(key == Event.RIGHT&& !activeH) {
player1.set_right(true);
player1.lookleft = false;
player1.looktop = false;
player1.lookdown = false;
player1.lookright = true;
}
if(key == 107&& !activeH){
player1.setUsew1(true);
}
//player2
if(key == 97&& !activeH) {
player2.set_left(true);
player2.lookleft = true;
player2.looktop = false;
player2.lookdown = false;
player2.lookright = false;
}
if(key == 119&& !activeH) {
player2.set_up(true);
player2.lookleft = false;
player2.looktop = true;
player2.lookdown = false;
player2.lookright = false;
}
if(key == 115&& !activeH) {
player2.set_down(true);
player2.lookleft = false;
player2.looktop = false;
player2.lookdown = true;
player2.lookright = false;
}
if(key == 100&& !activeH) {
player2.set_right(true);
player2.lookleft = false;
player2.looktop = false;
player2.lookdown = false;
player2.lookright = true;
}
if(key == 102&& !activeH){
player2.setUsew1(true);
}
return true;
}
// event handling for keys up
// Stop Thread
public void stop()
{
th.stop();
}
// Stop Thread
public void destroy()
{
th.stop();
}
public void update (Graphics g)
{
if (dbImage == null)
{
dbImage = createImage (this.getSize().width, this.getSize().height);
dbg = dbImage.getGraphics ();
}
dbg.setColor (getBackground ());
dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);
dbg.setColor (getForeground());
paint(dbg);
g.drawImage (dbImage, 0, 0, this);
}
/** draw game */
public void paint (Graphics g)
{
if(activeH){
HM.drawp(g);
}
if(!activeH){
player2.drawp(g);
player1.drawp(g);
g.setColor(Color.WHITE);
g.fillRect(0,V_safe.appletB,V_safe.appletH, 10);
g.setColor(Color.RED);
if(player1.gethp()>0){
g.draw3DRect(20, 360,player1.maxhp, 5, false);
g.fillRect(20, 360,player1.gethp(), 5);
}
if(player2.gethp()>0){
g.fillRect(300, 360,player2.gethp(), 5);
g.draw3DRect(300, 360,player2.maxhp, 5, false);
}
g.setColor(Color.BLUE);
g.draw3DRect(20, 370,player1.maxmagic, 5, false);
g.fillRect(20, 370,player1.getmagic(), 5);
g.fillRect(300, 370,player2.getmagic(), 5);
g.draw3DRect(300, 370,player2.maxmagic, 5, false);
for(int i=0;i<V_safe.appletH;i++){
for(int j=0;j<V_safe.appletB;j++){
T.filterRGB(j,i,Color.TRANSLUCENT);
}
}
}
}
}
mfg OyO