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

📄 gmcanvas.java

📁 蓝牙技术 本游戏来源于网络
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    	if (downPressed[0])		c += 0x00080000;
    	if (firePressed[0])		c += 0x00100000;
    	c += (tickCount & 0x0000ffff);
    	BlueTooth.send(c);
    }


	// -------------------------------------------------------------------------------------------
	// draw the title
	// -------------------------------------------------------------------------------------------
    private void drawTitle(Graphics g)
    {
        if (imageTitle != null)	// Should only occur if paused is pressed at the very point this thread is started
        {
			g.drawImage(imageTitle, getWidth()>>1, 0, Graphics.TOP | Graphics.HCENTER);
        }
    }
    // draw game
//#ifdef midp2
    private void draw()
    {
        Graphics g = getGraphics();
//#else
//    public void paint(Graphics g)
//    {
//#endif
		g.setFont(GAME_FONT);

		int i;
        g.setClip(0, 0, VIS_WIDTH, VIS_HEIGHT);

        if (gameMode == GM_TITLE || gameMode == GM_FIRST || gameMode == GM_SPLASH)
        {
			g.setColor(0x00000000);
			g.fillRect(0,0,VIS_WIDTH, VIS_HEIGHT);
			drawTitle(g);
			return;
		}
		// -------------------------------------------------------------------------------------------
		// Its assumed that payment stuff will be done when menu would normally be displayed
		// -------------------------------------------------------------------------------------------
		else if (gameMode == GM_TITLE2 || gameMode == GM_EXIT)
		{
			g.setColor(0x00000000);
			g.fillRect(0,0,VIS_WIDTH, VIS_HEIGHT);
			drawTitle(g);
			drawMenu(g);
		}

		// -------------------------------------------------------------------------------------------
		// Main game stuff is going to be displayed here
		// -------------------------------------------------------------------------------------------
		else if (gameMode != GM_INIT && !(gameMode == GM_INIT_LEVEL && tickCount == 0) && gameMode != GM_ENTER_SCORE)
		{
			g.setColor(0x00000000);
			g.fillRect(0,0,VIS_WIDTH, VIS_HEIGHT);
		}
		if (gameMode == GM_ENTER_SCORE)
		{
			if (Standard.enterScoreStatus == 0 || Standard.enterScoreStatus == 1 || Standard.enterScoreStatus == 4 || Standard.enterScoreStatus == 5)
			{
				g.setColor(0x00000080);
				g.fillRect(0, 0, VIS_WIDTH, VIS_HEIGHT);
				if (((VIS_HEIGHT>>1)-18) > fontHeight)
				{
					drawTitle(g);
				}
				Standard.myTicker(g, GAME_FONT, -1, VIS_WIDTH);
				Standard.drawEnterScore(g,20,fontHeight);
				drawSoftKey(g,6,-1);
			}
			else
			{
		        g.setColor(0x00000080);
				g.fillRect(0, 0, VIS_WIDTH, VIS_HEIGHT);
				drawTitle(g);
		        g.setColor(0x00F0F0F0);
				StringBuffer b = new StringBuffer("");
//				b.append(dude[thisDude].score);
				if (Standard.enterScoreStatus == 3)
				{
					int sx = (VIS_WIDTH>>1) - GAME_FONT.stringWidth(Standard.hsName.toString());
					if (sx < 0) sx = 0;
					g.drawString(Standard.hsName.toString(),sx,(VIS_HEIGHT>>1)-fontHeight,Graphics.TOP | Graphics.LEFT);
				}
		        g.drawString(dict.getString(Dictionary.SCORE),VIS_WIDTH >> 1,(VIS_HEIGHT>>1),Graphics.TOP | Graphics.RIGHT);
		        g.drawString(b.toString(),VIS_WIDTH >> 1,(VIS_HEIGHT>>1),Graphics.TOP | Graphics.LEFT);
				if (Standard.enterScoreStatus == 6 || Standard.enterScoreStatus == 7)
				{
					g.drawString(Standard.hsName.toString(),VIS_WIDTH >> 1,(VIS_HEIGHT>>1)-fontHeight,Graphics.TOP | Graphics.RIGHT);
					StringBuffer tstBuf = new StringBuffer(dict.getString(Dictionary.INT_CONN/*+Standard.hsSubmit*/));
					Standard.boxWrap(g, GAME_FONT, fontHeight, tstBuf, 8, (DISPLAY_HEIGHT>>2), DISPLAY_WIDTH-16, (DISPLAY_HEIGHT>>1));
				}
				drawSoftKey(g,0,16);
			}
		}

		// -------------------------------------------------------------------------------------------
		// Init animation here if required
		// -------------------------------------------------------------------------------------------
		if (gameMode == GM_INIT_LEVEL && tickCount > 0)
		{
		}

		// -------------------------------------------------------------------------------------------
		// End of level/game animation here if required
		// -------------------------------------------------------------------------------------------
		if (gameMode == GM_LEVEL_COMP || gameMode == GM_GAME_COMPLETE)
		{
		}

		// -------------------------------------------------------------------------------------------
		// Show game over animation here
		// -------------------------------------------------------------------------------------------
		if (gameMode == GM_GAME_OVER)
		{
	        g.setClip(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT);
	        g.setColor(0x00ffffff);
			g.drawString(dict.getString(Dictionary.GAME_OVER),DISPLAY_WIDTH>>1,yDisplay+(DISPLAY_HEIGHT>>1),Graphics.TOP | Graphics.HCENTER);
		}

		// -------------------------------------------------------------------------------------------
		// Show menu if its forced
		// -------------------------------------------------------------------------------------------
		if (forceMenu) drawMenu(g);


		// -------------------------------------------------------------------------------------------
		// Bluetooth setup or problems, so show a message
		// -------------------------------------------------------------------------------------------
		if (btResent > BT_DELAY)
		{
			StringBuffer tstBuf = new StringBuffer(dict.getString(Dictionary.BT_LOST));
			Standard.boxWrap(g, GAME_FONT, fontHeight, tstBuf, 8, (DISPLAY_HEIGHT>>2), DISPLAY_WIDTH-16, (DISPLAY_HEIGHT>>1));
		}
		else if (bBTSetup)
		{
			// Draw bubble box if bluetooth
			if ((btStatus == BT_AWAIT_RECEIVE && bHost) || btStatus == BT_AWAIT_CLIENT)
			{
				StringBuffer tstBuf = new StringBuffer(dict.getString(Dictionary.BT_WAIT_JOIN));
				Standard.boxWrap(g, GAME_FONT, fontHeight, tstBuf, 8, (DISPLAY_HEIGHT>>2), DISPLAY_WIDTH-16, (DISPLAY_HEIGHT>>1));
			}
			else if ((btStatus == BT_AWAIT_RECEIVE && !bHost) || btStatus == BT_AWAIT_HOST)
			{
				StringBuffer tstBuf = new StringBuffer(dict.getString(Dictionary.BT_SEARCH_HOST));
				Standard.boxWrap(g, GAME_FONT, fontHeight, tstBuf, 8, (DISPLAY_HEIGHT>>2), DISPLAY_WIDTH-16, (DISPLAY_HEIGHT>>1));
			}
		}

		// -------------------------------------------------------------------------------------------
		// Show frames per second if its a beta
		// -------------------------------------------------------------------------------------------
//#ifdef demo
		g.setClip(0, 0, VIS_WIDTH, VIS_HEIGHT);
        g.setColor(0x00ffffff);
		StringBuffer buf = new StringBuffer("");
		buf.append(fps);
		buf.append("fps");
		g.drawString(buf.toString(), VIS_WIDTH, 0, Graphics.TOP | Graphics.RIGHT);
//#endif
    }



	// -------------------------------------------------------------------------------------------
	// Set the clipping region. returns true if within boudaries
	// -------------------------------------------------------------------------------------------
	static boolean mySetClip(Graphics g, int x, int y, int xs, int ys)
	{
		int xe = xs,
			ye = ys;
		if (x > GMCanvas.xDisplay+DISPLAY_WIDTH || x+xs < GMCanvas.xDisplay
				|| y > GMCanvas.yDisplay+DISPLAY_HEIGHT || y+ys < GMCanvas.yDisplay)
					return false;
		if (x < GMCanvas.xDisplay)
		{
			xe-= GMCanvas.xDisplay-x;
			x = GMCanvas.xDisplay;
		}
		else if (x+xs > GMCanvas.xDisplay+DISPLAY_WIDTH) xe = (GMCanvas.xDisplay+DISPLAY_WIDTH)-x;
		if (y < GMCanvas.yDisplay)
		{
			ye-= GMCanvas.yDisplay-y;
			y = GMCanvas.yDisplay;
		}
		else if (y+ys > GMCanvas.yDisplay+DISPLAY_HEIGHT) ye = (GMCanvas.yDisplay+DISPLAY_HEIGHT)-y;

		g.setClip(x, y, xe, ye);
		return true;
	}


	// -------------------------------------------------------------------------------------------
	// Show game credits
	// -------------------------------------------------------------------------------------------
	public void drawCredit(Graphics g)
	{
	}


	// -------------------------------------------------------------------------------------------
	// Show game Menu:- will no doubt need to be changed for each game
	// -------------------------------------------------------------------------------------------
	public void drawMenu(Graphics g)
	{
		if (optionPage == 3)
		{
//			Standard.drawHiscore(g,imageTitle.getHeight()+6,fontHeight);
			drawSoftKey(g,-1,7);
			return;
		}
		else if (optionPage == 4)
		{
			drawCredit(g);
			drawSoftKey(g,-1,7);
			return;
		}
		int x,
			y = (gameMode == GM_TITLE || gameMode == GM_TITLE2) ? /*imageTitle.getHeight()+6*/ yDisplay+8 : yDisplay+8,
			ye = (gameMode == GM_TITLE || gameMode == GM_TITLE2) ? VIS_HEIGHT-fontHeight : yDisplay+DISPLAY_HEIGHT,
			i,
			j,
			k,
			col,
			opt,
			optOffset,
			rKey,
			radius = 48,//(VIS_WIDTH>>1)-16,
			sinCount = 0,
			iText,
			ih = Standard.imageText[0].getHeight(),
			bounce;

		switch (optionPage)
		{
			case 1:
				opt = MAX_OPTIONS[1];
				optOffset = 8;
				sinCount = 8;
				rKey = 7;

				break;
			case 2:
				opt = MAX_OPTIONS[2];
				optOffset = 10;
				sinCount = 1;
				rKey = 7;
				break;
			default:
				opt = MAX_OPTIONS[0];
				optOffset = 0;
				rKey = 5;
				if (forceMenu)
				{
					sinCount = 2;
				}
				else
				{
					if (optionPage == 0)
					{
						if (!options[0] || !options[2])
							sinCount = 7;
						if (!options[0] && !options[2])
							sinCount = 1;
					}
				}
				break;
		}
		drawSoftKey(g,6,rKey);
        g.setClip(0, 0, VIS_WIDTH, VIS_HEIGHT);
    	y+=((ye-y)-((ih+2)*opt))>>1;
    	x = (VIS_WIDTH>>1)-((opt>>1)*40);
    	y = (VIS_HEIGHT>>1)-16;

    	for (i = optOffset; i < opt+optOffset; i++)
        {
			if (forceMenu && i != 0 && i != 5) continue;
        	if (optionPage == 0 && ((!options[i] && i == 0) || (i != 0 && !options[i]))) continue;
        	if (optionPage == 2)
        	{
				if (ge != null)
				{
        			if (GameEffects.soundOn && i == optOffset+1) i++;
        			else if (!GameEffects.soundOn && i == optOffset) i++;
				}
				else if (i == optOffset) i++;
        	}
			if ((i-optOffset) == option && !forceMenu)
			{
				bounce = tickCount & 0x7;
				bounce -=4;
				if (bounce < 0) bounce = -bounce;
			}
			else bounce = 0;
        	iText = i;
        	if (optionPage == 1 && i == 10) iText = 7;
        	else if (optionPage == 2 && i == 14) iText = 7;
        	x = (VIS_WIDTH>>1)-((radius*menuC[sinCount])>>14);
        	y = ((VIS_HEIGHT>>1)-24)+((radius*(16384-menuS[sinCount++]))>>14);
        	y -= bounce;
    		g.setColor(0x00303060);
    		g.fillRoundRect(x-9,y-9,17,17,8,8);
			if ((i-optOffset) == option)
			{
	    		g.setColor(0x00f0f000);
	    		g.drawRoundRect(x-9,y-9,17,17,8,8);
//#ifdef nokia
//				g.setColor(0x008080c0);
//#else
	    		g.setColor(0x00303060);
//#endif
	    		g.fillRoundRect(((VIS_WIDTH>>1)-(Standard.imageText[iText].getWidth()>>1))-4,(VIS_HEIGHT>>1)+24,Standard.imageText[iText].getWidth()+8,Standard.imageText[iText].getHeight(),8,8);
	        	if (forceMenu && i != 0) iText = Dictionary.QUIT-1;
				g.drawImage(Standard.imageText[iText],VIS_WIDTH>>1, (VIS_HEIGHT>>1)+24, Graphics.TOP | Graphics.HCENTER);
			}
			if (forceMenu && i != 0) iText = 6;
			if (optionPage == 1) iText--;
			if (optionPage == 2)
			{
				if (i >= 11 && i <= 13) iText--;
				iText--;
			}

			if (imageMenu != null)
			{
		        g.setClip(x-8,y-8,16,16);
				g.drawImage(imageMenu,x-8-(iText<<4),y-8,Graphics.TOP | Graphics.LEFT);
		        g.setClip(0, 0, VIS_WIDTH, VIS_HEIGHT);
			}
		}

	}


	// -------------------------------------------------------------------------------------------
	// Draw soft key text. Move to Standard?
	// -------------------------------------------------------------------------------------------
	public void drawSoftKey(Graphics g, int l, int r)
	{
   		g.setColor(0x00303060);
        g.setClip(0,VIS_HEIGHT-(fontHeight+1),VIS_WIDTH,fontHeight+1);
		if (l >= 0) g.fillRect(0,VIS_HEIGHT-(fontHeight+1),GAME_FONT.stringWidth(dict.getString(Dictionary.MENU_0+l))+2,fontHeight+1);
		if (r >= 0) g.fillRect(VIS_WIDTH-(GAME_FONT.stringWidth(dict.getString(Dictionary.MENU_0+r))+2),VIS_HEIGHT-(fontHeight+1),(GAME_FONT.stringWidth(dict.getString(Dictionary.MENU_0+r))+2),fontHeight+1);
   		g.setColor(0x00f0f0f0);
		if (l >= 0) g.drawString(dict.getString(Dictionary.MENU_0+l), 0, VIS_HEIGHT-fontHeight, Graphics.TOP | Graphics.LEFT);
		if (r >= 0) g.drawString(dict.getString(Dictionary.MENU_0+r), VIS_WIDTH-GAME_FONT.stringWidth(dict.getString(Dictionary.MENU_0+r)), VIS_HEIGHT-fontHeight, Graphics.TOP | Graphics.LEFT);
	}


	// -------------------------------------------------------------------------------------------
	// If we are scrolling then correct the sprites on screen position
	// -------------------------------------------------------------------------------------------
	static void setPosition()
	{
	}

	// -------------------------------------------------------------------------------------------
	// Collision stuff
	// -------------------------------------------------------------------------------------------
	static void collTest()
	{
	}

	// -------------------------------------------------------------------------------------------
	// Used to reload a level and setup level specific stuff
	// -------------------------------------------------------------------------------------------
	public void restartLevel(int lvl)
	{
	}


	// -------------------------------------------------------------------------------------------
	// Store the game to RMS
	// -------------------------------------------------------------------------------------------
	public void storeGame()
	{
		// A list of times when we do not want game data overwritten
		if (gameMode == GM_TITLE || gameMode == GM_TITLE2 || bBTSetup || bMultiplayer || gameMode == GM_EXIT) Standard.setSettings(this);
		else
		{
			Standard.setSettings(this);
			Standard.setGame(this);
		}
	}

}

⌨️ 快捷键说明

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