posts - 495,comments - 227,trackbacks - 0
          public ? class ? Core ? extends ? Canvas ?
          ? implements ? Runnable ? , ? RecordFilter ? { ?
          ? ?
          ? ?
          ? ////////////////////////////////////////////////////////////////// ?
          ? //Game ? core ?
          ? ////////////////////////////////////////////////////////////////// ?
          ? ?
          ? ?
          ? //#ifndef ? Core.GameCanvas ?
          ? ?
          ? //define ? constant ? to ? handle ? game ? key ? states ?
          ? public ? static ? final ? int ? UP_PRESSED ? = ? 1 ? << ? UP; ?
          ? public ? static ? final ? int ? DOWN_PRESSED ? = ? 1 ? << ? DOWN; ?
          ? public ? static ? final ? int ? LEFT_PRESSED ? = ? 1 ? << ? LEFT; ?
          ? public ? static ? final ? int ? RIGHT_PRESSED ? = ? 1 ? << ? RIGHT; ?
          ? public ? static ? final ? int ? FIRE_PRESSED ? = ? 1 ? << ? FIRE; ?
          ? public ? static ? final ? int ? GAME_A_PRESSED ? = ? 1 ? << ? GAME_A; ?
          ? public ? static ? final ? int ? GAME_B_PRESSED ? = ? 1 ? << ? GAME_B; ?
          ? public ? static ? final ? int ? GAME_C_PRESSED ? = ? 1 ? << ? GAME_C; ?
          ? public ? static ? final ? int ? GAME_D_PRESSED ? = ? 1 ? << ? GAME_D; ?
          ? //double ? buffer ?
          ? private ? Image ? __bufferedImage; ?
          ? //clip ?
          ? private ? boolean ? __setClip; ?
          ? private ? int ? __clipX, ? __clipY, ? __clipWidth, ? __clipHeight; ?
          ? ?
          ? public ? void ? paint(Graphics ? g) ?
          ? { ?
          ? if ? (this.__setClip) ? { ?
          ? g.clipRect( ? this.__clipX, ? this.__clipY, ? this.__clipWidth, ? this.__clipHeight); ?
          ? this.__setClip ? = ? false; ?
          ? } ?
          ? g.drawImage(this.__bufferedImage, ? 0, ? 0, ? Graphics.TOP ? | ? Graphics.LEFT ? ); ?
          ? } ?
          ? ?
          ? public ? void ? flushGraphics() ?
          ? { ?
          ? repaint(); ?
          ? serviceRepaints(); ?
          ? } ?
          ? ?
          ? public ? void ? flushGraphics(int ? x, ? int ? y, ? int ? width, ? int ? height) ?
          ? { ?
          ? this.__setClip ? = ? true; ?
          ? this.__clipX ? = ? x; ?
          ? this.__clipY ? = ? y; ?
          ? this.__clipWidth ? = ? width; ?
          ? this.__clipHeight ? = ? height; ?
          ? repaint(); ?
          ? serviceRepaints(); ?
          ? } ?
          ? ?
          ? //#endif ?
          ? ?
          ? ?
          ? //define ? constant ? to ? handle ? soft ? key ? states ?
          ? public ? static ? final ? int ? SOFT_FIRST_PRESSED ? = ? GAME_A_PRESSED; ?
          ? public ? static ? final ? int ? SOFT_LAST_PRESSED ? = ? GAME_B_PRESSED; ?
          ? //MIDlet ? object ?
          ? ? ? ? ? private ? MIDlet ? __midlet; ?
          ? //key ? states ? and ? soft ? key ? states ?
          ? private ? int ? __keyStates, ? __currentKeyStates, ? __lastKeyStates, ? __softKeyStates, ? __currentSoftKeyStates, ? __lastSoftKeyStates; ?
          ? ? ? ? ? //used ? for ? sleep ?
          ? ? ? ? ? private ? long ? __lastSystemTime, ? __elapsedTime; ?
          ? ?
          ? //canvas ? Graphics ? object ?
          ? private ? Graphics ? g; ?
          ? //view ? window ?
          ? private ? int ? viewX, ? viewY, ? viewWidth, ? viewHeight; ?
          ? ? ? ? ? //running ? and ? pause ? flags ?
          ? ? ? ? ? public ? boolean ? running ? = ? true; ?
          ? ? ? ? ? public ? boolean ? pause; ?
          ? ? ? ? ? //clock ?
          ? private ? boolean ? clockRunning ? = ? true; ?
          ? ? ? ? ? public ? long ? virtualTime; ?
          ? ? ? ? ? //frame ? delay ?
          ? ? ? ? ? private ? long ? frameDelay ? = ? 120; ?
          ? //auto ? flushGraphics ?
          ? ?
          ? public ? Core(MIDlet ? m) ? { ?
          ? //#ifndef ? Core.GameCanvas ?
          ? super(); ?
          ? //#else ?
          ? //# ? super(false); ?
          ? //# ? setFullScreenMode(true); ?
          ? //#endif ?
          ? ?
          ? ?
          ? //#ifdef ? Core.GameCanvas ?
          ? this.viewWidth ? = ? getWidth(); ?
          ? this.viewHeight ? = ? getHeight(); ?
          ? //#else ?
          ? //#if ? polish.FullCanvasSize:defined ?
          ? //#= ? this.viewWidth ? = ? ${polish.FullCanvasWidth}; ?
          ? //#= ? this.viewHeight ? = ? ${polish.FullCanvasHeight}; ?
          ? //#else ?
          ? //# ? ? this.viewWidth ? = ? getWidth(); ?
          ? //# ? ? this.viewHeight ? = ? getHeight(); ?
          ? //#endif ?
          ? //#endif ?
          ? ?
          ? ?
          ? //#ifndef ? Core.GameCanvas ?
          ? this.__bufferedImage ? = ? Image.createImage(this.viewWidth, ? this.viewHeight ? ); ?
          ? this.g ? = ? this.__bufferedImage.getGraphics(); ?
          ? //#else ?
          ? //# ? this.g ? = ? getGraphics(); ?
          ? //#endif ?
          ? ?
          ? ?
          ? //midlet ?
          ? ? ? ? ? this.__midlet ? = ? m; ?
          ? } ?
          ? ?
          ? protected ? void ? keyPressed(int ? keyCode) ? { ?
          ? ?
          ? //#ifndef ? Core.GameCanvas ?
          ? this.__keyStates ? |= ? 1 ? << ? getGameAction(keyCode); ?
          ? //#endif ?
          ? ?
          ? ?
          ? ?
          ? switch ? (keyCode) ? { ?
          ? //#ifdef ? polish.key.LeftSoftKey ?
          ? //# ? case ? ${polish.key.LeftSoftKey}: ?
          ? //#else ?
          ? case ? -6: ?
          ? //#endif ?
          ? this.__softKeyStates ? |= ? SOFT_FIRST_PRESSED; ?
          ? break; ?
          ? //#ifdef ? polish.key.RightSoftKey ?
          ? //# ? case ? ${polish.key.RightSoftKey}: ?
          ? //#else ?
          ? case ? -7: ?
          ? //#endif ?
          ? this.__softKeyStates ? |= ? SOFT_LAST_PRESSED; ?
          ? break; ?
          ? } ?
          ? ?
          ? } ?
          ? ?
          ? protected ? void ? keyReleased(int ? keyCode) ? { ?
          ? ?
          ? //#ifndef ? Core.GameCanvas ?
          ? this.__keyStates ? &= ? ~(1 ? << ? getGameAction(keyCode)); ?
          ? //#endif ?
          ? ?
          ? ?
          ? ?
          ? switch ? (keyCode) ? { ?
          ? //#ifdef ? polish.key.LeftSoftKey ?
          ? //# ? case ? ${polish.key.LeftSoftKey}: ?
          ? //#else ?
          ? case ? -6: ?
          ? //#endif ?
          ? this.__softKeyStates ? &= ? ~SOFT_FIRST_PRESSED; ?
          ? break; ?
          ? //#ifdef ? polish.key.RightSoftKey ?
          ? //# ? case ? ${polish.key.RightSoftKey}: ?
          ? //#else ?
          ? case ? -7: ?
          ? //#endif ?
          ? this.__softKeyStates ? &= ? ~SOFT_LAST_PRESSED; ?
          ? break; ?
          ? } ?
          ? ?
          ? } ?
          ? ?
          ? /** ?
          ? ? * ? detect ? user ? input ?
          ? ? * ? ?
          ? ? * ? @param ? keyPressedConstant ?
          ? ? * ? ? ? ? ? ? ? ? ? ? ? ? XXX_PRESSED ? constant ? like ? FIRE_PRESSED ?
          ? ? * ? @param ? detectsStroke ?
          ? ? * ? ? ? ? ? ? ? ? ? ? ? ? set ? true ? to ? detect ? stroke ? action,false ? to ? detect ? key ? pressed ?
          ? ? * ? ? ? ? ? ? ? ? ? ? ? ? state ?
          ? ? * ? @param ? soft ?
          ? ? * ? ? ? ? ? ? ? ? ? ? ? ? set ? true ? to ? detect ? soft ? key,false ? to ? detect ? game ? key. ?
          ? ? * ? @param ? update ?
          ? ? * ? ? ? ? ? ? ? ? ? ? ? ? set ? true ? to ? update ? key(soft ? key) ? state ?
          ? ? * ? @return ?
          ? ? */ ?
          ? private ? final ? boolean ? detectInput(int ? keyPressedConstant, ? boolean ? detectsStroke,boolean ? soft,boolean ? update){ ?
          ? ? ? ? ? if(soft){ ? ? ? ?
          ? ? ? ? ? if(update){ ?
          ? ? ? ? ? this.__lastSoftKeyStates ? = ? this.__currentSoftKeyStates; ?
          ? ? ? ? ? this.__currentSoftKeyStates ? = ? this.__softKeyStates; ?
          ? ? ? ? ? } ?
          ? ? ? ? ? ?
          ? ? ? ? ? if(detectsStroke){ ?
          ? ? ? ? ? ? ? ? ? ? ? ? ? return ? ((this.__lastSoftKeyStates ? & ? keyPressedConstant) ? != ? 0) ? && ? ((this.__softKeyStates ? & ? keyPressedConstant) ? == ? 0); ? ?
          ? ? ? ? ? ? ? ? ? }else{ ?
          ? ? ? ? ? ? ? ? ? return ? ((this.__softKeyStates ? & ? keyPressedConstant) ? != ? 0); ?
          ? ? ? ? ? ? ? ? ? } ?
          ? ? ? ? ? }else{ ? ? ? ? ?
          ? ? ? ? ? if(update){ ?
          ? ? ? ? ? //#ifdef ? Core.GameCanvas ?
          ? //# ? this.__keyStates ? = ? getKeyStates(); ?
          ? ? ? ? ? //#endif ?
          ? ? ? ? ? this.__lastKeyStates ? = ? this.__currentKeyStates; ?
          ? ? ? ? ? this.__currentKeyStates ? = ? this.__keyStates; ?
          ? ? ? ? ? } ?
          ? ? ? ? ? ?
          ? ? ? ? ? if(detectsStroke){ ?
          ? ? ? ? ? ? ? ? ? ? ? ? ? return ? ((this.__lastKeyStates ? & ? keyPressedConstant) ? != ? 0) ? && ? ((this.__keyStates ? & ? keyPressedConstant) ? == ? 0); ? ?
          ? ? ? ? ? ? ? ? ? }else{ ?
          ? ? ? ? ? ? ? ? ? return ? ((this.__keyStates ? & ? keyPressedConstant) ? != ? 0); ?
          ? ? ? ? ? ? ? ? ? } ?
          ? ? ? ? ? } ?
          ? } ?
          ? ?
          ? //implements ? interface ? Runnable ?
          ? public ? void ? run(){ ?
          ? try{ ?
          ? initialize(); ?
          ? ?
          ? while ? (running) ? { ?
          ? this.__lastSystemTime ? = ? System.currentTimeMillis(); ?
          ? ?
          ? if(!pause){ ?
          ? //#ifndef ? Core.GameCanvas ?
          ? this.g ? = ? this.__bufferedImage.getGraphics(); ?
          ? //#else ?
          ? //# ? this.g ? = ? getGraphics(); ?
          ? //#endif ?
          ? executeFrameTask(); ?
          ? if(clockRunning){ ?
          ? this.virtualTime ? += ? this.frameDelay; ?
          ? } ?
          ? } ?
          ? ?
          ? this.__elapsedTime ? = ? System.currentTimeMillis() ? - ? this.__lastSystemTime; ?
          ? if ? (this.__elapsedTime>0 ? && ? this.__elapsedTime ? < ? this.frameDelay) ? { ?
          ? try{ ?
          ? Thread.sleep(this.frameDelay ? - ? this.__elapsedTime); ?
          ? }catch(InterruptedException ? ie){} ?
          ? } ?
          ? ?
          ? //#mdebug ? benchmark ?
          ? //# ? System.out.println("elapsed ? time: ? " ? + ? String.valueOf(this.__elapsedTime) ? + ? ?
          ? //# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? " ? ? (" ? + ? String.valueOf(this.__elapsedTime*100/this.frameDelay) ? + ? "%)"); ?
          ? //#enddebug ?
          ? } ?
          ? ?
          ? this.__midlet.notifyDestroyed(); ?
          ? ? ? ? ? ? ? ? ? //#mdebug ? info ?
          ? ? ? ? ? //# ? System.out.println("game ? stop ? normally."); ?
          ? //#enddebug ?
          ? ? ? ? ? }catch(Exception ? e){ ?
          ? ? ? ? ? ? ? ? ? //#mdebug ? fatal ?
          ? ? ? ? ? //# ? System.out.println("a ? fatal ? error ? occured."); ?
          ? ? ? ? ? ? ? ? ? //# ? e.printStackTrace(); ?
          ? //#enddebug ?
          ? ? ? ? ? ? ? ? ? ?
          ? ? ? ? ? showSystemHint(Locale.get("Game.SystemError")); ?
          ? ? ? ? ? ?
          ? ? ? ? ? this.__midlet.notifyDestroyed(); ?
          ? ? ? ? ? } ?
          ? } ?
          ? ? ? ? ? ? ? ? ? //略…… ?
          ? }???


          ??????? 上面的代碼在MIDP1.0接口的基礎(chǔ)上模擬了MIDP2.0 ? GameCanvas的功能,并對用戶輸入作了增強(qiáng)。 ?
          ? ? ? ? paint(Graphics ? g)實(shí)現(xiàn)了父類的抽象方法。 ?
          ? ? ? ? flushGraphics()和flushGraphics(int ? x, ? int ? y, ? int ? width, ? int ? height)是對GameCanvas相應(yīng)方法的模擬,方便調(diào)用。 ?
          ? ? ? ? keyPressed(int ? keyCode)和keyReleased(int ? keyCode)用來捕獲用戶輸入,并記錄按鍵的狀態(tài)。 ?
          ? ? ? ? detectInput(int ? keyPressedConstant, ? boolean ? detectsStroke,boolean ? soft,boolean ? update)用于根據(jù)案件狀態(tài)來判斷,用戶(玩家)是否將某個(gè)鍵(包括左右系統(tǒng)鍵)按下一次,或按下沒有松開。 ?
          ? ? ? ? run()實(shí)現(xiàn)了Runnable接口的方法,其中,游戲初始化在initialize()中進(jìn)行,游戲循環(huán)在executeFrameTask()中實(shí)現(xiàn)。每一幀如果不到預(yù)定的幀延遲時(shí)間就讓當(dāng)前線程睡眠一會(huì)。 ?
          ? ?
          ? ? ? ? 這只是一小部分,為了閱讀方便有些改動(dòng)。另外,在我的游戲內(nèi)核里還有 ?
          ? ? ? ? Temporary ? Memory部分 ? ? ? ? ? ? 用于方便的把數(shù)據(jù)按照數(shù)據(jù)流DataInputStream和DataOutputStream來操作。 ?
          ? ? ? ? General部分 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 定義了8個(gè)方向,高效產(chǎn)生隨機(jī)數(shù),對矩形進(jìn)行碰撞判斷,byte[]和int的相互轉(zhuǎn)換。 ?
          ? ? ? ? Device ? Feature部分 ? ? ? ? ? ? ? ? 包括設(shè)備相關(guān)特性的操作:聲音、振動(dòng)和燈光 ?
          ? ? ? ? UI部分 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 包括在屏幕上書寫特效文字,在一個(gè)區(qū)域內(nèi)分頁顯示大段文字(比如人物對話),系統(tǒng)信息提示和進(jìn)度條。 ?
          ? ? ? ? Map部分 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 對游戲中地圖的解析和顯示 ?
          ? ? ? ? Game ? Menu部分 ? ? ? ? ? ? ? ? ? ? ? ? ? 游戲菜單,繪制菜單和獲取用戶對菜單項(xiàng)的選擇。 ?
          ? ? ? ? Resource ? and ? storage部分 ? ? 用于獲取打包資源(為了使壓縮比更大)和按文件名方式管理RMS內(nèi)容,還有從網(wǎng)上下載資源。 ?
          ? ? ? ? Path部分 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 產(chǎn)生完美的圓弧和直線路徑,用于子彈敵人飛行等 ?
          ? ? ? ? 上面各部分為了使字節(jié)碼盡可能少,我沒有做類封裝,而是寫到了一起。另外,如果有哪些部分沒有被調(diào)用到,那么在作繞碼(混淆)時(shí),會(huì)被自動(dòng)去掉,所以不必?fù)?dān)心。 ?
          ? ?
          ? ? ? ? ? 我還寫了對MIDP2.0 ? Sprite類的模擬類,以便使用。 ?
          ? ?
          ? ? ? ? ? 內(nèi)核部分之外,就是具體游戲邏輯的實(shí)現(xiàn)了。其實(shí),有了上面工具的幫助,游戲邏輯的實(shí)現(xiàn)是就容易多了。 ?
          ? ?
          ? ? ? ? ? 除了j2me的程序,在開發(fā)中還需要一些工具,如:資源打包工具,地圖編輯器和圖像優(yōu)化工具。 ?
          ? ? ? ? ? 資源打包工具——把多個(gè)資源文件(如png圖片等)打包為一個(gè)文件,這樣在jar包中會(huì)有更大的壓縮比。 ?
          ? ? ? ? ? 地圖編輯器——編輯游戲地圖,共類似TiledLayer使用。 ?
          ? ? ? ? ? 圖像優(yōu)化工具——將png圖片進(jìn)一步壓縮,節(jié)約空間。 ?
          ? ?
          ? ? ? ? ? 以上內(nèi)容我正在使用。 ?
          ? ?
          ? ?
          ? 二、商業(yè)運(yùn)作 ?
          ? ? ? ? ? 這方面問題如果沒有深入進(jìn)去,是比較難了解的。在國內(nèi),j2me應(yīng)用是通過sp(Service ? Provider,開發(fā)者是cp ? content ? provider之一)來進(jìn)行發(fā)布,通過移動(dòng)審批后供用戶下載使用。通常的商業(yè)模式為:預(yù)付款+按比例分成。具體數(shù)字和比例看CP的名氣、東西的品質(zhì)和談判的技巧等。 ?
          ? ? ? ? ? 如果東西好,還可以銷售到國外。除了通過運(yùn)營商銷售以外,還可以放在獨(dú)立的銷售網(wǎng)站上銷售。好東西,價(jià)格都很高的。像gameloft的單機(jī)游戲幾十港元一個(gè)。通過運(yùn)營商的,通常可以買到4-5歐元一個(gè)下載。 ?
          ? ? ? ? ? 所以,新興的手機(jī)游戲市場,是個(gè)大餡餅,有很多機(jī)會(huì)。尤其是對于我們這種沒有資金的個(gè)人或小型團(tuán)隊(duì)來說,是淘金千載難逢的機(jī)遇。 ?
          ? ? ? ? ? 更詳細(xì)的以后再談。 ?
          ? 三、demo ?
          ? ? ? ? ? 這個(gè)demo是我目前尚未發(fā)布的作品,MIDP2 ? is ? required.具體我不多談了,CSDN不能上傳,有興趣可以給我發(fā)郵件,我用附件發(fā)送。 ?
          ? ?
          ? 四、關(guān)于我和我尋求的幫助 ?
          ? ? ? ? ? 先說我個(gè)人。我2000年考入國防科技大學(xué),2年后不能忍受壓抑的環(huán)境要求退學(xué)未受批準(zhǔn),于是不告而別被開除。后來研究技術(shù),沒有找到合適的市場機(jī)會(huì)。幾個(gè)月前和像素點(diǎn)工作室的朋友在四川合作開發(fā)手機(jī)游戲,現(xiàn)在擁有1個(gè)完整產(chǎn)品和完善內(nèi)核、周邊工具。 ?
          ? ?
          ? ? ? ? ? 也許最理智的程序員也會(huì)在愛情面前陷入死循環(huán),直到資源耗盡系統(tǒng)崩潰! ?
          ? ? ? ? ? 我尋求的幫助。去年我和北京一個(gè)女孩有個(gè)為期5個(gè)月的浪漫約定,于是我就走入移動(dòng)開發(fā)領(lǐng)域。可是,時(shí)間到了,我的東西還沒出來,我失約了。約定又超過了2個(gè)月,我不想絮叨情感上的糾纏不清,可的確發(fā)生了很多事情。今天我和她聊天,我不能再等了。我不能等到我的游戲談判完賣出去以后再去找她,因?yàn)樗獨(dú)Я俗约海^無玩笑。 ?
          ? ?
          ? ?
          ? ? ? ? ? 對具體的技術(shù)和商業(yè)細(xì)節(jié)感興趣,可以和我面談。如果你愿意善意的幫助一個(gè)同行,交一個(gè)真誠的朋友或者共同開發(fā)手機(jī)游戲市場,請盡快聯(lián)系我。??
          http://topic.csdn.net/t/20050308/05/3832358.html

          posted on 2007-02-03 19:15 SIMONE 閱讀(367) 評論(0)  編輯  收藏 所屬分類: JAVA
          主站蜘蛛池模板: 喀什市| 盐山县| 平南县| 通化市| 江源县| 石阡县| 襄城县| 北辰区| 济阳县| 安国市| 无棣县| 武山县| 长汀县| 阳春市| 临夏市| 瑞昌市| 甘谷县| 福泉市| 芒康县| 察隅县| 比如县| 涪陵区| 云梦县| 泰顺县| 湾仔区| 岳池县| 缙云县| 永寿县| 奉贤区| 会泽县| 大丰市| 巴塘县| 偏关县| 南木林县| 绍兴县| 美姑县| 若尔盖县| 稷山县| 龙江县| 岳阳县| 婺源县|