import com.sun.kjava.*; public class Warp extends Spotlet implements Runnable{ Bitmap flag = new Bitmap(new short[] { 9, 13, 2, 0, 0, 0, 0, 0, -4096, -17408, -16768, -16512, -16512, -16640, -20992, -24576, -24576, -24576, -24576, -24576, -8192 }); short blockdata[]={ -1, -2049, -1, -17, -2049, -1, 22365, -1, // Fading intro grid -2049, -1, -2049, -1, 22365, -3089, -2049, -1025, -2049, -3089, -2049, -3089, -2049, 8872, 22365, -3089, // Intro grid -2049, -3089, -2049, -3089, 22365, -3089, -2049, -3089 }; short mapblocks[]={ // Used for building backgrounds 1, 10923, 21845, 10923, 21845, 10923, 21845, 10923, // 0, empty square 21845, 10923, 21845, 10923, 21845, 10923, 21845, -1, 1, -32765, 16389, 8207, 20501, 2111, 21589, 767, // 1, pyramid 21845, 1023, 22485, 4095, 24565, 16383, 32765, -1, 5855, 12283, 22005, 10923, 21845, 10923, 21845, 10923, // 2, pyramid shadow 21845, 10923, 21845, 10923, 21845, 10923, 21845, -1, 6193, 26575, 24565, -17413, -22533, 26621, 32757, 32681, // 3, glass sphere 32597, 32425, -16557, -16725, 23895, 26511, 22591, -1, 2045, 10987, 21845, 10923, 21845, 10923, 21845, 10923, // 4, sphere shadow 21845, 10923, 21845, 10923, 21845, 10923, 21845, -1, 6321, 32639, 24509, -20485, -18441, 32765, -1, -1, // 5, exploded sphere 32767, 32749, -16393, -20485, 24575, 32479, 22839, -1, 1, 10923, 21845, 16379, 24565, 15027, 23893, 15027, // 6, hatch 23893, 15027, 23893, 16371, 20485, 10923, 21845, -1, -21846, 21845, -21846, 21845, -21846, 21845, -21846, 21845, // 7, water -21846, 21845, -21846, 21845, -21846, 21845, -21846, 21845, -22486, 16405, -32726, 53, -31638, 597, 8427, 1025, // 8, leaf 129, 65, -32509, 3, -16250, 24589, -18374, 22517, -22486, 16397, -32762, 3, -31742, 513, 41, 769, // 9, leaf 2 3649, 13569, -5613, 21507, -22010, 21517, -22470, 22517, -22518, 17733, -30046, 5137, -23928, 21828, 10914, 17748, // 10, rings 10914, 17748, 8874, 4421, -30680, 17745, -23902, 20501, -21846, 5189, -30070, 19669, 9922, 1629, -32198, 17013, // 11, grass -32216, 22785, -5057, 16407, 2118, 6771, -17606, 22493, -16646, 30549, -21846, 23925, -21846, 21845, -21846, 21845, // 12, shadow -21846, 21845, -21846, 21845, -21846, 21845, -21846, 21845, -21846, 17493, -20830, 21591, -21846, 30021, 10922, 21852, // 13, exploded -21842, 13653, -5462, 20596, -17730, 30173, -23894, 19765, -21782, 20541, -24562, 16391, -32474, -32685, 53, -32741, // 14, rock -32483, -32577, -24081, 21215, -6658, 29695, -16390, 24575, -17746, 22525, -21526, 21845, -21846, 21845, -21846, 21845, // 15, shadow -21846, 21845, -21846, 21845, -21846, 21845, -21846, 21845, -21846, 0, -21846, 0, -21846, 0, -21846, 0, // 16, sand -21846, 0, -21846, 0, -21846, 0, -21846, 0, -20502, 8184, -17730, 28692, -5462, -8188, -21847, -16382, // 17, hole 27305, -32768, -21847, 16384, -23904, 4096, -24574, 1312, -22486, 24, -32116, 16390, 2730, 5, -21845, 1, // 18, pile -21845, 16387, -21841, 24583, -9554, 29757, -16390, 22516, -21846, 5456, -21846, 320, -21846, 0, -21846, 0, // 19, shadow -21846, 0, -21846, 0, -21846, 0, -21846, 0, -21846, 272, 10922, 24324, 15018, 12289, -21853, 20673, // 20, blown up -21622, 18176, -21863, 119, -22486, 17429, -22342, 21972, -20502, 6168, -24530, 16390, -16373, -32767, -32765, -32767, // 21, rock -32757, -32767, -32757, 16407, -6102, 29021, -17734, 6133, -21846, 1364, -21846, 336, -21846, 0, -21846, 0, // 22, shadow -21846, 0, -21846, 0, -21846, 0, -21846, 0, -5446, -26548, -14710, 25356, -24422, 6301, -19424, 24577, // 23, plant -32237, -29619, -1978, 22725, -22298, 4565, -19542, 7429, -16706, 17219, -32314, -31411, -29762, -27123, -13306, 30727, // 24, gravel -18422, 9309, -14538, 17378, -13629, 26455, -16658, 21812 }; Bitmap life = new Bitmap(new short[] { // Life indicator 15, 15, 2, 0, 0, 0, 0, 0, 4032, 4400, 8462, 16642, 16670, -31788, -31532, -31276, -30764, -31788, 16670, 20802, 11182, 5488, 4032}); Bitmap warplogo = new Bitmap(new short[] { // File src\bitmaps\warplogo.bmp; size: 120x61 (compressed) // header 120, 61, 16, -32768, 0, 0, 0, 0, // bits 674, -1, -32768, 2047, -4096, 255, 0, 0, 63, -256, 21504, 4064, 1029, -18946, 21887, -14932, -448, 2722, -30059, 16511, 30538, -31585, -30206, -22018, -28635, 3218, 8336, 16375, -876, 4479, 6788, 16638, 9544, 12580, -31450, -28689, -1983, 17918, 9257, -27138, 18947, 19776, 10408, 10239, -3686, -28417, -935, 18946, -512, -11184, 2377, 18755, -4097, 29995, -1887, 31678, -257, -16969, -1870, -19945, 28668, 17393, 3071, -130, -1, -380, -1975, 27901, -24592, 26398, -935, -733, 32761, 1536, 25102, 7, -384, 63, -1901, -311, 28145, 32448, 23553, 11791, 10239, 4223, -7524, 21957, 7252, 8698, -13654, -22543, 20289, 32709, 30867, -32712, -24690, -1326, 32399, -8169, 8319, -32015, 9993, 28799, -19970, -13057, 5057, 8190, 16511, 1506, 20240, 25087, 22522, -28162, 1922, 24405, 32011, -15044, 8898, 3070, 3068, 900, -16392, -24065, -469, -30120, 1473, -433, -17865, 1809, 32591, -4, 1812, -18345, -31748, 22270, 2040, -29147, 16352, -27649, -1968, 305, 20264, 20814, -496, -24258, -21806, 279, -16, 1044, 25182, 4098, 23806, 16386, 31818, 0, 12159, -22463, -6756, 8196, -17154, -32763, -1910, -8107, 8191, -8190, -26683, 15439, -6024, -321, 27641, 21130, -21889, -63, -19291, -32136, -16432, 29182, 32661, -3435, 5205, -1, -31157, 3844, -3969, -31006, -769, -22304, 9298, -26626, 2228, -18687, -7745, -27524, 5061, 23487, -16385, 11083, 24069, -15617, 1477, 31791, -26497, -1, -1, 19020, 973, -493, -160, -123, 32388, -28585, -24580, 9072, -454, -129, 15137, 2047, -1977, 224, 0, 16882, -476, 19055, 7712, -27145, -934, -28001, -420, 24032, -22506, -23557, -1883, 1407, -8004, -24352, 10788, -28673, -1750, 21695, -32705, 30810, -8120, -30417, -16, 21673, 32257, 16120, -24384, 4944, -30, 21835, 31760, 8177, 5344, 11393, 24575, -2646, -19716, 703, -7640, -8125, 10815, -1, -1, -2044, 24517, -26656, -1, -241, -28225, -30137, 15, 2687, 5525, 15, 9663, 9536, 15, -25730, -726, 31, -947, -1, 20608, 32537, -329, -22272, 6655, -48, -32705, 449, -32641, 470, -32737, 1407, -16256, 32541, -412, -43, -32737, 7679, 127, -16384, 3346, -16497, -32641, 3492, 7952, -32577, 3498, -16609, -32641, 4052, 17400, 128, -241, -14176, 47, -32641, 3569, 17488, -32513, 4070, 3028, 3840, 4088, 23080, -18688, 4094, -23214, 24320, 4095, -9555, -256, 1786, -20736 }); // Various data for drawing mobile bitmap objects static final int sX[]={0,19,38,57,73,89, 105,105, 114,126,114,146,142,126, 0,19,38,57,73,89,105,89, 105,105, 124,142, 135,68,89,0,18,35,51,67,113,0,16,30,44,57,81, 50,68,91,0,18,37,55,70,55,70,0,25,138,116, 110,142,124,106,88}; static final int sY[]={0,0,0,0,0,0, 0,6, 0,0,12,18,0,16, 19,20,17,14,16,14,24,30, 16,20, 36,36, 54,47,46,39,39,37,37,32,44,57,57,57,53,53,32, 64,69,66,93,93,92,88,88,104,104,72,72,72,74, 56,88,90,90,85}; static final int sW[]={19,19,19,16,16,16, 9,9, 12,16,12,14,18,20, 19,19,19,16,16,16,19,16, 9,9, 18,18, 25,21,21,18,17,16,15,14,11,16,14,14,13,11,8, 18,19,19,18,19,18,15,16,16,15,25,25,22,22, 18,18,18,18,18}; static final int sH[]={18,19,17,14,16,14, 10,10, 12,16,12,14,18,20, 20,20,20,16,16,16,20,16, 4,4, 18,18, 18,22,20,18,18,16,15,15,12,15,15,13,11,11,9, 19,19,19,21,23,25,16,16,16,16,21,20,16,16, 18,18,18,18,18}; static final int sdX[]={9,9,9,8,8,8, 5,5, 6,8,6,7,9,10, 9,9,9,8,8,8,9,8, 5,5, 9,9, 9,8,8,9,9,8,8,7,6,8,8,7,7,6,5, 9,10,10,9,9,9,8,9,9,8,12,12,11,11, 9,9,9,9,9}; static final int sdY[]={9,9,7,8,8,6, 5,5, 6,8,6,7,9,10, 9,9,9,8,8,8,9,8, 2,2, 9,9, 5,11,10,9,9,8,7,7,6,8,8,7,6,6,5, 9,9,9,9,9,9,8,8,8,8,9,9,8,8, 9,9,9,9,9}; static Graphics g = Graphics.getGraphics(); static Button exitButton = new Button("Exit", 138, 146); static java.util.Random random = new java.util.Random(); static final String credits1="By Karl",credits2="H\u00f6rnell"; static final String gameOver="GAME OVER"; static short screenShort1[]=new short[1448],screenShort2[]=new short[1448]; static Bitmap screen1,screen2; static short sh; // Information pertaining to levels, attack waves and certain enemies static final int levBlocks[]={1,3,6, 8,9,10,11,14, 17,18,21,23,24}; static final int levBlockStart[]={0,3,8},levBlockNum[]={3,5,5},levBackground[]={0,7,16}; static final int blockProperty[]={0,2,0,1,0,0,0, 0,0,0,0,1,0,0,2,0, 0,0,1,0,0,2,0,0,0}; static final boolean hasShadow[]={false,true,false,true,false,false,false, false,false,false,false,true,false,false,true,false, false,false,true,false,false,true,false,false,false}; static final int levEnemies[]={0,0,7,10,0,0,14,15,0,0,16,17}; static final int waveTypes[]={0,1,0,0, 1,2,0,0, 2,1,3,0}; static final int toKill[]={5,5,0,0, 6,5,0,0, 5,7,5,0}; static final int waveShipLook[]={24,24,24,25,25,55,56,56,56,57,58,59}; static final int duckLook[]={43,41,42,41,44,45,46,46,46,45,44}; static int map[]=new int[21*16]; static Warp warpGame; static boolean initiated=false; static Thread game; static StringBuffer scoreBuf=new StringBuffer(14); static long nextTime=System.currentTimeMillis(),nowTime; static int toDraw[]=new int[25],numDraw; static int toMask[]=new int[60],numMask; static int i,j,k,l,m,n,dir,wantDir,fire,lastDir,counter,dsi; static int scX1,scX2,scY,baseX,updateBase,updateScan; static int fBullets,enemies,eBullets; static int wave,killed; static int fBulNum[]=new int[3],fBulCount,blockList[]=new int[10],blockNum,backBlock; static int enNum[]=new int[5],enCount,collNum[]=new int[10],collCount; static int andX[]=new int[20],andY[]=new int[20],andT[]=new int[20],ands; static int orX[]=new int[20],orY[]=new int[20],orT[]=new int[20],ors; static int xorX[]=new int[20],xorY[]=new int[20],xorT[]=new int[20],xors; static int gameMode=99,lives,score,newscore,level; static int oDir[]=new int[10],oPos[]=new int[10],oX[]=new int[10], oY[]=new int[10],oType[]=new int[10],oExtra[]=new int[10]; static int expPos[]=new int[8],expA,expB; static int blockQ[]=new int[10],blockPos[]=new int[10],blockStore[]=new int[10]; public static void main(String[] args) { scoreBuf.append("SCORE: "); warpGame=new Warp(); warpGame.register(WANT_SYSTEM_KEYS); game=new Thread(warpGame); game.start(); } public void prepareIntro() { if (!initiated) { screenShort1[0]=(short)160; screenShort1[1]=(short)80; screenShort1[2]=(short)20; screenShort2[0]=(short)160; screenShort2[1]=(short)80; screenShort2[2]=(short)20; screen1=new Bitmap(screenShort1); screen2=new Bitmap(screenShort2); initiated=true; // I have to define part of the graphics data here due to a bug in // the KVM Bitmap ships = new Bitmap(new short[] { // File src\bitmaps\ships.bmp; size: 160x120 (compressed) // header 160, 120, 20, -32768, 0, 0, 0, 0, // bits 2173, -253, -4096, 32256, 4032, 31999, 4092, 20476, 20352, 2018, -4033, -14340, 8191, 3084, 393, -32719, 12403, -1037, -4029, -4029, 960, 28867, -16377, -205, -3582, 2112, -16113, 19710, 20448, 16833, -3969, -15376, 8067, 3, -4276, 19972, 14599, -15888, -189, -16320, 16951, -31, -31680, -32017, 28739, -14327, 2271, -16133, 16448, 18306, 29945, -24720, -29181, -32274, -16320, 18686, 2515, -5305, -32268, -2817, -16, -2, 4065, 32071, -12226, -25077, 496, -2942, 13443, 28924, 8160, -2687, -2832, 17935, 4787, 13428, -32263, -24784, 16368, -8814, 13390, -26105, 703, 29940, -16313, -32735, -30976, -8318, 29790, -25855, 7970, -8204, -31792, 16384, 963, 255, -23820, -12162, -26303, 459, -8969, -28187, 22400, 247, 19447, -11714, -27297, -11781, -1980, 18394, -4345, -7184, 8076, 8160, -175, -1976, -30471, 27583, -4613, 22480, -16281, -1220, -912, -32753, -15873, 27991, -13800, 2207, -4998, -1025, -6827, -1697, 12300, 12289, 511, 15103, -6998, -17307, 31869, -209, -3349, -993, -32, 1264, 16322, 3, -16577, -6563, 31807, -911, -1181, -673, -4077, -16378, 20679, 1983, 8163, -21508, 4064, 24823, -15874, 4088, -8192, 1008, -2017, -8177, -17649, 511, -8000, 16636, 754, 968, 3712, -3904, 1016, -18, 1022, 192, 12400, -2048, -6649, -10240, -12288, 359, 24560, 16128, 16456, 508, -7844, 1265, -7840, -12281, -8189, -10483, 11390, -8116, 25343, 4544, 1410, 4127, -8190, -8161, -1824, -239, 25089, -15999, 8250, 4845, 4737, -7406, -250, -4033, -960, 511, 8385, 576, 16736, 562, -205, -32240, 561, 32752, 3312, 32766, 0, -192, 644, -16157, -14459, 25279, 28946, -32144, -24580, 15376, -8065, 139, -32622, 2113, 511, -6910, 12545, -7169, -32, 8193, -1151, -7864, 178, 19392, -254, -32144, -16379, -10239, 24768, -1, -1310, 4560, 15482, -14856, 5617, -6820, 5936, 192, -110, 4848, 16906, 2499, -5895, -13368, 738, -28816, 28926, 8192, -12366, 13150, 1935, -3074, 30680, 4086, 22456, -3696, 32513, -8222, 28998, 11520, 6141, -273, -1901, -337, -17651, -24513, 24831, -32283, 28750, 7536, 24448, -256, 29271, -20478, -13819, -3472, -912, 2047, 16386, -452, -21366, 16128, 26236, -16385, -15376, 8184, 31759, 32277, -5888, 23769, 24439, 7806, 12480, 8995, -4089, -8000, 254, 10443, -13567, -902, -16805, -6799, -7637, 25536, -32767, -461, 30663, 4728, 16380, -255, 9678, 30234, -41, 29632, -8185, -483, -4218, 19192, 8184, -16894, -28780, 3034, 11712, -993, -497, -253, -26640, 2016, -24820, -121, -17569, 32752, -4093, -4040, -249, -511, -32, 32256, -34, 5279, -32698, 14581, -3872, 1991, -24337, 504, 193, -28925, -27905, -27647, 19968, 22216, 1008, -4094, 3976, 16543, 1016, 532, -31470, 32670, 32383, -20776, 5620, -4092, 7967, -6, 3078, 774, 1738, -8308, 9524, 23258, -21697, -3847, -472, 8440, 4577, 1145, 2751, -12800, 30398, -1, -304, 10, 8699, 8976, -30556, -30028, -28739, 18304, 29162, -16388, -3854, 4138, -24065, 17296, -28444, -27505, 13312, -9919, -6896, 2041, -4064, 8231, -7891, 20564, 143, -192, 7936, 12331, -32768, -15888, 8768, 8193, -2173, 4192, -23409, 10770, -8253, 3125, 22016, 289, 12335, -21762, -24096, 26744, 18964, -21793, -32544, 31975, -999, 10736, 25120, 6271, -1408, 96, 106, -14853, -28701, -8, 17189, 15600, -3248, 2112, -1119, -8088, 30830, -15470, -15441, -16060, -272, 938, 2016, -3197, 4192, -23360, -119, 12035, -4112, -1538, 160, -189, -28592, -7065, -28730, 153, 20476, 1984, -4091, 8001, 20527, -12061, -127, -3685, -28674, 3941, 9456, 815, -19777, -221, 4248, -23360, 32512, 219, 4067, -8417, 14639, -3872, 22479, -10241, 12769, -25479, -8193, -27905, -26065, -1025, 496, -3413, -3393, -196, 1807, 1951, -750, -1633, 11194, 28, 6624, -4096, 28672, 253, 16382, 1023, 8186, -3625, 12159, -32256, 1216, 16568, -3809, -2048, -799, -217, 16387, -31927, 10224, 8048, -2049, -16129, -2033, -1985, -7180, -28892, -16400, 59, 28095, -12345, -4095, 29696, 14591, -7229, -7217, -31436, 32, -256, 26916, -8193, -80, 16208, 1028, -3130, 8645, 10127, 9467, -2195, -18433, 8000, 4208, 1682, 19639, -30841, 9786, 4833, -213, -1, -497, -512, 8304, 30427, 30805, 8226, 10993, -9425, -7172, 1799, -24336, 191, -64, -17146, 1313, 9165, -1761, -2045, -1016, 16496, -1024, 255, 17344, 17345, 15, -27905, 2883, 6271, 16502, -512, 0, 291, -16384, -15601, -16081, -32672, 3968, -189, -16317, -15739, 8195, 283, -793, 8193, 28703, -8, -2298, 8197, 8752, 1543, -24625, -32705, 39, -7920, -333, -30841, 8964, 159, -4209, 24960, 10273, 4351, 21281, 9992, -1825, 28643, -28257, 25112, 13584, -337, -14651, -7184, 2308, -192, 8160, 6432, -24022, -22000, -1797, -7229, -7217, -241, -32001, 8232, 4115, -4013, 8191, 28687, -32768, -3336, 4088, 16147, -1232, -12232, 6768, -19135, 24583, 255, 24, 0, 7680, 8706, 32656, -9196, 16459, -4182, 28735, -3073, 19236, 8483, 1023, 12560, 3084, 24683, -651, 3, 4994, 32512, 2054, 28748, 4088, -8065, -1, 24446, 28480, -17009, -31748, 12815, -31739, -3988, 8435, 24551, 20608, -15735, 1789, 29200, 17412, 8396, -3936, 16320, 24449, 16513, 16520, -913, -2010, 8076, 1056, -8144, -16447, 28547, -16256, -16252, 10462, -3272, 517, 7168, -8112, 16355, 24519, 8193, 16646, 2024, -6608, 13856, -20432, -32385, -225, 760, 12290, -31997, 511, -30176, 9729, 8632, 2048, -4016, 28674, -31745, 24581, 1551, -32388, 511, -4403, 14398, -24456, 3312, -24352, 321, -192, 642, 995, -64, 16383, -13832, 11776, -12240, 4064, -4001, -16256, -16151, -32511, -32319, 237, 3216, 23679, -1800, -20225, -32448, 22530, 192, -5880, -12356, 2032, -3969, -12160, -15624, -24319, -31360, 29684, 2034, -1800, -16144, 16383, -16129, -5409, -32257, 16256, -3840, 16368, -7940, -24321, -7730, 1987, 5112, 125, 2016, -15354, 255, 11, 4609, -3847, 8180, 3227, -516, 28867, -16321, -4858, -3, 3312, -7944, 32744, 7332, -21968, -113, -768, 3968, 0, 24768, -241, -14228, 0, 16129, -16, -16258, 71, 399, -1401, -30716, 1008, 22000, 8304, 2595, 18183, 16321, -28449, 18304, 3337, -769, -28976, 8162, 25079, 2040, 510, -16319, -1793, 8967, -16367, 1584, 524, -4086, -15361, -7681, 6152, 1538, 385, -9928, 31496, 8225, 252, 2224, 0, 24831, 12347, 3086, -16128, 9248, 26492, 4131, 17016, -4033, 257, -20225, 8196, -30719, 8828, 5168, -8397, -25455, 5796, 16768, -3888, -25342, 6399, 20354, -27680, -23934, 5432, -221, 6168, -29265, -14272, 464, 4193, 6911, 20546, -27632, -23559, 2552, -719, 4112, -15363, 18434, 28673, 433, -641, 8479, -14270, 14736, -154, -25572, -16216, 1093, -23952, 810, -7507, 18193, 17425, -28673, -15108, 5361, 22019, 27633, -4079, 27647, -6733, -32096, -30583, -15617, -29112, 11516, 1984, -224, -3878, -8704, 27519, 12768, -29630, 14601, -7965, 31847, -9172, 2288, 16264, 2613, -185, 8657, -14269, -1655, -3841, 8185, 31744, 32, 648, -12278, -14741, -129, 12767, -13214, -31979, -797, 16352, 15615, 19696, 195, -41, -176, 25300, 6322, 32276, 13287, -4160, -975, 430, -4065, -7222, -16385, 20418, -11280, -20204, 9508, -6377, -32752, 14379, -16, 8304, 0, -222, -31544, -24263, -32280, 32486, 2878, 2110, 21952, -16260, -208, 15820, 3960, 16509, 20039, 16640, 0, -16384, 255, 6159, -15869, -1985, -888, -8183, -892, 247, 4095, -15873, 2047, -29504, 3356, 57, -32641, -3890, -16376, 2048, -24313, 190, -24564, -15360, -12031, -449, -31520, 6428, -31744, -8448, 31, -8189, -637, -7951, -828, 27, 3968, -1600, -8029, 16776, 31, 0, 497, -15136, 831, 2048, 1792, 484, -8137, -30192, 1, -2848, 4032, -3072, 506, -8185, -8132, 0 }); g.drawBitmap(0,0,ships); g.copyOffScreenRegion(0,0,160,160,0,0,Graphics.OVERWRITE, Graphics.ONSCREEN_WINDOW,Graphics.OFFSCREEN_WINDOW); g.clearScreen(); } // Prepare the intro grid background screenShort1[1]=(short)80; screenShort2[1]=(short)80; l=8; for (i=0;i<16;i++) { sh=blockdata[i]; k=l; l+=10; for (j=k;j>1]; blockNum=levBlockNum[level>>1]; for (i=0;i>1]+i]; gameMode=3; } else // Even levels have attack waves { wave=2*level-4; killed=0; gameMode=4; } counter=0; g.drawString(level+"",126,147,Graphics.PLAIN); } public void run() { while(true) { counter++; nowTime=System.currentTimeMillis(); if (nowTime0) prepareGame(); break; case 2: // Leaving intro scroll(2); handleObjects(); if (oType[0]==1) { if (oX[0]>16) oX[0]--; if (oX[0]==16 && oY[0]==72) { oType[0]=0; addObject(3,16,72,0); } } if (scY>0) { scY--; screenShort1[1]=(short)(144-scY); screenShort2[1]=screenShort1[1]; } i=8+90*(scX1&14); if (scX1>=-144 && scX1<16) // Draw on screen 2 { i+=(14-scX1)>>4; j=i+180; for (k=i;k>4; j=i+180; for (k=i;k63) fixLevelVariables(); break; case 3: // Odd level, scrolling background scroll(2); handleObjects(); if ((scX1&14)==14) // Time for a map update, prepare new vertical block line { updateScan=0; i=((baseX+176)&0xff0)%320; l=i>>4; if (l<10) l+=8; else l+=2046; map[i]=1; updateBase=i+1; if (counter>56 && counter<450) { // Here is where we distribute random blocks for (k=0;k<9;k++) blockStore[k]=backBlock; k=0; while (k<2) { i=random.nextInt()&0xffff; j=i%9; m=blockList[(i>>>4)%blockNum]; if (blockStore[j]==backBlock || (blockProperty[m]>0 && blockProperty[blockStore[j]]==0)) { k++; blockStore[j]=m; if (hasShadow[blockStore[j]] && blockStore[j+1]==backBlock) blockStore[j+1]=blockStore[j]+1; } } j=0; for (k=0;k<9;k++) { if (map[updateBase+k]!=blockStore[k]) { blockPos[j]=l; blockQ[j++]=blockStore[k]<<4; } map[updateBase+k]=blockStore[k]; l+=160; } } else { k=l; j=0; for (i=0;i<9;i++) { if (map[updateBase+i]!=backBlock) { blockPos[j]=k; blockQ[j++]=backBlock<<4; } map[updateBase+i]=backBlock; k+=160; } } while (j<10) blockQ[j++]=-1; map[updateBase+9]=1; if (blockQ[8]>=0) { i=blockQ[8]; blockQ[8]=-1; j=blockPos[8]; if (j<2048) // Screen 1 { for (k=0;k<16;k++) { screenShort1[j]=mapblocks[i++]; j+=10; } } else { j&=2047; for (k=0;k<16;k++) { screenShort2[j]=mapblocks[i++]; j+=10; } } } } else if (expA!=expB) // Handle possible explosions { newscore+=10; i=expPos[expA]; if (blockProperty[map[i]]>0) map[i]+=2; k=map[i]<<4; if (i<160) // On screen 1 { j=8+((i-1)&15)*160+(i>>4); for (i=0;i<16;i++) { screenShort1[j]=mapblocks[k++]; j+=10; } } else // On screen 2 { j=8+((i-1)&15)*160+((i-160)>>4); for (i=0;i<16;i++) { screenShort2[j]=mapblocks[k++]; j+=10; } } expA=(expA+1)&7; } else if ((scX1&14)==8) { i=random.nextInt(); j=(i>>>4)%9; if (enemies<2 && (i&4)==0 && counter>32 && blockProperty[blockStore[j]]==0) { addObject(levEnemies[level*2+((i>>>8)&1)],176,8+16*j,0); enemies++; } } if (blockQ[updateScan]<0) { updateScan=0; if (counter>520 && (scX1&14)==0) // Switch to next level -- attack wave { level++; fixLevelVariables(); } } else { i=blockQ[updateScan]; blockQ[updateScan]=-1; j=blockPos[updateScan++]; if (j<2048) // Screen 1 { for (k=0;k<16;k++) { screenShort1[j]=mapblocks[i++]; j+=10; } } else { j&=2047; for (k=0;k<16;k++) { screenShort2[j]=mapblocks[i++]; j+=10; } } } break; case 4: // Even level, attack waves scroll(2); if (counter<169) { // Background updates basically consist of drawing black pixels i=8+90*(scX1&14); if (scX1>=-144 && scX1<16) // Draw on screen 2 { i+=(14-scX1)>>4; j=i+180; for (k=i;k>4; j=i+180; for (k=i;k40 && enemies+killed50) gameMode=99; break; default: // Just started prepareIntro(); break; } if (gameMode<9) { g.drawBitmap(scX1,scY,screen1); g.drawBitmap(scX2,scY,screen2); } drawObjects(); if (newscore!=score) drawScore(); } } public void scroll(int s) { scX1-=s; scX2-=s; if (scX1<-159) scX1+=320; if (scX2<-159) scX2+=320; baseX=160-scX2; } public void handleObjects() // Take care of all mobile objects, including ship { fBulCount=0;enCount=0;collCount=0; for (i=0;i<10;i++) switch(oType[i]) { case 1: // Demo ship k=random.nextInt(); if ((k&28)==0 && fBullets<2 && gameMode==1) { addObject(2,oX[i]+8,oY[i],0); fBullets++; } if ((k&112)==0 && gameMode==1) oDir[i]=83+3*(k&15); if (oY[i]oDir[i]) { oY[i]-=oExtra[i]; addAnd(i,5); addOr(i,2); } else { addAnd(i,4); addOr(i,1); } break; case 2: // Demo bullet oX[i]+=8; if ((counter&1)==0) addAnd(i,6); else addXor(i,7); if (oX[i]>160) { oType[i]=0; fBullets--; } break; case 3: // Main ship oPos[i]=(oPos[i]+2)%320; if (fire>0 && fBullets<2) { fire=0; addObject(4,oX[i]+8,oY[i],0); fBullets++; g.playSound(Graphics.SOUND_CLICK); } if (oDir[i]==2) { oY[i]+=4; addAnd(i,3); addOr(i,0); } else if (oDir[i]==1) { oY[i]-=4; addAnd(i,5); addOr(i,2); } else { addAnd(i,4); addOr(i,1); } if ((oY[i]&15)==8) { if (wantDir==1 && oY[i]>8) oDir[i]=1; else if (wantDir==2 && oY[i]<136) oDir[i]=2; else oDir[i]=0; wantDir=0; } if (blockProperty[map[(oPos[i]&0xff0)+1+(oY[i]>>4)]]>0) destroyShip(); break; case 4: // Real bullet oX[i]+=8; oPos[i]=(oPos[i]+10)%320; if ((counter&1)==0) addAnd(i,6); else addXor(i,7); if (oX[i]>159) { oType[i]=0; fBullets--; } else { k=oPos[i]&0xff0; j=k+1+((oY[i]-6)>>4); k+=1+((oY[i]+6)>>4); m=blockProperty[map[j]]; n=blockProperty[map[k]]; if (m==2 || n==2) { oType[i]=5; oExtra[i]=8; g.playSound(Graphics.SOUND_CLICK); } else if (m==1) { oType[i]=6; oExtra[i]=10; expPos[expB]=j; expB=(expB+1)&7; g.playSound(Graphics.SOUND_INFO); } else if (n==1) { oType[i]=6; oExtra[i]=10; expPos[expB]=k; expB=(expB+1)&7; g.playSound(Graphics.SOUND_INFO); } else fBulNum[fBulCount++]=i; } break; case 5: // Stopped bullet oX[i]-=2; addAnd(i,oExtra[i]); oExtra[i]++; if (oExtra[i]>9) { oType[i]=0; fBullets--; } break; case 6: // Big explosion oX[i]-=2; addAnd(i,oExtra[i]); oExtra[i]++; if (oExtra[i]>13) { oType[i]=0; fBullets--; } break; case 7: // Rotator oX[i]-=2; if ((oPos[i]&15)==8 && (oY[i]&15)==8) { j=(oPos[i]&0xff0)+1+(oY[i]>>4); k=(j+304)%320; if (blockProperty[map[k]]==0) oDir[i]=3; else if (oDir[i]==0 || oDir[i]==3) oDir[i]=1+((counter&8)>>3); if ((oDir[i]==1 && blockProperty[map[j-1]]>0) || (oDir[i]==2 && blockProperty[map[j+1]]>0)) oDir[i]=0; } if (oDir[i]==3) { oX[i]-=2; oPos[i]=(oPos[i]+318)%320; } else if (oDir[i]==1) oY[i]-=2; else if (oDir[i]==2) oY[i]+=2; addOr(i,14+(counter%3)); addAnd(i,17+(counter%3)); standardEnemyStuff(i); break; case 8: // Part of exploding ship oX[i]+=oDir[i]; oY[i]+=oPos[i]; addAnd(i,oExtra[i]); if ((counter&1)==0) oExtra[i]++; if (oExtra[i]>13) oType[i]=9; break; case 9: // Countdown after death oExtra[i]++; if (oExtra[i]>40) gameMode=9; break; case 10: // Tank oX[i]-=2; if ((oY[i]&15)==8) { j=(oPos[i]&0xff0)+1+(oY[i]>>4); if (oDir[i]==0) oDir[i]=1+((counter&8)>>3); if ((oDir[i]==1 && blockProperty[map[j-1]]>0) || (oDir[i]==2 && blockProperty[map[j+1]]>0)) oDir[i]=0; } if (oDir[i]==1) oY[i]-=2; else if (oDir[i]==2) oY[i]+=2; if (eBullets<1 && oY[0]-oY[i]<16 && oY[i]-oY[0]<16) { eBullets++; addObject(11,oX[i]-8,oY[i],1); g.playSound(Graphics.SOUND_CLICK); } addOr(i,20); addAnd(i,21); standardEnemyStuff(i); break; case 11: // Enemy bullet oX[i]-=8; oPos[i]=(oPos[i]+314)%320; if ((counter&1)==0) addAnd(i,22); else addXor(i,23); if (oX[i]<0) { oType[i]=0; eBullets--; } else { if (blockProperty[map[(oPos[i]&0xff0)+1+(oY[i]>>4)]]>0) { oType[i]=12; oExtra[i]=8; g.playSound(Graphics.SOUND_CLICK); } else collNum[collCount++]=i; } break; case 12: // Stopped enemy bullet oX[i]-=2; addAnd(i,oExtra[i]); oExtra[i]++; if (oExtra[i]>9) { oType[i]=0; eBullets--; } break; case 13: // Wave ship oX[i]-=2; switch(oExtra[i]) { case 0: oX[i]--; break; case 1: if (oDir[i]==0) oDir[i]=1+((counter&32)>>5); oY[i]+=(oDir[i]<<3)-12; if (oY[i]<8 || oY[i]>136) oDir[i]=3-oDir[i]; break; case 2: if (eBullets<1 && oY[0]-oY[i]<16 && oY[i]-oY[0]<16) { eBullets++; addObject(11,oX[i]-8,oY[i],1); g.playSound(Graphics.SOUND_CLICK); } break; case 3: if ((oY[i]&14)==8) { oDir[i]=0; for (j=0;j<2;j++) { k=fBulNum[j]; if (oType[k]==4 && oX[k]>4)]!=backBlock) oY[i]=8+(((random.nextInt()&0xffff)%9)<<4); else oExtra[i]=1; } else { if (oExtra[i]<6) j=34-oExtra[i]; else if (oExtra[i]>12) j=16+oExtra[i]; else j=29; addOr(i,j); addAnd(i,j+6); oExtra[i]++; if (oExtra[i]>18) { oExtra[i]=0; oY[i]=152; } enNum[enCount++]=i; collNum[collCount++]=i; } if (oX[i]<-12) { oType[i]=0; enemies--; } break; case 16: // Seagull oX[i]-=2; if (oDir[i]==0) { oY[i]-=5; addOr(i,51); addAnd(i,53); if (oY[i]<-10) oDir[i]=1; } else { oY[i]+=5; addOr(i,52); addAnd(i,54); if (oY[i]>154) oDir[i]=0; } standardEnemyStuff(i); break; case 17: // Duck if (oExtra[i]==0) { oX[i]-=4; oPos[i]=(oPos[i]+318)%320; j=duckLook[counter&3]; addOr(i,j); addAnd(i,j+6); } else { oX[i]-=6; oPos[i]=(oPos[i]+316)%320; oExtra[i]--; j=duckLook[oExtra[i]+3]; addOr(i,j); j+=6; if (j>50) j=50; addAnd(i,j); } if ((oPos[i]&15)==8 && oExtra[i]==0) { j=(oPos[i]&0xff0)+1+(oY[i]>>4); k=(j+304)%320; if (blockProperty[map[k]]>0 || blockProperty[map[j]]>0) oExtra[i]=8; } standardEnemyStuff(i); break; default: break; } // Check for bullet-enemy collisions for (i=0;i>4)&7)-4; } g.playSound(Graphics.SOUND_CLICK); } public void addAnd(int n, int look) { andX[ands]=oX[n]; andY[ands]=oY[n]; andT[ands++]=look; } public void addOr(int n, int look) { orX[ors]=oX[n]; orY[ors]=oY[n]; orT[ors++]=look; } public void addXor(int n, int look) { xorX[xors]=oX[n]; xorY[xors]=oY[n]; xorT[xors++]=look; } // Routine that ANDs, ORs and XORs bitmap data from the offscreen buffer to the visible // screen, after the background has been drawn. public void drawObjects() { i=0; while (i144) m=144-k; g.copyOffScreenRegion(sX[l],sY[l],sW[l],m,j,k,Graphics.OR, Graphics.OFFSCREEN_WINDOW,Graphics.ONSCREEN_WINDOW); } i=0; while (i144) m=144-k; g.copyOffScreenRegion(sX[l],sY[l],sW[l],m,j,k,Graphics.AND, Graphics.OFFSCREEN_WINDOW,Graphics.ONSCREEN_WINDOW); } i=0; while (i144) m=144-k; g.copyOffScreenRegion(sX[l],sY[l],sW[l],m,j,k,Graphics.XOR, Graphics.OFFSCREEN_WINDOW,Graphics.ONSCREEN_WINDOW); } } public void addObject(int t, int x, int y, int e) { dsi=0; while (oType[dsi]!=0) dsi++; oType[dsi]=t; oX[dsi]=x; oY[dsi]=y; oDir[dsi]=0; oExtra[dsi]=e; oPos[dsi]=((baseX+x)&0xfff)%320; } public void keyDown(int k) { // Set the variables "wantDir" and "fire" according to the pressed key // They will be read by the main game loop switch(k) { case PAGEUP: // Up wantDir=1; break; case PAGEDOWN: // Down wantDir=2; break; case KEY_HARD1: // Fire case KEY_HARD2: case KEY_HARD3: case KEY_HARD4: fire=1; break; default: break; } } public void penDown(int x, int y) { if (exitButton.pressed(x,y)) System.exit(0); } }