Also wie ihr vieleicht mitbekommen habt versuch ich mein erstes kleines Spiel zu programmieren jedoch hab ich ein problem weil ich nicht weis dwie ich 2 class (später mehr) verbinden kann.
level1
-Start level2
Ende level1
---
-Start level2
--Start level3
-Ende level2
.....
So sol das inetwa sein
Nice wäre auch das ihr mir gleich die fertigen scrips dan gibt
level1:
Java
mport java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
/**
*Version: 0.4.5.
*Letzte Veränderung:27.2.2013
*
*Ersteller: Oliver Ostermaier (lolmaker355)
*/
public class lolsBall extends Applet implements Runnable
{
int x_pos = 12;
int y_pos = 12;
int radius = 5;
int x_speed = 6;
int y_speed = 8;
int sliderx_pos = 50;
int slidery_pos = 150;
int swidth = 60;
int sheight = 1;
Rectangle box = new Rectangle(swidth, sheight);
int sliderx_speed = 0;
int appletsize_top = 0;
int appletsize_bottom =
200;
int appletsize_left = 0;
int appletsize_right =
150;
int lx_pos = 100;
int ly_pos = appletsize_top +20;
int lwidth = 50;
int lheight = 1;
Rectangle brick = new Rectangle(lx_pos, ly_pos, lwidth, lheight);
Random rnd = new Random ();
private Image dbImage;
private Graphics dbg;
Thread thread;
boolean running = false;
public void init()
{
enableEvents(AWTEvent.KEY_EVENT_MASK);
setFocusable(true);
}
public void start ()
{
running = true;
thread = new Thread (this);
thread.start();
}
public void stop()
{
running = false;
if(thread != null)
thread.interrupt();
thread = null;
}
public void run ()
{
while (running)
{
if (x_pos - radius + x_speed < appletsize_left ||
x_pos + radius + x_speed > appletsize_right )
{
x_speed *= -1;
}
if (y_pos - radius + y_speed < appletsize_top)
{
y_speed *= -1;
}
if(y_pos + radius + y_speed > appletsize_bottom )
{
y_pos = appletsize_bottom - radius;
y_speed *= -1;
}
if(x_pos + radius + x_speed > sliderx_pos &&
x_pos - radius + x_speed < sliderx_pos + swidth)
{
if(y_pos + radius + y_speed > slidery_pos)
{
y_speed *= -1;
}
}
if(x_pos + radius + x_speed > lx_pos &&
x_pos - radius + x_speed < lx_pos + lwidth)
{
if(y_pos - radius < ly_pos + brick.height)
{
y_speed *= -1;
System.out.println("Sie haben den Block zerstört");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("In 3s startet Level2");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("In 2s startet level2");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("In 1s startet level2");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Level2 startet");
//Hier muss eine verknüpfung hin das die class level2 startet und
//dieses Programm "geschlössen" wird
lx_pos = 10000;
ly_pos = 10000;
brick.setLocation(lx_pos, lx_pos);
}
}
x_pos += x_speed;
y_pos += y_speed;
repaint();
try
{
Thread.sleep (90);
}
catch (InterruptedException ex)
{
running = false;
break;
}
}
}
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);
}
public void paint (Graphics g)
{
g.drawLine(appletsize_right, appletsize_top,
appletsize_right, appletsize_bottom);
g.drawLine(appletsize_left, appletsize_bottom,
appletsize_right, appletsize_bottom);
Graphics2D g2 = (Graphics2D) g;
g.setColor (Color.red);
g.fillOval (x_pos - radius, y_pos - radius, 2 * radius, 2 * radius);
box.setLocation(sliderx_pos, slidery_pos);
g2.setColor (Color.blue);
g2.draw(box);
g2.setColor (Color.pink);
g2.draw(brick);
}
protected void processKeyEvent(KeyEvent e)
{
int keyCode = e.getKeyCode();
if (keyCode == KeyEvent.VK_LEFT)
{
if (sliderx_pos -10 > appletsize_left)
sliderx_pos = sliderx_pos -20;
}
else if (keyCode == KeyEvent.VK_RIGHT)
{
if (sliderx_pos + swidth +10 < appletsize_right)
sliderx_pos = sliderx_pos +20;
}
}
}
Alles anzeigen
//Edit: kann nur 10k Zeichen benutzten :o