⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jmps.java

📁 一个j2me的滑雪游戏
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
 
// http://www2.r-force.co.jp/iapp/java/047/
// http://www2.r-force.co.jp/iapp/java/JMP/

//import com.nttdocomo.io.*;
//import com.nttdocomo.ui.*;

import java.io.*;
import java.util.Random;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.rms.*;

import com.nokia.mid.ui.*;
import com.nokia.mid.sound.*;


/**
 * Contains the main game engine.
 *
 * @author <a href="mailto:xp@livingmobile.net">Xavier Palau</a>
 * @version $Revision: 1.16.2.9.2.7 $
 * @changed $Author: xavier $ $Date: 2003/06/24 12:13:27 $
 */
public class JMPS extends FullCanvas
{
  private static JMP main;
  private static final String STORE_NAME = "skijumping_high";
  
  boolean isPaused = false;
  boolean helpFirstScreen = true;
  boolean pausedForHelp = false;
  public boolean visible = true;
  boolean paint_lock = false;
  
  private Sound theme;      
  private Sound wincup;
  private Sound wingame;
  private Sound lost;
      
  private	static byte buf[];
  private	static DataOutputStream out;
  private	static DataInputStream in;

//	private final static int KL = ( 1 << KEY_1 | 1 << KEY_4 | 1 << KEY_7 | 1 << KEY_LEFT );// KL 65682
//	private final static int KR = ( 1 << KEY_3 | 1 << KEY_6 | 1 << KEY_9 | 1 << KEY_RIGHT );// KR 262728
//	private final static int KU = ( 1 << KEY_2 | 1 << KEY_UP );// KU 131076
//	private final static int KD = ( 1 << KEY_8 | 1 << KEY_DOWN );// KD 524544
//	private final static int KC = ( 1 << KEY_5 | 1 << KEY_SELECT );// KC Com[4]
//	private final static int SL = ( 1 << KEY_SOFT1 );// SL:2097152
//	private final static int SR = ( 1 << KEY_SOFT2 );// SR:4194304

  private static int BASELINE = Graphics.BASELINE;
  private static int LEFT_TOP = Graphics.LEFT | Graphics.TOP;
  private static int CENTER_TOP = Graphics.HCENTER | Graphics.TOP;

	private static Font 	 NF;	
	private static Random  R;
  private static String[]	names = {"Ogawa","Steve","Ritva","Maria","Sven","Mika","Daniela","Max"};
  private static String[]	strCommon = null;
  private static String[]	strSpecific = null;
  private String strTemp;

  // -100 = menu ; -1 = loading ; 0 = title ;
  // 100 = choose country ; 200 = cup, opponents
  // 300 = game intro ; 350 = choose wind
  // {400, 500, 600, 700} = descent, jump, balance, landing
  // 800 = jump results ; 850 = ranking
  // 888 = get supporters' applause ;  900 = win (cup)
  // {350, 400, 500, 600, 650, 700} = Tutorial
  // 950 = continue?
  // 1000 = scores
  // {998, 999, 1200} = game cleared
	private static int GM;
  private static int GM_old = -1000;
  private int progmax;
  private int progress;
  //private int counter = 0;
  //int[] colors = { 255,223,191,159,127,95,63,31,0,31,63,95,127,159,191,223 };

  private static Image[] I;
  private static Image startImage;

	private static int 	nSel;
	private static int 	ResCnt;
	private static int 	nStage;
	private static int 	Frame;
	private static int 	LineX, LineY, LineOY;//, RedLine;
	private static int	nScroll;
	private static int 	CVY;
	private static int	Pow;
	private static int	Wind, WindPow, WindTime, WindUD, WindLR, WindLRPow;
  private static int[]	nScore = {0,0,0,0,0,0,0,0,0,0,0,0,0}; //new int[4 + 8]; // +1:cumulate
  private static int	totalScore = 0;
	private static int	Kaisuu;
	private static int	Kyori, Hikyori, Hikei, RedPoint;
	private static int 	FirstKyori, HowTo;
	private static int	PXY, JX, OffJP;
	private static int	fClear;

	private static int[] 	Scr;
	private static int[] 	C;
	private static int[] 	Key;
	private static int[] 	WCur;	
	private static int[]	Head;
	private static int[] 	VSList;
	private static int[] 	icList;
	private static int[]	CupTime;
	private static int[]	CpuScore;
	private static int[]	Meter;
	private static int[]	Power; // MaxPower
	private static int[]	WindSpeed;
	private static int[]	Ending;
	private static int[]	Temp;

	//private static byte	  Pallete[][];
	//private static byte 	header[][];
	//private static byte 	img[][];

	private static boolean[] 	GF;


//------------------------------------------------------------------------------

  public JMPS()
  {
    System.gc();
  	Scr = new int[3];
  	C = new int[6];
  	Key = new int[4];
  	WCur = new int[6];
  	Head = new int[16];
  	VSList = new int[8];
  	CupTime = new int[11];
  	CpuScore = new int[60];
  	Meter = new int[12];
  	Power = new int[8];
  	WindSpeed = new int[24];
  	Ending = new int[9];
  	Temp = new int[11];
  	GF = new boolean[19];	

    Scr[0] = ( getWidth() - 120) / 2;
    Scr[1] = ( getHeight() - 120) / 2;

  	C[0] = 16777215; // Util.getColorOfRGB(255, 255, 255); // white
	  C[1] = 16754225; // Util.getColorOfRGB(255, 166,  49); // light orange
	  C[2] = 11913983; // Util.getColorOfRGB(181, 202, 255); // "ice" blue
	  C[3] = 16736063; // Util.getColorOfRGB(255,  95,  63); // red
	  C[4] = 16727903; // Util.getColorOfRGB(255,  63,  95); // red2
    
    // softkeys
    SOFTKEY_HEIGHT = 14;
    SOFTKEY_TOPLINE = getColorOfRGB(0,0,0);
    SOFTKEY_BACKGROUND = getColorOfRGB(255,255,255);
    SOFTKEY_FOREGROUND = getColorOfRGB(0,0,0);
    SOFTKEY_TEXTAREA = getColorOfRGB(200, 222, 255);
    setSoftButtonsMargin(4, 4);

    main = (JMP) JMP.getCurrentApp();

    strCommon = main.txt.getBundle("strCommon");
    strSpecific = main.txt.getBundle("strSpecific");
    
    NF = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL);

	  GM = -10;
	  R = new Random( new java.util.Date().getTime() );
  }


//------------------------------------------------------------------------------

	public void initAll()
	{		
    int i;
		GF[1] = true;

		try
		{
      System.gc();
      
      // init sound        
      theme   = new Sound(readResource("/sounds/theme.ott"), Sound.FORMAT_TONE);
      wincup  = new Sound(readResource("/sounds/wincup.ott"), Sound.FORMAT_TONE);
      wingame = new Sound(readResource("/sounds/wingame.ott"), Sound.FORMAT_TONE);
      lost    = new Sound(readResource("/sounds/lost.ott"), Sound.FORMAT_TONE);
            
      in = new DataInputStream( getClass().getResourceAsStream("JMP.spf") );

      // loading bar...
      GM = -1;
      progmax = 4 * (10 + 2 + 2); // flags + start image + misc
      progress = 0;

      // initialize image array
			I = new Image[48];
      for (i=0; i<48; i++) I[i] = null;
			
      // load flags
			for (i=0; i<10; i++) {
        I[i] = Image.createImage("/images/img" + i + ".png");
        //System.out.println("Loaded img[" + i + "] to I[" + i + "]");
        loadProgress(4*1);
			  System.gc();
			}
			
      // load start image
      startImage = Image.createImage("/images/start.png");
      loadProgress(4*2);

			// Load game variables initial values (146 bytes)
			for (i = 0; i<6 ; i++) WCur[i] = in.readByte();
			for (i = 0; i<11; i++) CupTime[i] = in.readByte();
			for (i = 0; i<60; i++) CpuScore[i] = in.readByte();
			for (i = 0; i<16; i++) Head[i] = in.readByte();
			for (i = 0; i<12; i++) Meter[i] = in.readByte();
			for (i = 0; i<8 ; i++) Power[i] = in.readByte();
			for (i = 0; i<24; i++) WindSpeed[i] = in.readByte();
			for (i = 0; i<9 ; i++) Ending[i] = in.readByte();

      loadProgress(4*1);
			in.close();

      // Read scores

      RecordStore highscore = null;
      try {
        highscore = RecordStore.openRecordStore(STORE_NAME, false);
        for (i = 0; i < nScore.length; i++)
          nScore[i] = Integer.parseInt(new String(highscore.getRecord(i+1)));
      }
      catch (Exception e) {}
      finally {
        if (highscore != null) {
          try { highscore.closeRecordStore(); }
          catch (Exception e) {}
        }
      }
      loadProgress(4*1);
		}
		catch(Exception e) { }

		notifyTitle();
    playsound(theme);
	}



//------------------------------------------------------------------------------

  // loads imga.png to imgb.png(included) set of images (incr: loading bar)
	public void LoadGraph(int a, int b, int incr)
	{
		try {
			for (int i=a; i<=b; i++) {
				System.gc();
        if(I[i] == null) {
          I[i] = Image.createImage("/images/img" + i + ".png");
          //System.out.println("Loaded (Graph) img[" + i + "] to I[" + i + "]");
        }
        loadProgress(incr);
			}
		} catch(Exception e) {}
	}

/*
    // UNloads imga.png to imgb.png(included) set of images
	public void unLoadGraph(int a, int b)
	{		
		try {
			for (int i=a; i<=b; i++) {				
        I[i] = null;
        //System.out.println("Unloaded img[" + i + "]);
			}
		} catch(Exception e) {}
    System.gc();
	}
*/

  public void ChangeTeamGraph()
  {
    // added v 1.0.2
    I[45] = null;
    I[46] = null;
    I[47] = null;
    System.gc();
    try {
      I[45] = Image.createImage("/images/img" + (48+VSList[0]) + ".png");
      I[46] = Image.createImage("/images/img" + (56+VSList[0]*2) + ".png");
      I[47] = Image.createImage("/images/img" + (57+VSList[0]*2) + ".png");
    }
    catch (Exception e) {}    
  }

	public void LoadTeamGraph()
	{
		int i, j;
		try{
			Temp[0] = 0;
      for (i=0; i<11 && GF[17]; i++ ) I[37+i] = null;
			for (i=0; i<4; i++) {
				System.gc();
        I[37+Temp[0]] = Image.createImage("/images/img" + (37+i) + ".png");
        //System.out.println("1. Loaded img[" + (37+i) + "] to I[" + (37+Temp[0]) + "]");
        loadProgress(1);
        Temp[0]++;
			}

			j = 0;
			if(VSList[0] == 1 || VSList[0] == 4 || VSList[0] == 5) j = 4;

			for (i=0; i<5; i++) {
				System.gc();       	
        if (i < 4) {
					if (j != 0 && i == 2) {
            I[37+Temp[0]] = Image.createImage("/images/img" + (41+i) + ".png");
            //System.out.println("2a. Loaded img[" + (41+i) + "] to I[" + (37+Temp[0]) + "]");
						j--;
					}
					else {
            I[37+Temp[0]] = Image.createImage("/images/img" + (41+i+j) + ".png");
            //System.out.println("2b. Loaded img[" + (41+i+j) + "] to I[" + (37+Temp[0]) + "]");
          }
				}
				else {
          I[37+Temp[0]] = Image.createImage("/images/img" + (48+VSList[0]) + ".png");
          //System.out.println("2c.Loaded img[" + (48+VSList[0]) + "] to I[" + (37+Temp[0]) + "]");
        }
        Temp[0]++;
        loadProgress(1);
			}
      			
			for (i=0; i<2; i++)	{
				System.gc();
        I[37+Temp[0]] = Image.createImage("/images/img" + (56+i+VSList[0]*2) + ".png");
        //System.out.println("3.Loaded img[" + (56+i+VSList[0]*2) + "] to I[" + (37+Temp[0]) + "]");
				Temp[0]++;
        loadProgress(1);
			}			
			GF[17] = true;
			System.gc();			
		} catch (Exception e) {}
	}


  public void loadProgress(int incr) {
    progress += incr;
    if (GM != -1) return;
    Draw();
  }

//------------------------------------------------------------------------------
  	
	public void CreateWind()
	{
		Wind = Math.abs( R.nextInt() % 8 );		
		WindPow = 1 + Math.abs( R.nextInt() % 3 );		
		WindTime = 10 + Math.abs( R.nextInt() % 11 );
		WindUD = 13;
		if( Wind == 0 || Wind == 1 || Wind == 7 ) WindUD = 255;
		if( Wind > 2 && Wind < 4 ) WindUD = 5 + WindPow * 2;
		WindLRPow = 0;
		if( Wind != 0 && Wind != 4 )
			WindLRPow = (1-2*(Wind/4)) * WindSpeed[VSList[0]*3 + WindPow-1];
	}



//------------------------------------------------------------------------------

  
	public void processEvent(int type, int param)
	{
		if (type == KEY_PRESSED_EVENT) {

			Key[3] = getKeypadState();
      
      //boolean SOFT_1 = (Key[3] & 0x400000) != 0; //boolean SOFT_1 = (Key[3] == 4194304);
      //boolean SOFT_2 = (Key[3] & 0x200000) != 0; //boolean SOFT_2 = (Key[3] == 2097152);

      boolean SOFT_1 = (param == KEY_SOFT1);
      boolean SOFT_2 = (param == KEY_SOFT2);

      if (isPaused) {
        
        if(!pausedForHelp) {
          if(SOFT_1) {
            isPaused = false;
            setSoftLabels(main.txt.getBundle("cmdOK")[0], main.txt.getBundle("cmdBack")[0]);
            GF[4] = true;
            Draw();
          }
          return;
        }
        
        if (helpFirstScreen) {
          helpFirstScreen = false;
          Draw();
        }
        else {
          Key[3] = 0;
          resetKeypadState();
          isPaused = false;
          helpFirstScreen = true;          
          setSoftLabels(main.txt.getBundle("cmdOK")[0], main.txt.getBundle("cmdBack")[0]);
          GF[4] = true;
          GF[1] = true; // clear screen!
          Draw();
        }
        return;
      }
      
      if (GM == 0) { // TITLE Mode
        if (SOFT_2) { // Menu Command
          Key[3] = 0;
          GM = -100;
        }
        else if (SOFT_1) startGame();
        else if(param == KEY_5 || param == KEY_SELECT) startGame();
        else {
          if(GM < 350 || GM >=800) {
            showSoftKeys();
            hideSoftKeys(5000, 20);
          }
        }
      }
      else if (GM == 100 || GM == 200) {  // PRE-GAME Modes
        if (SOFT_2) notifyTitle();     // Back
        if (SOFT_1) ProEvent(1048576); // OK button mapped to action key

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -