Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (427)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (466)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
  JavaGaming.org - Pastebin



Author: Gef (posted 2014-02-10 23:32:56, viewed 72 times)

1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48   49   50   51   52   53   54   55   56   57   58   59   60   61   62   63   64   65   66   67   68   69   70   71   72   73   74   75   76   77   78   79   80   81   82   83   84   85   86   87   88   89   90   91   92   93   94   95   96   97   98   99   100   101   102   103   104   105   106   107   108   109   110   111   112   113   114   115   116   117   118   119   120   121   122   123   124   125   126   127   128   129   130   131   132   133   134   135   136   137   138   139   140   141   142   143   144   145   146   147   148   149   150   151   152   153   154   155   156   157   158   159   160   161   162   163   164   165   166   167   168   169   170   171   172   173   174   175   176   177   178   179   180   181   182   183   184   185   186   187   188   189   190   191   192   193   194   195   196   197   198   199   200   201   202   203   204   205   206   207   208   209   210   211   212   213   214   215   216   217   218   219   220   221   222   223   224   225   226   227   228   229   230   231   232   233   234   235   236   237   238   239   240   241   242   243   244   245   246   247   248   249   250   251   252   253   254   255   256   257   258   259   260   261   262   263   264   265   266   267   268   269   270   271   272   273   274   275   276   277   278   279   280   281   282   283   284   285   286   287   288   289   290   291   292   293   294   295   296   297   298   299   300   301   302   303   304   305   306   307   308   309   310   311   312   313   314   315   316   317   318   319   320   321   322   323   324   325   326   327   328   329   330   331   332   333   334   335   336   337   338   339   340   341   342   343   344   345   346   347   348   349   350   351   352   353   354   355   356   357   358   359   360   361   362   363   364   365   366   367   368   369   370   371   372   373   374   375   376   377   378   379   380   381   382   383   384   385   386   387   388   389   390   391   392   393   394   395   396   397   398   399   400   401   402   403   404   405   406   407   408   409   410   411   412   413   414   415   416   417   418   419   420   421   422   423   424   425   426   427   428   429   430   431   432   433   434   435   436   437   438   439   440   441   442   443   444   445   446   447   448   449   450   451   452   453   454   455   456   457   458   459   460   461   462   463   464   465   466   467   468   469   470   471   472   473   474   475   476   477   478   479   480   481   482   483   484   485   486   487   488   489   490   491   492   493   494   495   496   497   498   499   500   501   502   503   504   505   506   507   508   509   510   511   512   513   514   515   516   517   518   519   520   521   522   523   524   525   526   527   528   529   530   531   532   533   534   535   536   537   538   539   540   541   542   543   544   545   546   547   548   549   550   551   552   553   554   555   556   557   558   559   560   561   562   563   564   565   566   567   568   569   570   571   572   573   574   575   576   577   578   579   580   581   582   583   584   585   586   587   588   589   590   591   592   593   594   595   596   597   598   599   600   601   602   603   604   605   606   607   608   609   610   611   612   613   614   615   616   617   618   619   620   621   622   623   624   625   626   627   628   629   630   631   632   633   634   635   636   637   638   639   640   641   642   643   644   645   646   647   648   649   650   651   652   653   654   655   656   657   658   659   660   661   662   663   664   665   666   667   668   669   670   671   672   673   674   675   676   677   678   679   680   681   682   683   684   685   686   687   688   689   690   691   692   693   694   695   696   697   698   699   700   701   702   703   704   705   706   707   708   709   710   711   712   713   714   715   716   717   718   719   720   721   722   723   724   725   726   727   728   729   730   731   732   733   734   735   736   737   738   739   740   741   742   743   744   745   746   747   748   749   750   751   752   753   754   755   756   757   758   759   760   761   762   763   764   765   766   767   768   769   770   771   772   773   774   775   776   777   778   779   780   781   782   783   784   785   786   787   788   789   790   791   792   793   794   795   796   797   798   799   800   801   802   803   804   805   806   807   808   809   810   811   812   813   814   815   816   817   818   819   820   821   822   823   824   825   826   827   828   829   830   831   832   833   834   835   836   837   838   839   840   841   842   843   844   845   846   847   848   849   850   851   852   853   854   855   856   857   858   859   860   861   862   863   864   865   866   867   868   869   870   871   872   873   874   875   876   877   878   879   880   881   882   883   884   885   886   887   888   889   890   891   892   893   894   895   896   897   898   899   900   901   902   903   904   905   906   907   908   909   910   911   912   913   914   915   916   917   918   919   920   921   922   923   924   925   926   927   928   929   930   931   932   933   934   935   936   937   938   939   940   941   942   943   944   945   946   947   948   949   950   951   952   953   954   955   956   957   958   959   960   961   962   963   964   965   966   967   968   969   970   971   972   973   974   975   976   977   978   979   980   981   982   983   984   985   986   987   988   989   990   991   992   993   994   995   996   997   998   999   1000   1001   1002   1003   1004   1005   1006   1007   1008   1009   1010   1011   1012   1013   1014   1015   1016   1017   1018   1019   1020   1021   1022   1023   1024   1025   1026   1027   1028   1029   1030   1031   1032   1033   1034   1035   1036   1037   1038   1039   1040   1041   1042   1043   1044   1045   1046   1047   1048   1049   1050   1051   1052   1053   1054   1055   1056   1057   1058   1059   1060   1061   1062   1063   1064   1065   1066   1067   1068   1069   1070   1071   1072   1073   1074   1075   1076   1077   1078   1079   1080   1081   1082   1083   1084   1085   1086   1087   1088   1089   1090   1091   1092   1093   1094   1095   1096   1097   1098   1099   1100   1101   1102   1103   1104   1105   1106   1107   1108   1109   1110   1111   1112   1113   1114   1115   1116   1117   1118   1119   1120   1121   1122   1123   1124   1125   1126   1127   1128   1129   1130   1131   1132   1133   1134   1135   1136   1137   1138   1139   1140   1141   1142   1143   1144   1145   1146   1147   1148   1149   1150   1151   1152   1153   1154   1155   1156   1157   1158   1159   1160   1161   1162   1163   1164   1165   1166   1167   1168   1169   1170   1171   1172   1173   1174   1175   1176   1177   1178   1179   1180   1181   1182   1183   1184   1185   1186   1187   1188   1189   1190   1191   1192   1193   1194   1195   1196   1197   1198   1199   1200   1201   1202   1203   1204   1205   1206   1207   1208   1209   1210   1211   1212   1213   1214   1215   1216   1217   1218   1219   1220   1221   1222   1223   1224   1225   1226   1227   1228   1229   1230   1231   1232   1233   1234   1235   1236   1237   1238   1239   1240   1241   1242   1243   1244   1245   1246   1247   1248   1249   1250   1251   1252   1253   1254   1255   1256   1257   1258   1259   1260   1261   1262   1263   1264   1265   1266   1267   1268   1269   1270   1271   1272   1273   1274   1275   1276   1277   1278   1279   1280   1281   1282   1283   1284   1285   1286   1287   1288   1289   1290   1291   1292   1293   1294   1295   1296   1297   1298   1299   1300   1301   1302   1303   1304   1305   1306   1307   1308   1309   1310   1311   1312   1313   1314   1315   1316   1317   1318   1319   1320   1321   1322   1323   1324   1325   1326   1327   1328   1329   1330   1331   1332   1333   1334   1335   1336   1337   1338   1339   1340   1341   1342   1343   1344   1345   1346   1347   1348   1349   1350   1351   1352   1353   1354   1355   1356   1357   1358   1359   1360   1361   1362   1363   1364   1365   1366   1367   1368   1369   1370   1371   1372   1373   1374   1375   1376   1377   1378   1379   1380   1381   1382   1383   1384   1385   1386   1387   1388   1389   1390  
import java.applet.Applet;
import java.awt.Color;
import java.awt.Event;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.util.Random;

/**
 * Raid On Java 4K, Felix Unger 2014

 * Felix.Unger.Germany@gmx.de

 * Java4k 2014 contest http://java4k.com

 * 

 * <b>The Story:</b>

 * After the evil empire has attacked your home (the java islands) and builds evil factories, it is time for revenge.

 * 

 * You come home on an aircraft carrier equipped with a helicopter. Your job is to destroy the factories (grey squares) on the java islands. To accomplish your mission, you must bomb each factory with eight bombs (press B-key). But beware, the higher your progress the harder is the defense. In other words, there are more enemy jets with more hitpoints and the defense towers can shoot a longer distance.

 * 

 * The warzone consists of 8 islands. Four Islands are on the right side from your carrier and four on the left. Every island has two factories. If you destroy a factory, you�ll reach the next level. Enemy jets respawn immediately. In total the game has 16 levels.

 * 

 * Your helicopter can only carry 9 bombs. Thus, you have to reload after an attack. To reload, you�ll have to land on the aircraft carrier (press space). Whilst landed, your helicopter will be reloaded and repaired. So don�t start too early. Luckily your helicopter is secured as long as it stays on the carrier.

 * 

 * The carrier moves from south to north to avoid enemy fire. So you have to search the carrier in the warzone.

 * 

 * Please note that the warzone has no border. If you fly long enough in one direction, you will return to your starting point. Instructions/Input:

 * 

 * <b>Instructions/Input:</b>

 * <ul>
 * <li>Enter to start</li>

 * <li>Space = Land on/start from aircraft carrier.
 * <ul>
 * <li>For landing, the helicopter needs a direct contact with the carrier.</li>
 * </ul>
 * <li>Cursorkeys = Controlling the helicopter</li>

 * <li>F = fires the machine gun
 * <li>B = drops a Bomb

 * <ul>
 * <li>For bombing a factory, you have to stay above a factory and press B. You�ll see a great explosion; you have a direct hit on the target. Otherwise there is only a small explosion. In this case, you�ll need to aim better.
 * </ul>
 * </ul>
 * 
 * @author Felix Unger
 */
@SuppressWarnings("serial")
public class A extends Applet implements Runnable
{

   public void start()
   {
      new Thread(this).start();
   }

   private final static int SCREEN_WIDTH = 320;
   private final static int SCREEN_HEIGHT = 256;

   private final static int MAP_WIDTH = 2048;
   private final static int MAP_HEIGHT = 2048;
   private final static int MAP_CENTER_X = 1024;
   private final static int MAP_CENTER_Y = 1024;

   private final static int HEATMAP_WIDTH = 512;
   private final static int HEATMAP_HEIGHT = 512;
   private final static int HEATMAP_LENGTH = HEATMAP_WIDTH * HEATMAP_HEIGHT;
   private final static int HEATMAP_COOLDOWN = 10;

   // Factory datastructure
   private final static int FAC_NUMBER = 16;
   private final static int FAC_DATA_LENGTH = 4;
   private final static int FAC_HEALTH = 0;
   private final static int FAC_XPOS = 1;
   private final static int FAC_YPOS = 2;
   private final static int FAC_HEALTH_START_VALUE = 12000;
   private final static int FAC_BOMB_DAMAGE = 1500;

   // Enemy.
   private final static int ENM_NUMBER = 96;
   private final static int ENM_INT_DATA_LENGTH = 7;
   // 0 = dead

   private final static int ENM_INT_COLOR = 1;
   // 0 = can shoot
   private final static int ENM_INT_FIRE_REPEAT = 2;
   private final static int ENM_INT_X_POS = 3;
   private final static int ENM_INT_Y_POS = 4;
   // 0 = hang around
   // 1 = attack player
   private final static int ENM_INT_ATTACK_STATUS = 5;
   private final static int ENM_INT_CHANGE_DIRECTION = 6;
   private final static int ENM_DBL_DATA_LENGTH = 6;

   private final static int ENM_DBL_X_POS = 1;
   private final static int ENM_DBL_Y_POS = 2;
   private final static int ENM_DBL_X_SPEED = 3;
   private final static int ENM_DBL_Y_SPEED = 4;
   private final static int ENM_DBL_NEW_DIRECTION = 5;

   // defense tower
   private final static int TOWER_NUMBER = 16;
   private final static int TOWER_INIT_HEALTH = 10;
   private final static int TOWER_DATA_LENGTH = 4;

   private final static int TOWER_XPOS = 1;
   private final static int TOWER_YPOS = 2;
   private final static int TOWER_FIRE_REPEAT = 3;

   private final static int SHOOT_NUMBER = 10 + ENM_NUMBER + TOWER_NUMBER;
   private final static int SHOOT_DATA_LENGTH = 5;

   private final static int SHOOT_X_POS = 1;
   private final static int SHOOT_Y_POS = 2;
   private final static int SHOOT_X_SPEED = 3;
   private final static int SHOOT_Y_SPEED = 4;

   private final static int COPTER_INIT_HEALTH = 10;
   private final static int COPTER_INIT_BOMBS = 9;
   private final static double COPTER_ACCL = 0.1f;
   private final static double ROTOR_ACCL = 0.01f;

   private final static int CARRIER_X = 1004;

   private final static int WATER_COL = 0xff000088;

   private final int KEY_UP = 1004;
   private final int KEY_DOWN = 1005;
   private final int KEY_LEFT = 1006;
   private final int KEY_RIGHT = 1007;
   private final int KEY_F = 102;
   private final int KEY_B = 98;
   private final int KEY_ENTER = 10;
   private final int KEY_SPACE = 32;

   // *** Globals ***
   int scrX;
   int scrY;
   int iCopterX;
   int iCopterY;
   int screenTopLeftX;
   int screenTopLeftY;
   int screenTopLeftXOld;
   int screenTopLeftYOld;
   int[] screenPixels;
   Random random;

   // Heatmap
   int[] heatMap1;

   // Boolean array for keyboard
   boolean[] keyboardMap;

   // *** Globals END ***

   public void run()
   {
      // *** Locals ***

      Graphics frameGraphics;
      Graphics2D screenImageG2D;
      BufferedImage screenImage;

      double[] towerDblData;
      int[] towerData;

      // bullet data
      // first 10 slots for the player.
      // rest for the jets. Every jet has one slot.
      double[] shootData;

      int[] mapData;

      int[] fabData;

      // Integer arrays for gfx
      int[] copterGfxData;
      int[] rotorGfxData;
      int[] jetGfxData;
      int[] jetIntData;
      double[] jetDoubleData;

      // Heatmap vars
      BufferedImage heatmapImage;
      int[] heatmapPixels;
      int[] heatMap2;

      long lastTime;

      int bombWaitCounter;

      double dCopterX;
      double dCopterY;
      // collision square
      int coptKolx1;
      int coptKoly1;
      int coptKolx2;
      int coptKoly2;
      int copterLoadedBombs;
      double copterDirection;
      double rotorCounter;
      int copterHealth;
      double rotorSpeed;
      double copterSpeedX;
      double copterSpeedY;
      boolean copterIsLanding;

      int carrierY;

      // control vars
      boolean gameStarted;
      int spaceKey;
      int shootCounter;
      int level;
      int lastLevel;
      String winText;

      // *** Locals end ***

      // *** Init vars ***
      random = new Random();

      frameGraphics = getGraphics();
      heatmapImage = new BufferedImage(SCREEN_WIDTH, SCREEN_HEIGHT, BufferedImage.TYPE_INT_ARGB);
      heatmapPixels = ((DataBufferInt) heatmapImage.getRaster().getDataBuffer()).getData();

      screenImage = new BufferedImage(SCREEN_WIDTH, SCREEN_HEIGHT, BufferedImage.TYPE_INT_RGB);
      screenPixels = ((DataBufferInt) screenImage.getRaster().getDataBuffer()).getData();
      screenImageG2D = (Graphics2D) screenImage.getGraphics();

      keyboardMap = new boolean[32767];

      shootData = new double[SHOOT_DATA_LENGTH * SHOOT_NUMBER];
      jetDoubleData = new double[ENM_DBL_DATA_LENGTH * ENM_NUMBER];
      towerDblData = new double[TOWER_NUMBER];

      heatMap1 = new int[HEATMAP_WIDTH * HEATMAP_HEIGHT];
      towerData = new int[TOWER_NUMBER * TOWER_DATA_LENGTH];
      mapData = new int[MAP_WIDTH * MAP_HEIGHT];
      fabData = new int[FAC_NUMBER * FAC_DATA_LENGTH];
      copterGfxData = new int[32 * 32 * 16];
      rotorGfxData = new int[32 * 32 * 16];
      jetGfxData = new int[32 * 32 * 16];
      jetIntData = new int[ENM_INT_DATA_LENGTH * ENM_NUMBER];
      heatMap2 = new int[HEATMAP_WIDTH * HEATMAP_HEIGHT];

      rotorSpeed = 0;
      rotorCounter = 0;

      bombWaitCounter = 1;

      winText = "";

      lastTime = System.nanoTime();
      lastLevel = 0;

      // *** init vars END

      // Label for restart
      restart: while (true)
      {

         carrierY = 20;
         dCopterX = CARRIER_X + 20;
         dCopterY = carrierY + 40;
         shootCounter = 0;
         spaceKey = 0;
         screenTopLeftX = 0;
         screenTopLeftY = 0;
         copterHealth = COPTER_INIT_HEALTH;
         copterLoadedBombs = COPTER_INIT_BOMBS;
         copterIsLanding = true;
         level = 1;

         copterDirection = 0;
         copterSpeedX = 0;
         copterSpeedY = 0.1;

         gameStarted = false;

         char[] copterBase = ("................................" + //
         "...............XX.X............." + //
         "...............XXXX............." + //
         "...............XX.X............." + //
         "...............XX..............." + //
         "...............XX..............." + //
         "...............XX..............." + //
         "...............XX..............." + //
         "..............XXXX.............." + //
         "..............XXXX.............." + //
         "..............XXXX.............." + //
         "..............XXXX.............." + //
         ".............XXXXXX............." + //
         ".............XXXXXX............." + //
         ".............XXXXXX............." + //
         ".........X...XXXXXX...X........." + //
         ".........XXXXXXOOXXXXXX........." + //
         ".........XXXXXXOOXXXXXX........." + //
         ".........X...XXXXXX...X........." + //
         ".............XXOOXX............." + //
         ".............XXOOXX............." + //
         ".............XXOOXX............." + //
         "..............XXXX.............." + //
         "..............XXXX.............." + //
         "...............XX..............." + //
         "...............XX..............." + //
         "................................" + //
         "................................" + //
         "................................" + //
         "................................" + //
         "................................" + //
         "................................").toCharArray();

         char[] jetBaseData = ("................................" + //
         "................................" + //
         "................................" + //
         "...........XXXXXXXXX............" + //
         "...........XXXXXXXXX............" + //
         ".............XXXXX.............." + //
         "..............XXX..............." + //
         "..............XXX..............." + //
         ".......XXXXXXXXXXXXXXXXX........" + //
         ".......XXXXXXXXXXXXXXXXX........" + //
         "........XXXXXXXXXXXXXXX........." + //
         "........XXXXXXXXXXXXXXX........." + //
         ".........XXXXXXXXXXXXX.........." + //
         "..........XXXXXXXXXXX..........." + //
         "............XXXXXXX............." + //
         ".............XXXXX.............." + //
         "..............XXX..............." + //
         "..............XXX..............." + //
         "..............XXX..............." + //
         "..............XXX..............." + //
         "..............XXX..............." + //
         "..............XXX..............." + //
         "..............XXX..............." + //
         "..............XXX..............." + //
         "..............XXX..............." + //
         "..............XXX..............." + //
         "...............X................" + //
         "................................" + //
         "................................" + //
         "................................" + //
         "................................" + //
         "................................").toCharArray();

         // *** INIT ***

         // precalc rotor.
         int[] rotorBaseData = new int[32 * 32];
         for (int y3 = 0; y3 < 32; y3++)
         {
            for (int x4 = 0; x4 < 32; x4++)
            {
               rotorBaseData[x4 + y3 * 32] = 0xff00ff;
               if ((x4 == 16 || y3 == 15) & (x4 > 4) & (x4 < 27) & (y3 > 4) & (y3 < 27))
               {
                  rotorBaseData[x4 + y3 * 32] = 0xff0000;
               }
            }
         }

         // rotate gfx
         int targetIndex = 0;
         int pixColCopter;
         int pixColJet;
         int pixColRotor;
         for (int d = 0; d < 16; d++)
         {
            double dir = d * Math.PI * 2 / 16.0f;

            double cos = Math.cos(dir);
            double sin = Math.sin(dir);

            for (int y1 = 0; y1 < 32; y1++)
            {
               for (int x1 = 0; x1 < 32; x1++)
               {
                  int sourceX = (int) (cos * (x1 - 16) + sin * (y1 - 16) + 16);
                  int sourceY = (int) (cos * (y1 - 16) - sin * (x1 - 16) + 16);

                  if (sourceX > 31 || sourceY > 31)
                  {
                     pixColCopter = 0xFF00FF;
                     pixColJet = 0xFF00FF;
                     pixColRotor = 0xFF00FF;
                  } else
                  {
                     int sourceIndex = (sourceX + sourceY * 32) & 1023;

                     // Helicopter
                     if (copterBase[sourceIndex] == '.')
                     {
                        pixColCopter = 0xFF00FF;
                     } else
                     {
                        if (copterBase[sourceIndex] == 'O')
                        {
                           pixColCopter = 0x888888;
                        } else
                        {
                           pixColCopter = 0xFFFFFF;
                        }
                     }

                     // Rotor
                     pixColRotor = rotorBaseData[sourceIndex];

                     // Jet
                     if (jetBaseData[sourceIndex] == '.')
                     {
                        pixColJet = 0xFF00FF;
                     } else
                     {
                        pixColJet = 0xFFFFFF;
                     }

                  }

                  copterGfxData[targetIndex] = pixColCopter;
                  rotorGfxData[targetIndex] = pixColRotor;
                  jetGfxData[targetIndex++] = pixColJet;

               }
            }
         }

         // ****** SPRITES END ***********

         // *** Generate map
         BufferedImage inselBI = new BufferedImage(1024, 512, BufferedImage.TYPE_INT_RGB);
         Graphics2D inselG2D = (Graphics2D) inselBI.getGraphics();
         int[] inselDataBuffer = ((DataBufferInt) inselBI.getRaster().getDataBuffer()).getData();

         random.setSeed(7);
         int fabCounter = 0;
         for (int mapX = 0; mapX < 2047; mapX += 1024)
         {
            for (int mapY = 0; mapY < 2047; mapY += 512)
            {

               // Generate island:
               // first fill with water
               inselG2D.setColor(new Color(WATER_COL));
               inselG2D.fillRect(0, 0, 1024, 512);

               // now the land. 500 50x50 circles
               inselG2D.setColor(new Color(0x444444));
               for (int i2 = 0; i2 < 500; i2++)
               {
                  inselG2D.fillOval((312 + random.nextInt(400 - 25)), (100 + random.nextInt(312 - 25)), 50, 50);
               }

               // every island has 2 factories and 2 defense towers
               for (int i1 = 0; i1 < 2; i1++)
               {
                  fabData[FAC_XPOS + fabCounter * FAC_DATA_LENGTH] = mapX + 340 + random.nextInt(340);
                  fabData[FAC_YPOS + fabCounter * FAC_DATA_LENGTH] = mapY + 128 + random.nextInt(250);
                  fabData[FAC_HEALTH + fabCounter * FAC_DATA_LENGTH] = FAC_HEALTH_START_VALUE;

                  towerData[TOWER_XPOS + fabCounter * TOWER_DATA_LENGTH] = mapX + 340 + random.nextInt(340);
                  towerData[TOWER_YPOS + fabCounter * TOWER_DATA_LENGTH] = mapY + 128 + random.nextInt(250);
                  towerData[fabCounter * TOWER_DATA_LENGTH] = TOWER_INIT_HEALTH;
                  towerDblData[fabCounter] = 0;

                  fabCounter++;
               }

               // put the island in the water
               int inselIndex = 0;
               for (int y4 = mapY; y4 < mapY + 512; y4++)
               {
                  for (int x3 = mapX; x3 < mapX + 1024; x3++)
                  {
                     if (inselDataBuffer[inselIndex] == 0xff444444)
                     {
                        int col1 = random.nextInt(20) + 50;
                        inselDataBuffer[inselIndex] = col1 | (col1 << 8) | (col1 << 16);
                     }
                     mapData[x3 + y4 * MAP_WIDTH] = inselDataBuffer[inselIndex];
                     inselIndex++;
                  }
               }
            }
         }
         // *** Map end

         // *** init enemys
         int dblIndex1 = 0;
         for (int intIndex1 = 0; intIndex1 < ENM_NUMBER * ENM_INT_DATA_LENGTH; intIndex1 += ENM_INT_DATA_LENGTH)
         {

            // set color
            if (intIndex1 < 24 * ENM_INT_DATA_LENGTH)
            {
               jetIntData[ENM_INT_COLOR + intIndex1] = 0xaaaaaa;
            } else
            {
               if (intIndex1 % 6 == 0)
               {
                  // Land camouflage
                  jetIntData[ENM_INT_COLOR + intIndex1] = 0x333333;
               } else
               {
                  if (intIndex1 % 6 == 1)
                  {
                     // Water comouflage
                     jetIntData[ENM_INT_COLOR + intIndex1] = 0x0000aa;
                  } else
                  {
                     jetIntData[ENM_INT_COLOR + intIndex1] = 0xaaaaaa;
                  }
               }
            }

            jetIntData[ENM_INT_FIRE_REPEAT + intIndex1] = random.nextInt(100);
            if (intIndex1 < 6 * ENM_INT_DATA_LENGTH)
            {
               jetIntData[intIndex1] = random.nextInt(5) + 5;
            } else
            {
               jetIntData[intIndex1] = 0;
            }
            jetIntData[ENM_INT_X_POS + intIndex1] = random.nextInt(2048);
            jetIntData[ENM_INT_Y_POS + intIndex1] = random.nextInt(2048);
            jetIntData[ENM_INT_ATTACK_STATUS + intIndex1] = 2;
            jetIntData[ENM_INT_CHANGE_DIRECTION + intIndex1] = random.nextInt(500) + 1;
            jetDoubleData[ENM_DBL_X_POS + dblIndex1] = (double) jetIntData[ENM_INT_X_POS + intIndex1];
            jetDoubleData[ENM_DBL_Y_POS + dblIndex1] = (double) jetIntData[ENM_INT_Y_POS + intIndex1];
            double dir = random.nextDouble() * 2 * Math.PI - Math.PI;
            jetDoubleData[dblIndex1] = dir;
            jetDoubleData[ENM_DBL_NEW_DIRECTION + dblIndex1] = dir;
            jetDoubleData[ENM_DBL_X_SPEED + dblIndex1] = Math.cos(dir) * 3.0d;
            jetDoubleData[ENM_DBL_Y_SPEED + dblIndex1] = Math.sin(dir) * 3.0d;
            dblIndex1 += ENM_DBL_DATA_LENGTH;
         }
         // *** enemy init end

         // *************************
         // *** main loop for the game
         // *************************
         while (true)
         {

            if (gameStarted)
            {
               // *** process input

               if (!copterIsLanding && rotorSpeed == 1)
               {
                  // steering
                  if (keyboardMap[KEY_LEFT])
                     copterSpeedX = copterSpeedX - COPTER_ACCL * 2;
                  if (keyboardMap[KEY_RIGHT])
                     copterSpeedX = copterSpeedX + COPTER_ACCL * 2;
                  if (keyboardMap[KEY_UP])
                     copterSpeedY = copterSpeedY - COPTER_ACCL * 2;
                  if (keyboardMap[KEY_DOWN])
                     copterSpeedY = copterSpeedY + COPTER_ACCL * 2;

                  // fire
                  if (keyboardMap[KEY_F])
                  {
                     shootCounter++;
                  } else
                  {
                     shootCounter = 0;
                  }
               }

               // Space
               spaceKey = 0;
               if (keyboardMap[KEY_SPACE])
               {
                  spaceKey++;
               }

               // slow down the helicopter
               copterSpeedX = (Math.abs(copterSpeedX) > 0.01f) ? (copterSpeedX > 0 ? copterSpeedX - COPTER_ACCL
                     : copterSpeedX + COPTER_ACCL) : 0;
               copterSpeedY = (Math.abs(copterSpeedY) > 0.01f) ? (copterSpeedY > 0 ? copterSpeedY - COPTER_ACCL
                     : copterSpeedY + COPTER_ACCL) : 0;

               // and not to fast...
               copterSpeedX = copterSpeedX > 4 ? 4 : (copterSpeedX < -4 ? -4 : copterSpeedX);
               copterSpeedY = copterSpeedY > 4 ? 4 : (copterSpeedY < -4 ? -4 : copterSpeedY);

               // calc the global position of the helicopter
               // is the helicopter on the carrier?
               if (!copterIsLanding && rotorSpeed == 1)
               {
                  // No:
                  dCopterX += copterSpeedX;
                  dCopterY += copterSpeedY;
               } else
               {
                  // yes: move with the carrier
                  dCopterY -= 1;
               }
               iCopterX = ((int) dCopterX) & 2047;
               iCopterY = ((int) dCopterY) & 2047;

               // top left corner in world coordinates
               screenTopLeftXOld = screenTopLeftX;
               screenTopLeftYOld = screenTopLeftY;
               screenTopLeftX = (((int) (dCopterX + copterSpeedX * 10)) - (SCREEN_WIDTH / 2)) & 2047;
               screenTopLeftY = (((int) (dCopterY + copterSpeedY * 10)) - (SCREEN_HEIGHT / 2)) & 2047;

               // is the helicopter moving?
               if (Math.abs((copterSpeedX + 0.1f) * (copterSpeedY + 0.1f)) > 0.03f)
               {
                  // yes: calc the direction
                  copterDirection = Math.atan2(copterSpeedY, copterSpeedX);
               }

               // take car of the bombs
               bombWaitCounter++;
               if ((keyboardMap[KEY_B]) && (bombWaitCounter > 50) && (copterSpeedX == 0)
                     && (copterSpeedY == 0) && (shootCounter == 0) && (copterLoadedBombs > 0))
               {
                  // drop a bomb
                  bombWaitCounter = 0;
                  copterLoadedBombs--;
               }

               // *** collision test Bullets/Jet/Helicopter
               coptKolx1 = (iCopterX - 10) & 2047;
               coptKoly1 = (iCopterY - 10) & 2047;
               coptKolx2 = coptKolx1 + 20;
               coptKoly2 = coptKoly1 + 20;

               boolean copterShootSlotFound = false;
               for (int i = 0; i < SHOOT_NUMBER * SHOOT_DATA_LENGTH; i += SHOOT_DATA_LENGTH)
               {

                  if (shootCounter % 5 == 1 && !copterShootSlotFound && i < 10 * SHOOT_DATA_LENGTH)
                  {
                     if (shootData[i] == 0)
                     {
                        shootData[SHOOT_X_POS + i] = iCopterX;
                        shootData[SHOOT_Y_POS + i] = iCopterY;
                        shootData[SHOOT_X_SPEED + i] = Math.cos(copterDirection) * 12;
                        shootData[SHOOT_Y_SPEED + i] = Math.sin(copterDirection) * 12;
                        shootData[i] = 40;
                        copterShootSlotFound = true;
                     }
                  }

                  if (shootData[i] > 0)
                  {

                     shootData[SHOOT_X_POS + i] += shootData[SHOOT_X_SPEED + i];
                     shootData[SHOOT_Y_POS + i] += shootData[SHOOT_Y_SPEED + i];
                     shootData[i]--;

                     if (shootData[i] < 1)
                     {
                        shootData[i] = 0;
                     }

                     int shootx1 = ((int) shootData[SHOOT_X_POS + i] - 1) & 2047;
                     int shooty1 = ((int) shootData[SHOOT_Y_POS + i] - 1) & 2047;
                     int shootx2 = shootx1 + 1;
                     int shooty2 = shooty1 + 1;

                     if (i < 10 * SHOOT_DATA_LENGTH)
                     {
                        for (int j = 0; j < ENM_NUMBER; j++)
                        {
                           if (jetIntData[j * ENM_INT_DATA_LENGTH] > 0)
                           {
                              int jetx1 = (jetIntData[ENM_INT_X_POS + j * ENM_INT_DATA_LENGTH] - 12) & 2047;
                              int jety1 = (jetIntData[ENM_INT_Y_POS + j * ENM_INT_DATA_LENGTH] - 14) & 2047;
                              if (jetx1 < shootx2 && shootx1 < (jetx1 + 26) && jety1 < shooty2
                                    && shooty1 < (jety1 + 26))
                              {
                                 shootData[i] = 0;
                                 jetIntData[j * ENM_INT_DATA_LENGTH]--;
                                 if (jetIntData[j * ENM_INT_DATA_LENGTH] == 0)
                                 {
                                    setExplosion(jetx1, jety1, 10, 10, 25);
                                 } else
                                 {
                                    setExplosion(shootx1, shooty1, 1, 10, 1);
                                    jetIntData[ENM_INT_CHANGE_DIRECTION + j * ENM_INT_DATA_LENGTH] = 1;
                                 }
                              }
                           }
                        }

                        if (!(shootData[i] == 0))
                        {
                           for (int k = 0; k < TOWER_NUMBER * TOWER_DATA_LENGTH; k += TOWER_DATA_LENGTH)
                           {
                              if (towerData[k] > 0)
                              {
                                 int twx1 = towerData[TOWER_XPOS + k];
                                 int twy1 = towerData[TOWER_YPOS + k];
                                 if (twx1 < shootx2 && shootx1 < (twx1 + 20) && twy1 < shooty2
                                       && shooty1 < (twy1 + 20))
                                 {
                                    shootData[i] = 0;
                                    towerData[k]--;
                                    if (towerData[k] == 0)
                                    {
                                       setExplosion(twx1, twy1, 10, 10, 25);
                                    } else
                                    {
                                       setExplosion(shootx1, shooty1, 1, 10, 1);
                                    }
                                 }
                              }
                           }
                        }
                     } else
                     {
                        if (coptKolx1 < shootx2 && shootx1 < coptKolx2 && coptKoly1 < shooty2
                              && shooty1 < coptKoly2)
                        {
                           shootData[i] = 0;

                           copterHealth--;
                           if (copterHealth == 0)
                           {
                              winText = "";
                              lastLevel = level;
                              continue restart;
                           }
                           setExplosion(shootx1 - 12, shooty1 - 12, 10, 10, 25);
                        }
                     }
                  }
               }
               // **** Collision test END

               // **** Drawing operations ****
               // the map
               int mapIndex2 = screenTopLeftX + screenTopLeftY * MAP_WIDTH;
               for (int y = 0; y < SCREEN_HEIGHT; y++)
               {
                  for (int x = 0; x < SCREEN_WIDTH; x++)
                  {
                     screenPixels[y * SCREEN_WIDTH + x] = mapData[mapIndex2 & (MAP_WIDTH * MAP_HEIGHT - 1)];
                     mapIndex2++;
                  }
                  mapIndex2 += (MAP_WIDTH - SCREEN_WIDTH);
               }

               // *** defense towers ***
               int doubleOffset = 0;
               for (int i = 0; i < TOWER_NUMBER * TOWER_DATA_LENGTH; i += TOWER_DATA_LENGTH)
               {

                  if (towerData[i] > 0)
                  {
                     towerDblData[doubleOffset] += 0.04f;
                     if (towerDblData[doubleOffset] > Math.PI)
                     {
                        towerDblData[doubleOffset] -= Math.PI * 2;
                     }

                     int xWert = towerData[i + TOWER_XPOS];
                     int yWert = towerData[i + TOWER_YPOS];
                     calcWorldToScreen(xWert, yWert);
                     screenImageG2D.setColor(new Color(0xcccccc, false));
                     screenImageG2D.fillOval(scrX, scrY, 20, 20);
                     screenImageG2D.setColor(new Color(0x0, false));
                     double xd = 15.0 * Math.cos(towerDblData[doubleOffset]);
                     double yd = 15.0 * Math.sin(towerDblData[doubleOffset]);
                     screenImageG2D.drawLine(scrX + 10, scrY + 10, scrX + 10 + (int) xd, scrY + 10 + (int) yd);
                     screenImageG2D.setColor(new Color(0xaaaaaaa, false));
                     screenImageG2D.fillOval(scrX + 5, scrY + 5, 10, 10);

                     if (towerData[i + TOWER_FIRE_REPEAT]-- < 0)
                     {
                        towerData[i + TOWER_FIRE_REPEAT] = 1;
                        int offset = (10 + ENM_NUMBER + i / TOWER_DATA_LENGTH) * SHOOT_DATA_LENGTH;
                        if (shootData[offset] == 0)
                        {
                           shootData[SHOOT_X_POS + offset] = towerData[i + TOWER_XPOS] + 10 + (int) xd;
                           shootData[SHOOT_Y_POS + offset] = towerData[i + TOWER_YPOS] + 10 + (int) yd;
                           shootData[SHOOT_X_SPEED + offset] = xd / 5.0f;
                           shootData[SHOOT_Y_SPEED + offset] = yd / 5.0f;
                           shootData[offset] = 100 + (5 * level);
                        }
                     }
                  }
                  doubleOffset++;
               }

               // Factories
               boolean allFactoriesDestroyed = true;
               for (int i = 0; i < FAC_NUMBER * FAC_DATA_LENGTH; i += FAC_DATA_LENGTH)
               {

                  if (fabData[FAC_HEALTH + i] > 0)
                  {
                     allFactoriesDestroyed = false;

                     int x = fabData[FAC_XPOS + i];
                     int y = fabData[FAC_YPOS + i];

                     if (bombWaitCounter == 0)
                     {
                        if ((iCopterX < x + 40) && (iCopterX > x) && (iCopterY < y + 40) && (iCopterY > y))
                        {
                           fabData[FAC_HEALTH + i] -= FAC_BOMB_DAMAGE;
                           setExplosion(x - 10, y - 10, 20, 20, 50);
                           if (fabData[FAC_HEALTH + i] <= 0)
                           {
                              // next level
                              level++;
                              for (int intIndex = 0; intIndex < ENM_NUMBER * ENM_INT_DATA_LENGTH; intIndex += ENM_INT_DATA_LENGTH)
                              {
                                 if (intIndex < 6 * level * ENM_INT_DATA_LENGTH)
                                 {
                                    jetIntData[intIndex] = random.nextInt(level) + 4;
                                 }
                              }
                              for (int k = 0; k < TOWER_NUMBER * TOWER_DATA_LENGTH; k += TOWER_DATA_LENGTH)
                              {
                                 towerData[k] = TOWER_INIT_HEALTH;
                              }
                           }
                        } else
                        {
                           setExplosion(iCopterX - 15, iCopterY - 15, 5, 5, 25);
                        }
                     }

                     calcWorldToScreen(x, y);
                     screenImageG2D.setColor(new Color(0x888888));
                     screenImageG2D.fillRect(scrX, scrY, 40, 40);

                  }
               }

               if (allFactoriesDestroyed)
               {
                  winText = "YOU HAVE WON!";
                  lastLevel = level;
                  continue restart;
               }

               // **** aircraft carrier ****
               carrierY = (carrierY - 1) & 2047;

               calcWorldToScreen(CARRIER_X, carrierY);
               screenImageG2D.setColor(new Color(0x444444));
               screenImageG2D.fillRect(scrX, scrY, 40, 90);
               if (testCollisionWithWraparound(coptKolx1, coptKoly1, coptKolx2, coptKoly2, CARRIER_X, carrierY,
                     CARRIER_X + 40, carrierY + 90))
               {
                  if (spaceKey == 1)
                     copterIsLanding = !copterIsLanding;
               }
               screenImageG2D.setColor(new Color(0xffffff));
               for (int i = 0; i < 8; i++)
               {
                  screenImageG2D.fillRect(scrX + 19, scrY + 2 + i * 11, 2, 7);
               }

               // *** Bullets on the heatmap ***
               for (int i = 0; i < SHOOT_NUMBER * SHOOT_DATA_LENGTH; i += SHOOT_DATA_LENGTH)
               {
                  if (shootData[i] > 0)
                  {

                     int hx = (((int) shootData[SHOOT_X_POS + i]) - screenTopLeftXOld + 96) & 2047;
                     int hy = (((int) shootData[SHOOT_Y_POS + i]) - screenTopLeftYOld + 128) & 2047;
                     for (int y = hy; y < hy + 3; y++)
                     {
                        for (int x = hx; x < hx + 3; x++)
                        {
                           // Clipping
                           if (x > -1 && x < HEATMAP_WIDTH && y > -1 && y < HEATMAP_HEIGHT)
                           {
                              heatMap1[x + y * HEATMAP_WIDTH] = 0x2ff + HEATMAP_COOLDOWN;
                           }
                        }
                     }

                  }
               }

               // *** Jets
               int shootIndex = 10 * SHOOT_DATA_LENGTH;
               int dblIndex = 0;
               for (int intIndex = 0; intIndex < ENM_NUMBER * ENM_INT_DATA_LENGTH; intIndex += ENM_INT_DATA_LENGTH)
               {
                  if (jetIntData[intIndex] > 0)
                  {
                     jetIntData[ENM_INT_CHANGE_DIRECTION + intIndex]--;

                     if (jetIntData[ENM_INT_CHANGE_DIRECTION + intIndex] < 1)
                     {
                        if (random.nextInt(20 - level) == 0)
                        {
                           jetIntData[ENM_INT_ATTACK_STATUS + intIndex] = 1;
                           jetIntData[ENM_INT_CHANGE_DIRECTION + intIndex] = random.nextInt((10 * 5)
                                 + (level * 5));
                        } else
                        {
                           jetIntData[ENM_INT_ATTACK_STATUS + intIndex] = 0;
                           jetDoubleData[ENM_DBL_NEW_DIRECTION + dblIndex] = random.nextDouble() * 2 * Math.PI
                                 - Math.PI;
                           ;
                           jetIntData[ENM_INT_CHANGE_DIRECTION + intIndex] = random.nextInt(10 * 50);
                        }
                     }

                     if (jetIntData[ENM_INT_ATTACK_STATUS + intIndex] == 1)
                     {
                        int xWert = ((iCopterX + MAP_CENTER_X - jetIntData[ENM_INT_X_POS + intIndex]) & 2047)
                              - MAP_CENTER_X;
                        int yWert = ((iCopterY + MAP_CENTER_Y - jetIntData[ENM_INT_Y_POS + intIndex]) & 2047)
                              - MAP_CENTER_Y;
                        jetDoubleData[ENM_DBL_NEW_DIRECTION + dblIndex] = Math.atan2(yWert, xWert);
                     }

                     if (jetDoubleData[ENM_DBL_NEW_DIRECTION + dblIndex] != //
                     jetDoubleData[dblIndex])
                     {
                        double diff = jetDoubleData[ENM_DBL_NEW_DIRECTION + dblIndex]
                              - jetDoubleData[dblIndex];
                        if (diff < -Math.PI)
                        {
                           diff += Math.PI * 2;
                        }
                        if (diff < 0.03 && diff > -0.03)
                        {
                           jetDoubleData[dblIndex] = jetDoubleData[ENM_DBL_NEW_DIRECTION
                                 + dblIndex];
                        } else
                        {
                           if (diff > 0)
                           {
                              jetDoubleData[dblIndex] += 0.05f;
                           } else
                           {
                              jetDoubleData[dblIndex] -= 0.05f;
                           }
                        }

                     }

                     jetDoubleData[ENM_DBL_X_SPEED + dblIndex] = //
                     Math.cos(jetDoubleData[dblIndex]) * 3;
                     jetDoubleData[ENM_DBL_Y_SPEED + dblIndex] = //
                     Math.sin(jetDoubleData[dblIndex]) * 3;
                     jetDoubleData[ENM_DBL_X_POS + dblIndex] += jetDoubleData[ENM_DBL_X_SPEED + dblIndex];
                     jetDoubleData[ENM_DBL_Y_POS + dblIndex] += jetDoubleData[ENM_DBL_Y_SPEED + dblIndex];
                     jetIntData[ENM_INT_X_POS + intIndex] = ((int) jetDoubleData[ENM_DBL_X_POS + dblIndex]) & 2047;
                     jetIntData[ENM_INT_Y_POS + intIndex] = ((int) jetDoubleData[ENM_DBL_Y_POS + dblIndex]) & 2047;

                     if (!copterIsLanding && rotorSpeed == 1)
                     {
                        if (jetIntData[ENM_INT_FIRE_REPEAT + intIndex]-- < 0)
                        {
                           jetIntData[ENM_INT_FIRE_REPEAT + intIndex] = random.nextInt(100 - (level * 5));
                           if (shootData[shootIndex] == 0)
                           {
                              shootData[SHOOT_X_POS + shootIndex] = jetIntData[ENM_INT_X_POS + intIndex];
                              shootData[SHOOT_Y_POS + shootIndex] = jetIntData[ENM_INT_Y_POS + intIndex];
                              shootData[SHOOT_X_SPEED + shootIndex] = jetDoubleData[ENM_DBL_X_SPEED
                                    + dblIndex] * 3;
                              shootData[SHOOT_Y_SPEED + shootIndex] = jetDoubleData[ENM_DBL_Y_SPEED
                                    + dblIndex] * 3;
                              shootData[shootIndex] = 100;
                           }
                        }
                     }

                     int jetOffset = (((int) (jetDoubleData[dblIndex] / (Math.PI * 2)
                           * 16 + 0.5f + 4 + 8)) & 15);
                     jetOffset = jetOffset * 32 * 32;

                     // draw jet
                     drawObject(jetIntData[ENM_INT_X_POS + intIndex], jetIntData[ENM_INT_Y_POS + intIndex],
                           jetOffset, jetGfxData, jetIntData[ENM_INT_COLOR + intIndex]);

                  }
                  shootIndex += SHOOT_DATA_LENGTH;
                  dblIndex += ENM_DBL_DATA_LENGTH;
               }
               // *** Jets END

               // **** do the heatmap stuff ****
               int xOffset = screenTopLeftX - screenTopLeftXOld;
               if (Math.abs(xOffset) > 100)
               {
                  if (screenTopLeftX < screenTopLeftXOld)
                  {
                     xOffset = screenTopLeftX + MAP_WIDTH - screenTopLeftXOld;
                  } else
                  {
                     xOffset = screenTopLeftX - (screenTopLeftXOld + MAP_WIDTH);
                  }
               }

               int yOffset = screenTopLeftY - screenTopLeftYOld;
               if (Math.abs(yOffset) > 100)
               {
                  if (screenTopLeftY < screenTopLeftYOld)
                  {
                     yOffset = screenTopLeftY + MAP_HEIGHT - screenTopLeftYOld;
                  } else
                  {
                     yOffset = screenTopLeftY - (screenTopLeftYOld + MAP_HEIGHT);
                  }
               }

               // cool down, copy to heatmap2 and scroll
               for (int hmY = 0; hmY < HEATMAP_HEIGHT; hmY++)
               {
                  for (int hmX = 0; hmX < HEATMAP_WIDTH; hmX++)
                  {
                     if ((hmX + xOffset < 0) || (hmX + xOffset >= HEATMAP_WIDTH) || (hmY + yOffset < 0)
                           || (hmY + yOffset >= HEATMAP_HEIGHT))
                     {
                        heatMap2[hmX + hmY * HEATMAP_WIDTH] = 0;
                     } else
                     {
                        int heatWert = heatMap1[hmX + xOffset + ((hmY + yOffset) * HEATMAP_WIDTH)]
                              - HEATMAP_COOLDOWN;
                        heatMap2[hmX + hmY * HEATMAP_WIDTH] = heatWert < 0 ? 0 : heatWert;
                     }
                  }
               }

               // calc heat values
               for (int i = 0; i < HEATMAP_LENGTH; i++)
               {
                  int heatSum = heatMap2[(i - 1) & 0x3ffff] +
                        heatMap2[(i + 1) & 0x3ffff] +
                        heatMap2[(i - HEATMAP_WIDTH + 1) & 0x3ffff] +
                        heatMap2[(i - HEATMAP_WIDTH) & 0x3ffff] +
                        heatMap2[(i - HEATMAP_WIDTH - 1) & 0x3ffff] +
                        heatMap2[(i + HEATMAP_WIDTH + 1) & 0x3ffff] +
                        heatMap2[(i + HEATMAP_WIDTH) & 0x3ffff] +
                        heatMap2[(i + HEATMAP_WIDTH - 1) & 0x3ffff];
                  heatMap1[i] = (heatSum / 16) + (heatMap2[i] / 2);
               }

               // map heat values to color values
               int exPixIndex = 0;
               for (int hY = 128; hY < SCREEN_HEIGHT + 128; hY++)
               {
                  for (int hX = 96; hX < SCREEN_WIDTH + 96; hX++)
                  {
                     int heatWert = heatMap1[hX + hY * HEATMAP_WIDTH];
                     int transparanz = 0xff;
                     int heatCol = (heatWert - 512) + 0xffff00;
                     if (heatWert < 256)
                     {
                        heatCol = heatWert << 16;
                        transparanz = heatWert;
                     } else if (heatWert < 512)
                     {
                        heatCol = ((heatWert - 256) << 8) + 0xff0000;
                     }
                     heatmapPixels[exPixIndex] = heatCol + (transparanz << 24);
                     exPixIndex++;
                  }
               }
               // Draw the heatmap
               screenImageG2D.drawImage(heatmapImage, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, SCREEN_WIDTH,
                     SCREEN_HEIGHT, null);
               // **** heatmap stuff END ****

               // **** draw radar ****

               // 1. draw transparent map
               int screenIndex = 185 * SCREEN_WIDTH + 120;
               int mapIndex = screenTopLeftX - SCREEN_WIDTH + (screenTopLeftY - SCREEN_HEIGHT) * 2048;
               for (int sy = 0; sy < 64; sy++)
               {
                  for (int sx = 0; sx < 80; sx++)
                  {
                     int color = mapData[mapIndex & (MAP_WIDTH * MAP_HEIGHT - 1)];
                     if (color != WATER_COL)
                     {
                        color = 0x00555555;
                     }
                     if (sy == 0 || sy == 63 || sx == 0 || sx == 79)
                     {
                        color = 0;
                     }
                     int aktCol = screenPixels[screenIndex];
                     int rotNeu = (((aktCol & 0xff0000) >> 1) + ((color & 0xff0000) >> 1)) & 0xff0000;
                     int gruNeu = (((aktCol & 0x00ff00) >> 1) + ((color & 0x00ff00) >> 1)) & 0x00ff00;
                     int bluNeu = (((aktCol & 0x0000ff) >> 1) + ((color & 0x0000ff) >> 1)) & 0x0000ff;
                     screenPixels[screenIndex] = (rotNeu | gruNeu | bluNeu) & 0xffffff;
                     screenIndex++;
                     mapIndex += 12;
                  }
                  screenIndex += SCREEN_WIDTH - 80;
                  mapIndex = mapIndex + 2048 - (12 * 80) + 11 * 2048;
               }

               // 2. draw defense towers
               for (int i = 0; i < TOWER_NUMBER * TOWER_DATA_LENGTH; i += TOWER_DATA_LENGTH)
               {
                  if (towerData[i] > 0)
                  {
                     drawRadar(towerData[i + TOWER_XPOS] + 20, towerData[i + TOWER_YPOS] + 20, 0xffff00, false);
                  }
               }

               // 3. draw factories
               for (int i = 0; i < FAC_NUMBER * FAC_DATA_LENGTH; i += FAC_DATA_LENGTH)
               {
                  if (fabData[FAC_HEALTH + i] > 0)
                  {
                     drawRadar(fabData[i + FAC_XPOS] + 20, fabData[i + FAC_YPOS] + 20, 0x0, true);
                  }
               }

               // 4. draw carrier
               drawRadar(CARRIER_X + 20, carrierY + 45, 0x555555, true);

               // 5. draw jets
               for (int jetIndex = 0; jetIndex < ENM_NUMBER * ENM_INT_DATA_LENGTH; jetIndex += ENM_INT_DATA_LENGTH)
               {
                  if (jetIntData[jetIndex] > 0)
                  {
                     drawRadar(jetIntData[jetIndex + ENM_INT_X_POS], jetIntData[jetIndex + ENM_INT_Y_POS],
                           0xffffff, false);
                  }
               }

               // 6. last but not least the copter
               drawRadar(iCopterX, iCopterY, 0xff0000, false);

               // **** Radar END ****

               // Text stuff
               screenImageG2D.setColor(new Color(0xffffff));
               int letzteZeile = 14;
               screenImageG2D.drawString("Level: " + level, 4, letzteZeile-- * 16 + 8);
               screenImageG2D.drawString("Bombs: " + copterLoadedBombs, 4, letzteZeile-- * 16 + 8);
               screenImageG2D.drawString("Health: " + copterHealth, 4, letzteZeile-- * 16 + 8);
            }

            if (!gameStarted)
            {
               screenImageG2D.clearRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
            }

            // draw the helicopter
            int copterOffset = (((int) (copterDirection / (Math.PI * 2) * 16 + 0.5f + 4 + 8)) & 15);
            copterOffset = copterOffset * 32 * 32;
            drawObject(iCopterX, iCopterY, copterOffset, copterGfxData, -1);

            // rotor speed
            if (copterIsLanding)
            {
               rotorSpeed -= ROTOR_ACCL;
               if (rotorSpeed < 0)
               {
                  rotorSpeed = 0;
                  copterLoadedBombs = COPTER_INIT_BOMBS;
                  copterHealth = COPTER_INIT_HEALTH;

               }
               if (!gameStarted)
               {
                  rotorSpeed = 1;
               }
            } else
            {
               rotorSpeed += ROTOR_ACCL;
               if (rotorSpeed > 1)
                  rotorSpeed = 1;
            }
            rotorCounter = rotorCounter + rotorSpeed;
            // draw the rotor
            int rotorOffset = (((int) rotorCounter) % 4) * 32 * 32;
            drawObject(iCopterX, iCopterY, rotorOffset, rotorGfxData, 0xff0000);

            // Intro
            if (!gameStarted)
            {
               iCopterX = 157;
               iCopterY = 131;
               copterDirection = -1.5f;
               screenImageG2D.setColor(new Color(0xffffff));
               screenImageG2D.drawString("Raid on Java 4K", 114, 108);
               screenImageG2D.drawString(winText, 115, 80);
               screenImageG2D.drawString("Last Level " + lastLevel, 125, 165);
               if (keyboardMap[KEY_ENTER])
               {
                  gameStarted = true;
               }
            }

            frameGraphics.drawImage(screenImage, 0, 0, SCREEN_WIDTH * 2, SCREEN_HEIGHT * 2, 0, 0, SCREEN_WIDTH,
                  SCREEN_HEIGHT, null);

            do
            {
               Thread.yield();
            } while (System.nanoTime() - lastTime < 0);
            lastTime += (1000000000 / 50);

            if (!isActive())
               return;
         }
      }
   }

   /**
    * radar: sets a small or big dot
    * 
    * @param x
    * @param y
    * @param color
    * @param bigPixel
    */
   private void drawRadar(int x, int y, int color, boolean bigPixel)
   {
      int radarScrX = ((x - screenTopLeftX + SCREEN_WIDTH) & 2047) / 12 + 120;
      int radarScrY = ((y - screenTopLeftY + SCREEN_HEIGHT) & 2047) / 12 + 185;
      // clipping
      if (radarScrX > 119 && radarScrX < 120 + 79 && radarScrY > 184 && radarScrY < 185 + 63)
      {
         int screenIndex = radarScrX + radarScrY * SCREEN_WIDTH;
         screenPixels[screenIndex] = color;
         if (bigPixel)
         {
            screenPixels[screenIndex + 1] = color;
            screenPixels[screenIndex + SCREEN_WIDTH] = color;
            screenPixels[screenIndex + SCREEN_WIDTH + 1] = color;
         }
      }
   }

   /**
    * draw an 32x32 Object
    * 
    * @param x
    * @param y
    * @param offset
    *            - Startpoint in the gfxData
    * @param gfxData
    * @param color
    */
   private void drawObject(int x, int y, int offset, int[] gfxData, int color)
   {
      for (int worldY = y; worldY < y + 32; worldY++)
      {
         int screenY = (worldY - screenTopLeftY - 18) & 2047;
         for (int worldX = x; worldX < x + 32; worldX++)
         {
            int screenX = (worldX - screenTopLeftX - 16) & 2047;
            if (screenX > -1 && screenX < SCREEN_WIDTH && screenY > -1 && screenY < SCREEN_HEIGHT)
            {
               if (gfxData[offset] != 0xFF00FF)
               {
                  if (color == -1)
                  {
                     color = gfxData[offset];
                  }
                  screenPixels[screenX + screenY * SCREEN_WIDTH] = color;
               }
            }
            offset++;
         }
      }
   }

   private boolean testCollisionWithWraparound(int q1x1, int q1y1, int q1x2, int q1y2, int q2x1, int q2y1, int q2x2,
         int q2y2)
   {
      if (testCollision(q1x1, q1y1, q1x2, q1y2, q2x1, q2y1, q2x2, q2y2))
      {
         return true;
      }
      if (testCollision(q1x1 - MAP_WIDTH, q1y1, q1x2 - MAP_WIDTH, q1y2, q2x1, q2y1, q2x2, q2y2))
      {
         return true;
      }
      if (testCollision(q1x1, q1y1 - MAP_HEIGHT, q1x2, q1y2 - MAP_HEIGHT, q2x1, q2y1, q2x2, q2y2))
      {
         return true;
      }
      if (testCollision(q1x1 - MAP_WIDTH, q1y1 - MAP_HEIGHT, q1x2 - MAP_WIDTH, q1y2 - MAP_HEIGHT, q2x1, q2y1, q2x2,
            q2y2))
      {
         return true;
      }
      if (testCollision(q1x1 + MAP_WIDTH, q1y1, q1x2 + MAP_WIDTH, q1y2, q2x1, q2y1, q2x2, q2y2))
      {
         return true;
      }
      if (testCollision(q1x1, q1y1 + MAP_HEIGHT, q1x2, q1y2 + MAP_HEIGHT, q2x1, q2y1, q2x2, q2y2))
      {
         return true;
      }
      if (testCollision(q1x1 + MAP_WIDTH, q1y1 + MAP_HEIGHT, q1x2 + MAP_WIDTH, q1y2 + MAP_HEIGHT, q2x1, q2y1, q2x2,
            q2y2))
      {
         return true;
      }
      return false;
   }

   private boolean testCollision(int q1x1, int q1y1, int q1x2, int q1y2, int q2x1, int q2y1, int q2x2, int q2y2)
   {
      return !(q1x2 < q2x1 || q1x1 > q2x2 || q1y1 > q2y2 || q1y2 < q2y1);
   }

   private void calcWorldToScreen(int x, int y)
   {
      scrX = x - screenTopLeftX;
      if (screenTopLeftX + SCREEN_WIDTH > MAP_WIDTH)
      {
         if (scrX < -MAP_WIDTH / 2)
         {
            scrX += MAP_WIDTH;
         }
      } else
      {
         if (scrX > MAP_WIDTH / 2)
         {
            scrX -= MAP_WIDTH;
         }
      }
      scrY = y - screenTopLeftY;
      if (screenTopLeftY + SCREEN_HEIGHT > MAP_HEIGHT)
      {
         if (scrY < -MAP_HEIGHT / 2)
         {
            scrY += MAP_HEIGHT;
         }
      } else
      {
         if (scrY > MAP_HEIGHT / 2)
         {
            scrY -= MAP_HEIGHT;
         }
      }
   }

   private void setExplosion(int screenX, int screenY, int number, int blocksize, int verteilung)
   {
      int hx = (screenX - screenTopLeftXOld + 96) & 2047;
      int hy = (screenY - screenTopLeftYOld + 128) & 2047;
      for (int j2 = 0; j2 < number; j2++)
      {
         int x = random.nextInt(verteilung);
         int y = random.nextInt(verteilung);
         for (int y2 = hy + y; y2 < hy + y + blocksize; y2++)
         {
            for (int x2 = hx + x; x2 < hx + x + blocksize; x2++)
            {
               if (x2 > -1 && x2 < HEATMAP_WIDTH && y2 > -1 && y2 < HEATMAP_HEIGHT)
               {
                  heatMap1[x2 + y2 * HEATMAP_WIDTH] = 0x2ff + HEATMAP_COOLDOWN;
               }
            }
         }
      }
   }

   @Override
   public boolean handleEvent(Event e)
   {
      // System.out.println(e.key);
      return keyboardMap[e.key] = (e.id == Event.KEY_PRESS || e.id == Event.KEY_ACTION);
   }
}





Dump your java code here :



Special syntax:
  • To highlight a line (yellow background), prefix it with '@@'
  • To indicate that a line should be removed (red background), prefix it with '-'
  • To indicate that a line should be added (green background), prefix it with '+'
  • To post multiple snippets, seperate them by '~~~~'
  EOF
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (78 views)
2014-04-15 18:08:23

BurntPizza (69 views)
2014-04-15 03:46:01

UprightPath (81 views)
2014-04-14 17:39:50

UprightPath (66 views)
2014-04-14 17:35:47

Porlus (82 views)
2014-04-14 15:48:38

tom_mai78101 (106 views)
2014-04-10 04:04:31

BurntPizza (165 views)
2014-04-08 23:06:04

tom_mai78101 (262 views)
2014-04-05 13:34:39

trollwarrior1 (211 views)
2014-04-04 12:06:45

CJLetsGame (221 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!