這里我將要講述我游戲的主角,Hero。這里的游戲的主角相對(duì)比較簡(jiǎn)單。 只需實(shí)現(xiàn),飛機(jī)的移動(dòng)以及創(chuàng)建。
唯一的兩點(diǎn)是飛機(jī)移動(dòng)的時(shí)候,不能把飛機(jī)都給移動(dòng)到屏幕外面去了。只有的話,那我們這些設(shè)計(jì)游戲的人就太不專(zhuān)業(yè)了。呵呵。
至于發(fā)射子彈,本來(lái)我也想把Ball跟發(fā)射子彈的創(chuàng)建以及管理都放在此的,后來(lái)想想,還是分開(kāi)點(diǎn)好。這些就是高手們常常說(shuō)的。要解耦啊,每個(gè)類(lèi)應(yīng)該盡量簡(jiǎn)單啊。不應(yīng)該負(fù)責(zé)額外的工作啊。
我聽(tīng)這些都煩惱死了。不過(guò)煩惱歸煩。高手的話還是要聽(tīng)的。^_^
同理可以實(shí)現(xiàn)Foe, Ball等角色類(lèi),以及創(chuàng)建FoeManager, BallManager等.這里就不詳細(xì)闡述他們了
java 代碼
-
-
-
-
-
- package org.wuhua.battleplan;
-
- import org.wuhua.game.model.Fairy;
- import org.wuhua.game.util.Log;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public class Hero extends Fairy {
-
-
- static Log log = Log.getLog("Hero");
- static Hero hero;
- private Hero(int x, int y){
- super(Resources.FLY, x, y);
- }
-
-
-
- public final static Hero createHero(int x, int y){
- if(hero == null){
- hero = new Hero(x,y);
- }
- return hero;
- }
-
-
-
-
- public final void moveLeft(){
- if(this.getX()>=16)
- this.move(-8, 0);
- }
-
- public final void moveRight(){
- if(this.getX()<=Platform.WIDTH-16)
- this.move(8, 0);
- }
-
- public final void moveUp(){
- if(this.getY()>=8)
- this.move(0, -8);
- }
- public final void moveDown(){
- if(this.getY()<=Platform.HEIGHT-38)
- this.move(0, 8);
- }
- }
|