rendered paste body//imports
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.applet.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.File;
import java.applet.Applet;
import java.applet.AudioClip;
import java.net.URL;
import javax.imageio.ImageIO;
import java.io.*;
public class rts extends JFrame implements Runnable, KeyListener, MouseListener, MouseMotionListener
{
//obersicht rohstoffe geld einheiten bilder
Image limit; // unit limit
Image elec; // building limit
long oldtime;
long newtime;
//menue pics
//---
Image img_corvette;
Image map;
Image menu;
Image menu_build;
Image menu_comm;
Image menu_mucro;
Image menu_qps;
Image menu_qt;
Image menu_station;
//---
int framecount = 0;
int bbar = 0; // variable fur progrssbar beim units bauen
String level = "0"; // level variable
int e_z = 0; // gegner units zaehler
// positionsvariablen
//---
int menux = 915;
int menuy = 80;
int menu_width = 100;
int menu_height = 120;
int menu_buildy = menuy + 35;
//---
//status sounds
AudioClip s_win;
AudioClip s_lose;
AudioClip s_unitfull;
AudioClip s_nomoney;
AudioClip s_error;
boolean wires = false; // programers wireframe, true setzten und sich wireframes anschaun
boolean starto = false; // match beginnt variable
boolean loser = false; // man selbst hat verloren boolean
boolean winner = false; // man selbst hat gewonnen boolean
Image pic_lose; // variable für "you lose bild"
Image pic_win; // variable für "you win bild"
boolean ai = true; // in DIESER alpha version des Spiels ist der Gegner immer eine KI
int zahler; // zahl deiner einheiten DEINER
//bilder der units
//---
Image buff_alium[] = new Image[8];
Image buff_comm[] = new Image[8];
Image buff_mucro[] = new Image[8];
Image buff_missl[] = new Image[8];
Image buff_hit[] = new Image[9];
Image buff_expl[] = new Image[12];
//gebaeude
Image buff_station;
Image buff_qps;
Image buff_qt;
//---
//verschiende angriffs- und flug variablen
//---
int conx1 = 0;
int cony1 = 0;
int conx2 = 1000;
int cony2 = 1000;
int attx = 0;
int atty = 0;
Image att;
boolean attb = false;
int px = 0;
int py = 0;
//---
int marki = 0; // markierung
int mapx = 0; // mapposition x
int mapy = 0; // mapposition y
static int mapwidth=2500; // map breite
static int mapheight=2000;//map hohe
String mapname; // mapname zum laden
int player = 1; // 1 = player1, 2 = multiplayer oder CPU
// if player 1 dann die eine ecke, 2 andere ecke
// dieses spiel war darauf ausgelegt das man es im netzwerk nutzen konnte
String direction; // richtung
float lplus = 0f; // rechnungsvariable fur layze (geld)
int mb; //mouse button
AudioClip create; // qps spawn sound
//positionsvariablen
//--
int rx = 0;
int ry = 0;
int rx2 = 0;
int ry2 = 0;
//---
int whichship = 0; // variable bei spawnen von units
boolean marking = false; // wird mit der maus makiert ?
int unit_count = 0; // zaehlen von units
int kc; // keycode
int layze = 18000; // start layze -9000 ;)
Image img_layze; // mini bild fur layze anzeige
Image img_qps; //mini bild fur qps
int QPS = 0; // QPS = Quanten Potential Scanner, anzahl
static int ulimit = 24; // limit für units
unit acunit[] = new unit[ulimit+2]; // instanzen der klasse unit bilden
// maus koordinaten
int mx = 400;
int my = 400;
// hintergrundmusik
AudioClip music;
boolean playm = true;
// farben
Color bg = new Color(0,0,0);
Color mark = new Color(255,255,0);
Color fontcolor = new Color(180,180,240);
Cursor c; //Cursor variable
static int screenx = 1024; // festgelegte breite
static int screeny = 740; // und hoehe des fensters
//thread sachen
Thread th;
boolean running;
int schlaf = 20;
//fur double buffering
private Image dbImage;
private Graphics dbg;
public static void main(String[] args)
{
//wird von anderen klassen instanziert
}
public rts(String in_lvl)
{
level = in_lvl; // level holen
setTitle("Lunar Commander - Level "+level); // titel mit level angabe
setBackground(bg); // background auf schwarz
addKeyListener(this); // key listener adden für keyboard eingaben
addMouseListener(this); // mouse listener adden für maus klicks
addMouseMotionListener(this); // motion listener adden für maus bewegung
Container cp = getContentPane(); // contenpane deklarieren
//closing adapter
addWindowListener( new WindowAdapter() {public void windowClosing ( WindowEvent e) {System.exit(0); }});
setSize(screenx,screeny); // groesse des fenster setzen
setLayout(null); // layout null = koordinaten system
for (int ni = 0; ni < ulimit+2; ni++) // initializieren aller units
{
acunit[ni] = new unit(); // mit konstruktor aufruf
}
Font f = new Font( "Lucida", Font.PLAIN, 10 ); //neue schriftart erzeugen
setFont(f); // schriftart benutzen
//alle bilder in buffer schreiben / laden
//---------------------------------------->>>>>
buff_alium[0] = load_img("units\\alium\\u.gif");
buff_alium[1] = load_img("units\\alium\\ru.gif");
buff_alium[2] = load_img("units\\alium\\r.gif");
buff_alium[3] = load_img("units\\alium\\rd.gif");
buff_alium[4] = load_img("units\\alium\\d.gif");
buff_alium[5] = load_img("units\\alium\\ld.gif");
buff_alium[6] = load_img("units\\alium\\l.gif");
buff_alium[7] = load_img("units\\alium\\lu.gif");
//->
buff_comm[0] = load_img("units\\commeatus\\u.gif");
buff_comm[1] = load_img("units\\commeatus\\ru.gif");
buff_comm[2] = load_img("units\\commeatus\\r.gif");
buff_comm[3] = load_img("units\\commeatus\\rd.gif");
buff_comm[4] = load_img("units\\commeatus\\d.gif");
buff_comm[5] = load_img("units\\commeatus\\ld.gif");
buff_comm[6] = load_img("units\\commeatus\\l.gif");
buff_comm[7] = load_img("units\\commeatus\\lu.gif");
//->
buff_mucro[0] = load_img("units\\mucro\\u.gif");
buff_mucro[1] = load_img("units\\mucro\\ru.gif");
buff_mucro[2] = load_img("units\\mucro\\r.gif");
buff_mucro[3] = load_img("units\\mucro\\rd.gif");
buff_mucro[4] = load_img("units\\mucro\\d.gif");
buff_mucro[5] = load_img("units\\mucro\\ld.gif");
buff_mucro[6] = load_img("units\\mucro\\l.gif");
buff_mucro[7] = load_img("units\\mucro\\lu.gif");
//->
buff_missl[0] = load_img("rocket\\0.gif");
buff_missl[1] = load_img("rocket\\1.gif");
buff_missl[2] = load_img("rocket\\2.gif");
buff_missl[3] = load_img("rocket\\3.gif");
buff_missl[4] = load_img("rocket\\4.gif");
buff_missl[5] = load_img("rocket\\5.gif");
buff_missl[6] = load_img("rocket\\6.gif");
buff_missl[7] = load_img("rocket\\7.gif");
//->
buff_hit[0] = load_img("rocket\\EX1.gif");
buff_hit[1] = load_img("rocket\\EX2.gif");
buff_hit[2] = load_img("rocket\\EX3.gif");
buff_hit[3] = load_img("rocket\\EX4.gif");
buff_hit[4] = load_img("rocket\\EX5.gif");
buff_hit[5] = load_img("rocket\\EX6.gif");
buff_hit[6] = load_img("rocket\\EX7.gif");
buff_hit[7] = load_img("rocket\\EX8.gif");
buff_hit[8] = load_img("rocket\\EX9.gif");
//->
buff_expl[0] = load_img("explo\\E1.gif");
buff_expl[1] = load_img("explo\\E2.gif");
buff_expl[2] = load_img("explo\\E3.gif");
buff_expl[3] = load_img("explo\\E4.gif");
buff_expl[4] = load_img("explo\\E5.gif");
buff_expl[5] = load_img("explo\\E6.gif");
buff_expl[6] = load_img("explo\\E7.gif");
buff_expl[7] = load_img("explo\\E8.gif");
buff_expl[8] = load_img("explo\\E9.gif");
buff_expl[9] = load_img("explo\\E10.gif");
buff_expl[10] = load_img("explo\\E11.gif");
buff_expl[11] = load_img("explo\\E12.gif");
//->
buff_station = load_img("buildings\\station.gif");
buff_qps = load_img("qps.gif");
buff_qt = load_img("buildings\\gate.gif");
//---------------------------------------->>>>>
music = load_sound("songs\\song"+level+".wav"); //hintergrundmusik laden
//sound files laden
//---
create = load_sound("sounds\\create.wav");
s_unitfull = load_sound("sounds\\unitfull.wav");
s_nomoney = load_sound("sounds\\nomoney.wav");
s_error = load_sound("sounds\\error.wav");
s_win = load_sound("sounds\\win.wav");
s_lose = load_sound("sounds\\lose.wav");
//---
c = getToolkit().createCustomCursor(new ImageIcon("cur\\DANI1.gif").getImage(),new Point(0,0),"Cursor");
setCursor(c); //cursor deklarieren und nutzen
mapname = "lvl"+level; // mapname setzt sich zusammen aus dem wort lvl und der level zahl
direction = ""; //richtung
//grund pics werden geladen
//---
att = load_img("shot.gif");
map = load_img("maps\\"+mapname+".jpg");
img_corvette = load_img("corvette.gif");
menu_build = load_img("menu\\b_alium_up.gif");
menu_qps = load_img("menu\\b_qps_up.gif");
menu = load_img("menu.gif");
menu_comm = load_img("menu\\b_commeatus_up.gif");
menu_mucro = load_img("menu\\b_mucro_up.gif");
menu_qt = load_img("menu\\b_qt_up.gif");
menu_station = load_img("menu\\b_station_up.gif");
limit = load_img("limit.gif");
elec = load_img("elec.gif");
img_layze = load_img("layze.gif");
Image icony = load_img("ico.gif");
img_qps = load_img("mqps.gif");
//---
setIconImage(icony); //windows applikations icon setzen
pic_lose = load_img("lose.gif"); // bild laden "You lose"
pic_win = load_img("win.gif"); // bild laden "You win"
add_ship(5,1,120,40); // Basis Station Spieler 1
add_ship(5,2,120+2150,40+1750); // Basis Station Spieler 2
starto = true; // match beginnt
// 7 zufaellige gegnerische einheiten spawnen
//---
add_ship((int)Math.floor((Math.random()*3)+1),2,(int)Math.floor((Math.random()*1500)+1000),(int)Math.floor((Math.random()*1000)+800));
add_ship((int)Math.floor((Math.random()*3)+1),2,(int)Math.floor((Math.random()*1500)+1000),(int)Math.floor((Math.random()*1000)+800));
add_ship((int)Math.floor((Math.random()*3)+1),2,(int)Math.floor((Math.random()*1500)+1000),(int)Math.floor((Math.random()*1000)+800));
add_ship((int)Math.floor((Math.random()*3)+1),2,(int)Math.floor((Math.random()*1500)+1000),(int)Math.floor((Math.random()*1000)+800));
add_ship((int)Math.floor((Math.random()*3)+1),2,(int)Math.floor((Math.random()*1500)+1000),(int)Math.floor((Math.random()*1000)+800));
add_ship((int)Math.floor((Math.random()*3)+1),2,(int)Math.floor((Math.random()*1500)+1000),(int)Math.floor((Math.random()*1000)+800));
add_ship((int)Math.floor((Math.random()*3)+1),2,(int)Math.floor((Math.random()*1500)+1000),(int)Math.floor((Math.random()*1000)+800));
//---
}
public void fpsa()
{
setTitle("fps: "+framecount);
framecount=0;
}
public void keyReleased(KeyEvent e)
{
kc = 0; // key code bei loslassen zurücksetzen
}
public void keyPressed(KeyEvent e)
{
kc = e.getKeyCode(); // keycode in variable schreiben
if (kc == 27) { dispose(); System.exit(0); } // ESC = beenden
if (winner) // beenden nach gewonnen und tastendruck
{
dispose(); //fenster schliessen
System.exit(0); // java programm beenden
}
if (loser) { System.exit(0); } // wenn verloren , beenden, bei tasten druck
}
public void keyTyped(KeyEvent e) {}
public AudioClip load_sound(String str) // funktion zum sound files laden
{
File f = new File(str);
AudioClip lol;
URL u = null;
try { u = f.toURL();}
catch (Exception e) {}
lol = Applet.newAudioClip(u);
return lol;
}
static public Image load_img(String str2) // funktion zum bilder laden
{
File f = new File(str2);
Image img1 = null;
try { img1 = ImageIO.read( f ); }
catch (Exception e ) {}
return img1;
}
public void add_ship(int typo, int own, int xx, int yy)
{
int takethis = 222; // 222 = kein slot frei
for (int gx = ulimit-1; gx >= 0; gx--) // algorithmus um einen freien unit slot zu finden
{
if (gx < 0) {gx = 0;}
if (acunit[gx].alive == false) {takethis = gx;}
}
if (takethis != 222) // wenn kein slot gefunden worden ist ist diese zahl immernoch 222
{
if (typo == 1) // wenn typ = 1
{
acunit[takethis].speed = 1; // geschwindigkeit = 1
acunit[takethis].uwidth = 80;//breite der einheit = 80
acunit[takethis].uheight =90;// hohe = 90
acunit[takethis].hp = 5; //hp = 5
acunit[takethis].range = 350; // range = 350
acunit[takethis].unitpic = buff_alium[0]; // bild der einheit typ entsprechend
acunit[takethis].upath = "units\\alium\\"; //pfad typ entsprechend
if (own == player) {layze-=4000;} // wenn spieler baut, geld abzug
}
else if (typo == 2) // siehe oben
{
acunit[takethis].speed = 1; // siehe oben
acunit[takethis].uwidth = 50; // " "
acunit[takethis].uheight =50;
acunit[takethis].hp = 5;
acunit[takethis].range = 250;
acunit[takethis].upath = "units\\commeatus\\";
acunit[takethis].unitpic = buff_comm[0];
if (own == player) {layze-=800;}
}
else if (typo == 3) // siehe oben
{
acunit[takethis].speed = 1; // siehe oben
acunit[takethis].uwidth = 100;// " "
acunit[takethis].uheight =100;
acunit[takethis].hp = 5;
acunit[takethis].range = 500;
acunit[takethis].upath = "units\\mucro\\";
acunit[takethis].unitpic = buff_mucro[0];
if (own == player) {layze-=2750;}
}
else if (typo == 4) // siehe oben
{
acunit[takethis].speed = 0; // siehe oben
acunit[takethis].uwidth = 63; // " "
acunit[takethis].uheight =61;
acunit[takethis].hp = 3;
acunit[takethis].range = 0;
acunit[takethis].upath = "buildings\\";
acunit[takethis].unitpic = buff_qps;
QPS++; // qps zaehler erhoehen
create.play(); // sound abspielen
if (own == player) {layze-=3000;}
}
else if (typo == 5) // siehe oben
{
acunit[takethis].speed = 0; // siehe oben
acunit[takethis].uwidth = 170; // " "
acunit[takethis].uheight =170;
acunit[takethis].hp = 15;
acunit[takethis].range = 0;
acunit[takethis].upath = "buildings\\";
acunit[takethis].unitpic = buff_station;
//create.play();
if (own == player) {layze-=9000;}
}
else if (typo == 6) // siehe oben
{
acunit[takethis].speed = 0; // siehe oben
acunit[takethis].uwidth = 300; // " "
acunit[takethis].uheight =115;
acunit[takethis].hp = 7;
acunit[takethis].range = 0;
acunit[takethis].upath = "buildings\\";
acunit[takethis].unitpic = buff_qt;
if (own == player) {layze-=7500;}
}
acunit[takethis].prep = 0; // richtungs variable auf "up" hoch setzen = 0
acunit[takethis].alive = true; // unit lebt nun
acunit[takethis].s_ex = load_sound("sounds\\ex.wav"); //sounds laden
acunit[takethis].s_hit = load_sound("sounds\\hit.wav"); //sounds laden
acunit[takethis].s_shot = load_sound("rocket\\rocket.wav"); //sounds laden
acunit[takethis].s_voice_des = load_sound(acunit[takethis].upath+"voice_des.wav"); //sounds laden
acunit[takethis].s_voice_spawn = load_sound(acunit[takethis].upath+"voice_spawn.wav"); //sounds laden
acunit[takethis].s_voice_cmd = load_sound(acunit[takethis].upath+"voice_cmd.wav"); //sounds laden
if (own == player) {acunit[takethis].s_voice_spawn.play();} //sound spielen wenn vom spieler
acunit[takethis].utype = typo; //typ setzen
acunit[takethis].cmdd = false; // nicht auf dem weg irgendwo hin
acunit[takethis].chose = false; // nicht ausgewahlt
if (xx == 0) {acunit[takethis].ux = (int)Math.floor((Math.random()*300)+110+mapx);}
else {acunit[takethis].ux = xx;} // spawn point in random
if (yy == 0) {acunit[takethis].uy = (int)Math.floor((Math.random()*300)+30+mapy);}
else {acunit[takethis].uy = yy;} // spawn point in random
acunit[takethis].desx = 0; // keine destination
acunit[takethis].desy = 0; // keine destination
acunit[takethis].hitc = 0; // animationspic auf null
acunit[takethis].ishot = false; // kein schuss
acunit[takethis].atdelay = 150; // delay vom schiessen
acunit[takethis].attx = acunit[takethis].ux; // rakete unsichtbar positionieren
acunit[takethis].atty = acunit[takethis].uy; // rakete unsichtbar positionieren
acunit[takethis].attack = false; // kein angriff
if (own == player) {acunit[takethis].attpic = buff_missl[0];} // einheit bild laden
else {acunit[takethis].attpic = buff_missl[4];}// einheit bild laden
acunit[takethis].target = 0; // index of targetted "victim"
acunit[takethis].owner = own; // besitzer des raumschiffes zuweisen
unit_count++; // einheit zaehler erhoehen
}
}
public void destroy_ship(int iindex) // funktion um ein bestimmtes schiff zu loeschen
{ // parameter ist index des schiffes
if (acunit[iindex].utype == 4 && acunit[iindex].owner == 1) {QPS--;} // wenn es ein qps vom spieler ist dann qps runter zaehlen
acunit[iindex].alive = false; // nicht mehr aktiv
acunit[iindex] = new unit(); // konstruktor zum default setzen
unit_count--; // und runter zaehlen
}
public void mouseDragged(MouseEvent e)
{
rx2 = e.getX(); //maus daten speichern
ry2 = e.getY(); //maus daten speichern
}
public void mouseEntered (MouseEvent e) {}
public void mouseExited (MouseEvent e){}
public void mouseMoved (MouseEvent e)
{
mx = e.getX(); //maus daten speichern
my = e.getY(); //maus daten speichern
mb = e.getModifiers(); //maus daten speichern
}
public void mouseClicked (MouseEvent e){}
public void mousePressed (MouseEvent e)
{
int tempx = e.getX(); //maus daten speichern
int tempy = e.getY(); //maus daten speichern
mb = e.getModifiers(); //maus daten speichern
rx = e.getX(); // maus daten in rechnungsvariablen schreiben
ry = e.getY(); // maus daten in rechnungsvariablen schreiben
rx2 = rx; // maus daten in rechnungsvariablen schreiben
ry2 = ry; // maus daten in rechnungsvariablen schreiben
if (e.getModifiers() == 16) {marking = true;} // linke maus taste = markieren
for (int es = 0; es < unit_count; es++)
{
if ((tempx >= acunit[es].ux && tempx <= acunit[es].ux+acunit[es].uwidth) && (tempy >= acunit[es].uy && tempy <= acunit[es].uy+acunit[es].uheight) )
{ // kollision abfrage fur auswaehlen
if (e.getModifiers() == 16 && acunit[es].alive == true && acunit[es].owner == player)
{ // wenn linke maustaste, und einheit lebt, und es ist meine einheit
noselect(); //alle deselektieren
acunit[es].chose = true; // genau diesen hier markieren / auswahlen
acunit[es].s_voice_cmd.play(); // und sound spielen
}
}
else if (acunit[es].chose == true) // wenn einheit ausgewaehlt
{
if (e.getModifiers() == 4) //rechtsklick
{
acunit[es].desx = e.getX();//ziel des raumschiffes wo die maus ist;
acunit[es].desy = e.getY();//ziel des raumschiffes wo die maus ist;
px = e.getX(); //merken
py = e.getY(); //merken
acunit[es].desx +=(int)Math.floor((Math.random()*100)-50); // das ziel soll nicht ganz genau sein
acunit[es].desy +=(int)Math.floor((Math.random()*100)-50); // das ziel soll nicht ganz genau sein
acunit[es].cmdd = true; // los schicken
acunit[es].atdelay = 150; // mit delay
acunit[es].s_voice_des.play(); // und sound spielen
marki = 1; // status variable
acunit[es].attack = false; // kein angriff wärend des fluges
acunit[es].attx = acunit[es].ux + (acunit[es].uwidth/2); //rakete zurückholen
acunit[es].atty = acunit[es].uy + (acunit[es].uheight/2); //rakete zurückholen
}
else if (e.getModifiers() == 16) // maus links, auserhalb von einheiten
{noselect();} // deselektieren
}
}
if (tempx >= menux && tempx <= menux+menu_width) // grundsätzliches, ausrichtung
{
if (tempy >= menu_buildy && tempy <= menu_buildy+menu_height)
{
menu_build = load_img("menu\\b_alium_down.gif");
}
if (tempy >= menu_buildy+125 && tempy <= menu_buildy+menu_height+125)
{
menu_comm = load_img("menu\\b_commeatus_down.gif");
}
if (tempy >= menu_buildy+250 && tempy <= menu_buildy+menu_height+250)
{
menu_mucro = load_img("menu\\b_mucro_down.gif");
}
}
if (tempx >= 10 && tempx <= 10+100)
{
if(e.getY() >= menu_buildy && e.getY() <= menu_buildy+menu_height)
{
menu_qps = load_img("menu\\b_qps_down.gif");
}
if(e.getY() >= menu_buildy+125 && e.getY() <= menu_buildy+menu_height+125)
{
menu_station = load_img("menu\\b_station_down.gif");
}
if(e.getY() >= menu_buildy+250 && e.getY() <= menu_buildy+menu_height+250)
{
menu_qt = load_img("menu\\b_qt_down.gif");
}
}
}
public void mouseReleased (MouseEvent e)
{
marking = false;
rx2 = rx;
ry2 = ry;
if (e.getX() >= menux && e.getX() <= menux+menu_width) //menu klicks
{
if(e.getY() >= menu_buildy && e.getY() <= menu_buildy+menu_height) //menu klicks
{
menu_build = load_img("menu\\b_alium_up.gif"); //pic animations
if ((layze >= 4000) && (zahler < ulimit/2)) {whichship=1;bbar=1;} //unit bauen
if (layze < 4000) { s_nomoney.play();} // kein geld sound
if (zahler >= ulimit/2) { s_unitfull.play();}// units voll sound
}
if(e.getY() >= menu_buildy+125 && e.getY() <= menu_buildy+menu_height+125)
{
menu_comm = load_img("menu\\b_commeatus_up.gif"); // siehe oben etc
if ((layze >= 800) && (zahler < ulimit/2)) {whichship=2;bbar=1;}
if (layze < 800) { s_nomoney.play();}
if (zahler >= ulimit/2) { s_unitfull.play();}
}
if(e.getY() >= menu_buildy+250 && e.getY() <= menu_buildy+menu_height+250)
{
menu_mucro = load_img("menu\\b_mucro_up.gif"); // siehe oben etc
if ((layze >= 2750) && (zahler < ulimit/2)) {whichship=3;bbar=1;}
if (layze < 2750) { s_nomoney.play();}
if (zahler >= ulimit/2) { s_unitfull.play();}
}
}
if (e.getX() >= 10 && e.getX() <= 10+100)
{
if(e.getY() >= menu_buildy && e.getY() <= menu_buildy+menu_height)
{
menu_qps = load_img("menu\\b_qps_up.gif"); // siehe oben etc
if ((layze >= 3000) && (zahler < ulimit/2)) {whichship=4;bbar=1;}
if (layze < 3000) { s_nomoney.play();}
if (zahler >= ulimit/2) { s_unitfull.play();}
}
if(e.getY() >= menu_buildy+125 && e.getY() <= menu_buildy+menu_height+125)
{
menu_station = load_img("menu\\b_station_up.gif"); // siehe oben etc
if ((layze >= 9000) && (zahler < ulimit/2)) {whichship=5;bbar=1;}
if (layze < 9000) { s_nomoney.play();}
if (zahler >= ulimit/2) { s_unitfull.play();}
}
if(e.getY() >= menu_buildy+250 && e.getY() <= menu_buildy+menu_height+250)
{
menu_qt = load_img("menu\\b_qt_up.gif"); // siehe oben etc
if ((layze >= 7500) && (zahler < ulimit/2)) {whichship=6;bbar=1;}
if (layze < 7500) { s_nomoney.play();}
if (zahler >= ulimit/2) { s_unitfull.play();}
}
}
}
public void noselect() // funktion zum deselektieren aller einheiten
{
for (int no = 0; no < unit_count; no++) //schleife vom index 0 bis soviele wie es gibt
{
acunit[no].chose = false; //ausgewaehlt = nein
conx1=0; //rechnungsvariablen auch null
conx2=0;
cony1=0;
cony2=0;
}
}
public void start() // start funktion des threads
{
if (th == null) {
running = true;
th = new Thread(this);
th.setPriority(10);
th.start();
}
}
public void stop() // stop funktion des threads
{
if (th != null) {
running = false;
th = null;
}
}
public void run() // run funktion des threads, gameloop
{
while (running) // gameloop
{
if (newtime-oldtime >= 1000) {fpsa();oldtime=System.currentTimeMillis();}
newtime = System.currentTimeMillis();
zahler = 0;
for (int cc = 0; cc < unit_count; cc++)
{
if (acunit[cc].owner == player && acunit[cc].alive) { zahler++; }
} // eigene einheiten lokal gezaehlt
if (mx <= 25 && mapx <= 0) // map und einheiten bewegen durch maus bewegung
{
mapx+=2;
for (int ji = 0; ji < unit_count; ji++)
{
if (acunit[ji].alive == true) // wenn einheit aktiv auch bewegen
{
acunit[ji].ux+=2;
acunit[ji].desx+=2; // rechts bewegung der map und einheiten
acunit[ji].attx+=2;
}
}
}
if (mx >= 999 && mapx >= -1460)
{
mapx-=2;
for (int ji = 0; ji < unit_count; ji++)
{ // siehe oben nur andere richtung immer
if (acunit[ji].alive == true)
{
acunit[ji].ux-=2;
acunit[ji].desx-=2;
acunit[ji].attx-=2;
}
}
}
if (my <= 45 && mapy <= 0)
{ // siehe oben nur andere richtung immer
mapy+=2;
for (int ji = 0; ji < unit_count; ji++)
{
if (acunit[ji].alive == true)
{
acunit[ji].uy+=2;
acunit[ji].desy+=2;
acunit[ji].atty+=2;
}
}
}
if (my >= 715 && mapy >= -1260)
{ // siehe oben nur andere richtung immer
mapy-=2;
for (int ji = 0; ji < unit_count; ji++)
{
if (acunit[ji].alive == true)
{
acunit[ji].uy-=2;
acunit[ji].desy-=2;
acunit[ji].atty-=2;
}
}
}
if (bbar > 0) {bbar++;} // wenn bbar > 0 dann gehts los
if (bbar >= 100) { bbar=0;add_ship(whichship,player,0,0);} // wenn fertig: bauen
for (int sc = 0; sc < QPS;sc++) // layze durch qps erhoehen
{
lplus+=0.5f;
}
if (lplus >= 7.0f) {layze+=1; lplus=0f;} // layze durch qps erhoehen
if (playm) //MUSIK
{ //MUSIK
music.loop(); //MUSIK
playm = false; //MUSIK
} //MUSIK
//-----------------------------------------------
//ENCOUNTER
for (int e1 = 0; e1 < unit_count; e1++)
{
for (int e2 = 0; e2 < unit_count; e2++) //algorithmus um gegner in
{ // der nahe zu finden und anzugreifen
if (acunit[e1].alive && acunit[e2].alive) // wenn beide leben
{
if (acunit[e1].owner != acunit[e2].owner) // wenn anderer dem gegner gehort
{
if((acunit[e1].ux >= acunit[e2].ux-200 && acunit[e1].ux <= acunit[e2].ux+200) && (acunit[e1].uy >= acunit[e2].uy-200 && acunit[e1].uy <= acunit[e2].uy+200))
{ // wenn im bereich (range)
acunit[e1].attack = true; // angreifen
acunit[e1].target = e2; // target ist die index des gegners
}
else
{
acunit[e1].attack = false; // sonst nicht angreifen
}
}
}
}
}
// ENCOUNTER
//----------------------------------------------------------
// Shoot
for (int ts = 0; ts < unit_count; ts++)
{
if (acunit[ts].attack == false)
{
acunit[ts].attx = acunit[ts].ux + (acunit[ts].uwidth/2);
acunit[ts].atty = acunit[ts].uy + (acunit[ts].uheight/2);
}
if (acunit[ts].hitc > 0) { acunit[ts].hitc++;}
if (acunit[ts].alive && acunit[ts].attack)
{
if (acunit[ts].cmdd)
{
acunit[ts].attx = acunit[ts].ux + (acunit[ts].uwidth/2);
acunit[ts].atty = acunit[ts].uy + (acunit[ts].uheight/2);
}
if (acunit[ts].cmdd == false && acunit[ts].attack)
{ acunit[ts].prep = 0;
// hier wird die richtung der einheit neu eingestellt
//je nach gegebenheiten
if (acunit[ts].ux < (acunit[acunit[ts].target].ux-(acunit[acunit[ts].target].uwidth/2)))
{
acunit[ts].prep = 2;
if (acunit[ts].uy < (acunit[acunit[ts].target].uy-(acunit[acunit[ts].target].uheight/2)))
{
acunit[ts].prep = 3;
}
if (acunit[ts].uy > (acunit[acunit[ts].target].uy-(acunit[acunit[ts].target].uheight/2)))
{
acunit[ts].prep = 1;
}
}
else if (acunit[ts].ux > (acunit[acunit[ts].target].ux-(acunit[acunit[ts].target].uwidth/2)))
{
acunit[ts].prep = 6;
if (acunit[ts].uy < (acunit[acunit[ts].target].uy-(acunit[acunit[ts].target].uheight/2)))
{
acunit[ts].prep = 5;
}
if (acunit[ts].uy > (acunit[acunit[ts].target].uy-(acunit[acunit[ts].target].uheight/2)))
{
acunit[ts].prep = 7;
}
}
else
{
if (acunit[ts].uy < (acunit[acunit[ts].target].uy-(acunit[acunit[ts].target].uheight/2)))
{
acunit[ts].prep = 4;
}
if (acunit[ts].uy > (acunit[acunit[ts].target].uy-(acunit[acunit[ts].target].uheight/2)))
{
acunit[ts].prep = 0;
}
}
if (acunit[ts].explo == false)
{
if (acunit[ts].utype == 1) // alium
{acunit[ts].unitpic = buff_alium[acunit[ts].prep];}
if (acunit[ts].utype == 2) // commeatus
{acunit[ts].unitpic = buff_comm[acunit[ts].prep];}
if (acunit[ts].utype == 3) // mucro
{acunit[ts].unitpic = buff_mucro[acunit[ts].prep];}
}
}
if (acunit[ts].atdelay <= 0) //150
{
if (acunit[ts].ishot == false && acunit[ts].cmdd == false)
{
acunit[ts].s_shot.play();
acunit[ts].ishot=true;
}
if (acunit[ts].hitc == 0) //0
{
if (acunit[ts].attx+30 < acunit[acunit[ts].target].ux+(acunit[acunit[ts].target].uwidth/2)) {acunit[ts].attx+=2;}
if (acunit[ts].attx+30 > acunit[acunit[ts].target].ux+acunit[acunit[ts].target].uwidth) {acunit[ts].attx-=2;}
if (acunit[ts].atty+30 < acunit[acunit[ts].target].uy+(acunit[acunit[ts].target].uheight/2)) {acunit[ts].atty+=2;}
if (acunit[ts].atty+30 > acunit[acunit[ts].target].uy+acunit[acunit[ts].target].uheight) {acunit[ts].atty-=2;}
}
}
else
{
acunit[ts].atdelay--;
}
if (acunit[ts].attx+30 >= acunit[acunit[ts].target].ux + (acunit[acunit[ts].target].uwidth/2))
{if (acunit[ts].attx+30 <= acunit[acunit[ts].target].ux+acunit[acunit[ts].target].uwidth)
{if (acunit[ts].atty+30 >= acunit[acunit[ts].target].uy + (acunit[acunit[ts].target].uheight/2))
{if (acunit[ts].atty+30 <= acunit[acunit[ts].target].uy+acunit[acunit[ts].target].uheight)
{
if (acunit[ts].hitc == 0) {acunit[ts].hitc = 1;}
}
}
}
}
// hier passieren sachen mit angreifen
// wie kollision der rakete etc und hp abziehen
if (acunit[ts].hitc == 10) {acunit[ts].attpic = buff_hit[0];}
if (acunit[ts].hitc == 20) {acunit[ts].attpic = buff_hit[1];}
if (acunit[ts].hitc == 30) {acunit[ts].attpic = buff_hit[2];acunit[ts].s_hit.play();}
if (acunit[ts].hitc == 40) {acunit[ts].attpic = buff_hit[3];}
if (acunit[ts].hitc == 50) {acunit[ts].attpic = buff_hit[4];}
if (acunit[ts].hitc == 60) {acunit[ts].attpic = buff_hit[5];}
if (acunit[ts].hitc == 70) {acunit[ts].attpic = buff_hit[6];}
if (acunit[ts].hitc == 80) {acunit[ts].attpic = buff_hit[7];}
if (acunit[ts].hitc == 90) {acunit[ts].attpic = buff_hit[8];}
if (acunit[ts].hitc == 100)
{
acunit[ts].attx = acunit[ts].ux + (acunit[ts].uwidth/2);
acunit[ts].atty = acunit[ts].uy + (acunit[ts].uheight/2);
acunit[ts].atdelay = 150;
acunit[acunit[ts].target].hp--;
acunit[ts].ishot = false;
//für hit animation sorgen indem die attpic = explo pics wird
// und dieses festhalten solang
acunit[ts].hitc = 0;
}
if (acunit[acunit[ts].target].hp <= 0)
{
acunit[ts].attack = false;
acunit[ts].attpic = buff_missl[0];
acunit[acunit[ts].target].explo = true;
}
if (acunit[acunit[ts].target].alive == false)
{
acunit[ts].attx = acunit[ts].ux + (acunit[ts].uwidth/2);
acunit[ts].atty = acunit[ts].uy + (acunit[ts].uheight/2);
acunit[ts].atdelay = 150;
acunit[acunit[ts].target].hp--;
acunit[ts].ishot = false;
acunit[ts].hitc = 0;
}
}
}
for (int sdreh = 0; sdreh < unit_count; sdreh++)
{
if ((acunit[sdreh].cmdd == false) && (acunit[sdreh].hitc == 0))
{
acunit[sdreh].attpic = buff_missl[0];
// je nach richtung werden hier die raketen bewegt
if (acunit[sdreh].attx < (acunit[acunit[sdreh].target].ux+(acunit[acunit[sdreh].target].uwidth/2)))
{
acunit[sdreh].attpic = buff_missl[2];
if (acunit[sdreh].atty < (acunit[acunit[sdreh].target].uy+(acunit[acunit[sdreh].target].uheight/2)))
{
acunit[sdreh].attpic = buff_missl[3];
}
if (acunit[sdreh].atty > (acunit[acunit[sdreh].target].uy+(acunit[acunit[sdreh].target].uheight/2)))
{
acunit[sdreh].attpic = buff_missl[1];
}
}
else if (acunit[sdreh].attx > (acunit[acunit[sdreh].target].ux+(acunit[acunit[sdreh].target].uwidth/2)))
{
acunit[sdreh].attpic = buff_missl[6];
if (acunit[sdreh].atty < (acunit[acunit[sdreh].target].uy+(acunit[acunit[sdreh].target].uheight/2)))
{
acunit[sdreh].attpic = buff_missl[5];
}
if (acunit[sdreh].atty > (acunit[acunit[sdreh].target].uy+(acunit[acunit[sdreh].target].uheight/2)))
{
acunit[sdreh].attpic = buff_missl[7];
}
}
else
{
if (acunit[sdreh].atty < (acunit[acunit[sdreh].target].uy+(acunit[acunit[sdreh].target].uheight/2)))
{
acunit[sdreh].attpic = buff_missl[4];
}
if (acunit[sdreh].atty > (acunit[acunit[sdreh].target].uy+(acunit[acunit[sdreh].target].uheight/2)))
{
acunit[sdreh].attpic = buff_missl[0];
}
}
}
}
// Shoot
//----------------------------------------------------------
//Schuss bewegung, komplexe sachen :)
for (int oo = 0; oo < unit_count; oo++)
{
if (acunit[oo].hitc > 0 && acunit[oo].alive == false) {acunit[oo].attpic=buff_missl[0];}
if (acunit[oo].cmdd == true)
{ acunit[oo].prep = 0;
if (acunit[oo].ux < (acunit[oo].desx-(acunit[oo].uwidth/2)))
{
acunit[oo].prep = 2;
acunit[oo].ux+=acunit[oo].speed; // je nach richtung wird hier eine einheit zum ziel bewegt
if (acunit[oo].uy < (acunit[oo].desy-(acunit[oo].uheight/2)))
{
acunit[oo].uy+=acunit[oo].speed;
acunit[oo].prep = 3;
}
if (acunit[oo].uy > (acunit[oo].desy-(acunit[oo].uheight/2)))
{
acunit[oo].uy-=acunit[oo].speed;
acunit[oo].prep = 1;
}
}
else if (acunit[oo].ux > (acunit[oo].desx-(acunit[oo].uwidth/2)))
{
acunit[oo].ux-=acunit[oo].speed;
acunit[oo].prep = 6;
if (acunit[oo].uy < (acunit[oo].desy-(acunit[oo].uheight/2)))
{
acunit[oo].uy+=acunit[oo].speed;
acunit[oo].prep = 5;
}
if (acunit[oo].uy > (acunit[oo].desy-(acunit[oo].uheight/2)))
{
acunit[oo].uy-=acunit[oo].speed;
acunit[oo].prep = 7;
}
}
else
{
if (acunit[oo].uy < (acunit[oo].desy-(acunit[oo].uheight/2)))
{
acunit[oo].uy+=acunit[oo].speed;
acunit[oo].prep = 4;
}
if (acunit[oo].uy > (acunit[oo].desy-(acunit[oo].uheight/2)))
{
acunit[oo].uy-=acunit[oo].speed;
acunit[oo].prep = 0;
}
}
if ((acunit[oo].ux == (acunit[oo].desx-(acunit[oo].uwidth/2))) && (acunit[oo].uy == (acunit[oo].desy-(acunit[oo].uheight/2))) ) {acunit[oo].cmdd = false;}
if (acunit[oo].utype == 1) // alium
{
acunit[oo].unitpic = buff_alium[acunit[oo].prep];
}
if (acunit[oo].utype == 2) // commeatus
{
acunit[oo].unitpic = buff_comm[acunit[oo].prep];
}
if (acunit[oo].utype == 3) // mucro
{
acunit[oo].unitpic = buff_mucro[acunit[oo].prep];
}
}
}
// v explosion v
for (int aa = 0; aa < unit_count; aa++)
{
if (acunit[aa].alive && acunit[aa].explo)
{
acunit[aa].ex++;
//explosions animation
if (acunit[aa].ex == 10) {acunit[aa].unitpic = buff_expl[0];}
if (acunit[aa].ex == 20) {acunit[aa].unitpic = buff_expl[1];}
if (acunit[aa].ex == 30) {acunit[aa].unitpic = buff_expl[2];acunit[aa].s_ex.play();}
if (acunit[aa].ex == 40) {acunit[aa].unitpic = buff_expl[3];}
if (acunit[aa].ex == 50) {acunit[aa].unitpic = buff_expl[4];}
if (acunit[aa].ex == 60) {acunit[aa].unitpic = buff_expl[5];}
if (acunit[aa].ex == 70) {acunit[aa].unitpic = buff_expl[6];}
if (acunit[aa].ex == 80) {acunit[aa].unitpic = buff_expl[7];}
if (acunit[aa].ex == 90) {acunit[aa].unitpic = buff_expl[8];}
if (acunit[aa].ex == 100) {acunit[aa].unitpic = buff_expl[9];}
if (acunit[aa].ex == 110) {acunit[aa].unitpic = buff_expl[10];}
if (acunit[aa].ex == 120) {acunit[aa].unitpic = buff_expl[10];}
if (acunit[aa].ex == 130)
{
destroy_ship(aa); // schiff zerstoeren wenn explosion endet
acunit[aa].ex = 0;
acunit[aa].explo = false;
}
}
}
// ^ explosion ^
for (int qq = 0; qq < unit_count; qq++)
{
if((acunit[qq].ux >= acunit[acunit[qq].target].ux-acunit[qq].range && acunit[qq].ux <= acunit[acunit[qq].target].ux+acunit[qq].range) && (acunit[qq].uy >= acunit[acunit[qq].target].uy-acunit[qq].range && acunit[qq].uy <= acunit[acunit[qq].target].uy+acunit[qq].range))
{/*alles ok und so*/} else { acunit[qq].attack = false; } // attack bedingungen nochmals prüfen und ggf attacke unterbrechen
}
if ( zahler == 0 && starto) {loser = true;this.stop();music.stop();s_lose.play();} // wenn deine einheiten 0 dann verloren
for (int cg = 0; cg < unit_count; cg++) // gegnerische einheiten zaehlen
{
if (acunit[cg].owner != player && acunit[cg].alive) { e_z++; }
}
if (e_z == 0) {winner = true;this.stop();music.stop();s_win.play();} // wenn gegner keine einheiten mehr hat dann gewonnen
repaint();
framecount++;
try
{
Thread.sleep(schlaf); // thread wartezeit
}
catch (InterruptedException e)
{
//nothing
}
}
}
public void update (Graphics g) // double buffering
{
// Initialisierung des DoubleBuffers
if (dbImage == null)
{
dbImage = createImage (this.getSize().width, this.getSize().height);
dbg = dbImage.getGraphics ();
}
// Bildschirm im Hintergrund löschen
dbg.setColor (getBackground ());
dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);
// Auf gelöschten Hintergrund Vordergrund zeichnen
dbg.setColor (getForeground());
paint (dbg);
// Nun fertig gezeichnetes Bild Offscreen auf dem richtigen Bildschirm anzeigen
g.drawImage (dbImage, 0, 0, this);
}
public void paint(Graphics g)
{
g.drawImage(map,mapx,mapy,this); // map, karte zeichnen
for (int ei = 0; ei < unit_count; ei++)
{
if (acunit[ei].alive == true)
{
g.drawImage(acunit[ei].unitpic,acunit[ei].ux,acunit[ei].uy,this);
if (wires) // wenn wires aktiv sind
{
g.setColor(mark); // wires zu targets und zum schiff mittel punkt
g.drawLine(acunit[ei].ux,acunit[ei].uy,acunit[acunit[ei].target].ux,acunit[acunit[ei].target].uy);
g.setColor(new Color(244,80,80));
g.drawLine(acunit[ei].ux,acunit[ei].uy,acunit[ei].attx,acunit[ei].atty);
}
if (marking)
{
if (acunit[ei].ux >= conx1 && acunit[ei].ux <= conx2 && acunit[ei].uy >= cony1 && acunit[ei].uy <= cony2)
{
if (acunit[ei].owner == player) { acunit[ei].chose = true;}
}
}
}
if (acunit[ei].chose == true)
{
g.setColor(mark);
g.drawRect(acunit[ei].ux,acunit[ei].uy,acunit[ei].uwidth,acunit[ei].uheight);
if (marki > 0)
{
g.setColor(new Color(100,240,100));
g.fillOval(px-3, py-3, 7,7);
g.drawOval(px-marki,py-marki,((marki*2)+1),((marki*2)+1));
g.setColor(mark);
marki++;
}
if (marki >= 25) { marki = 0; }
}
}
for (int ho = 0; ho < unit_count; ho++) // die raketen zeichnen wenn ein angriff besteht
{
if (acunit[ho].attack == true && acunit[ho].atdelay == 0 && acunit[ho].alive == true)
{
g.drawImage(acunit[ho].attpic,acunit[ho].attx,acunit[ho].atty,this);
}
}
g.setColor(bg);
g.fillRect(870,45,70,16);
g.fillRect(980,45,35,16);
g.setColor(Color.white);
g.fillRect(menux, menu_buildy-15,bbar,10);
g.drawImage(menu_build,menux,menu_buildy,this);
g.drawImage(menu_comm,menux,menu_buildy+125,this);
g.drawImage(menu_mucro,menux,menu_buildy+250,this);
g.drawImage(menu_qps,10,menu_buildy,this);
g.drawImage(menu_station,10,menu_buildy+125,this);
g.drawImage(menu_qt,10,menu_buildy+250,this);
g.setColor(fontcolor);
g.drawImage(img_qps,745,40,this);
g.drawString(""+QPS,790,57);
g.drawImage(img_layze,835,40,this);
g.drawString(" "+layze,872,57);
g.drawImage(limit,945,40,this);
g.drawString(""+zahler+"/"+ulimit/2,982,57);
g.setColor(mark);
if (marking == true && mb == 16) // maus makierung zeichnen, wenn man gedrueckt haelt
// war tricky ;)
{
if (((rx2-rx) > 0) && ((ry2-ry) > 0))
{
g.drawRect(rx,ry,(rx2-rx),(ry2-ry));
conx1 = rx;
cony1 = ry;
conx2 = rx + (rx2-rx);
cony2 = ry + (ry2-ry);
}
else if (((rx2-rx) < 0) && ((ry2-ry) < 0))
{
g.drawRect(rx2,ry2,(rx-rx2),(ry-ry2));
conx1 = rx2;
cony1 = ry2;
conx2 = rx2 + (rx-rx2);
cony2 = ry2 + (ry-ry2);
}
else if (((rx2-rx) > 0) && ((ry2-ry) < 0))
{
g.drawRect(rx,ry2,(rx2-rx),(ry-ry2));
conx1 = rx;
cony1 = ry2;
conx2 = rx + (rx2-rx);
cony2 = ry2 + (ry-ry2);
}
else if (((rx2-rx) < 0) && ((ry2-ry) > 0))
{
g.drawRect(rx2,ry,(rx-rx2),(ry2-ry));
conx1 = rx2;
cony1 = ry;
conx2 = rx2 + (rx-rx2);
cony2 = ry + (ry2-ry);
}
}
if (winner) {g.drawImage(pic_win,250,330,this);} // wenn gewonnen "you win" zeichnen
if (loser) {g.drawImage(pic_lose,250,330,this);} // wenn verloren "you lose" zeichnen
}
}