RPG01

MAGI JAVA -Make a game in Java-
JAVA Game作成講座 021回
ショップを作る 1 宿屋


kouza021 jarファイル



[宿屋を作成]
他のショップを作る前に、もっとも簡単なひな型を公開する。
買い物処理はこれをベースに追加することで完成する。
ステータス画面とやることはほとんど同じなので難しい処理ではない。
まず一回目は宿屋の作成。
回復魔法陣があるから要らないって?
今回の作品はドラクエを目指して作っているので、
ドラクエでやっている処理はなるべく再現しておきたい。

[ShopPartクラスを新規作成]
短いので丸ごとコピペする。

import java.awt.Graphics;

public class ShopPart {

public int mode=0;
public int sType=0;
public int sRank=0;

public Graphics g;
private GameData gData=null;
public int[] cursorX=new int[60];
public int[] cursorY=new int[60];
public int[] cursorPos=new int[60];
public int[] cursorMax=new int[60];
public int[] timer=new int[2];

public boolean shopEnd=false;
private ItemDataSet idSet=null;
public ItemData[] siData=null;
public GraphicSet gSet=null;
public int siCount=0;
public boolean infoDisp=false;
public String infoWord="";
private int modeChange=0;
public int count=0;

public ShopPart() {
init();
gData=new GameData();
gSet=new GraphicSet();
idSet=new ItemDataSet();
}

public void init() {
mode=1;
sType=0;
sRank=0;
shopEnd=false;
for (int i=0;i<=59;i++) {
cursorX[i]=0;
cursorY[i]=0;
cursorPos[i]=0;
cursorMax[i]=0;
}
cursorSet(1,54,130,2);
timerSet(0);
siData=new ItemData[10];
for (int i=0;i<=9;i++) {

siData[i]=new ItemData();
}
infoDisp=false;
modeChange=0;
}

public void cursorSet(int num,int x,int y,int max) {
cursorX[num]=x;
cursorY[num]=y;
cursorPos[num]=0;
cursorMax[num]=max;
}

public void timerSet(int endtime) {
timer[0]=0;
timer[1]=endtime;
}

public void dataSet(GameData gdt,int shopType,int shopRank) {
init();
gData=gdt;
sType=shopType; //1宿 2武器 3防具 4装具? 5道具 と仮定する。
sRank=shopRank; //ランクが高い程強く高額なアイテムを扱う。
}

public void eventStart(GameData gdt) {
int cursorPlus=0;
int pushKey=0;
int cPlus=0;
if (gData.pPlatform.keyPush[4]) {
gData.pPlatform.keyPush[4]=false;
pushKey=1;
}
if (gData.pPlatform.keyPush[5]) {
gData.pPlatform.keyPush[5]=false;
pushKey=2;
}

if (gData.pPlatform.keyPush[0]) {
gData.pPlatform.keyPush[0]=false;
cPlus=-1;
}
if (gData.pPlatform.keyPush[1]) {
gData.pPlatform.keyPush[1]=false;
cPlus=1;
}
if (gData.pPlatform.keyPush[2]) {
gData.pPlatform.keyPush[2]=false;
cPlus=-20;
if (mode==9 || mode==11) cPlus=-10;

}
if (gData.pPlatform.keyPush[3]) {
gData.pPlatform.keyPush[3]=false;
cPlus=20;
if (mode==9 || mode==11) cPlus=10;
}
cursorPos[mode]+=cPlus;
if (cursorPos[mode] > cursorMax[mode]) cursorPos[mode]=0;
if (cursorPos[mode] < 0) cursorPos[mode]=cursorMax[mode];

int cpos=cursorPos[mode];
if (sType==1) { //宿屋のみ動作が違う。
if (mode==1) {//総合メニュー
if (pushKey==1) {
if (cpos==0) modeChange=2;
if (cpos==1) shopEnd=true;
}
if (pushKey==2) shopEnd=true;
}
if (mode==2) {
if (count==0) {
count++;
timerSet(30);
infoDisp=true;
infoWord="全回復した!";
//全回復する。トータル値をマックスと同じ値にする。当然liveがあるユニットのみ。空欄は無視

for (int i=0;i<=3;i++) {
if (gData.unitLiveCheck(i)) {
for (int j=0;j<=2;j++) {
gData.uData[i].vst_total[i]=gData.uData[i].vst_max_total[i];
}
}
}
}
if (timer[0]>=timer[1]) {
shopEnd=true;
}
}
} else { //武器屋、防具屋、装具屋、アイテム屋は全て共通の流れになる。

if (mode==1) {//総合メニュー

if (pushKey==2) shopEnd=true;
}
}
if (timer[1]>=1 && timer[0] if (modeChange>=1) {
infoDisp=false;
mode=modeChange;
modeChange=0;
count=0;
timerSet(0);
}
}

//手軽に入力するためだけの関数
public void sellItemDataSet(int type,int iNum) {
ItemData idata=idSet.dataSet_easy(type,iNum);
siData[siCount]=idata;
siCount++; //0から始めて一個ずつスライドする。
}

public void paint(Graphics gr) {
g=gr;
int sx=76;
int sy=108;
gSet.rectSet2(g,sx-22,sy-22,144,100,0,0);
String[] word1= {"","買う","売る","戻る"}; //0番目には店のカテゴリー名が入る
if (sType==1) {
String[] me= {"[宿屋]","休む","戻る",""};
word1=me;
}
for (int i=0;i<=word1.length-1;i++) {

gSet.wordDisp_short(gr,word1[i],sx,sy+i*22);
gSet.wordDisp_short2(g,"→",cursorX[1],cursorY[1]+cursorPos[1]*22,2);
}
if (infoDisp) infoPaint();
}

public void infoPaint() {
int sx=100;
int sy=300;
gSet.rectSet2(g,sx-22,sy-22,144,100,0,0);
gSet.wordDisp_short(g,infoWord,sx,sy);
}

}

ほとんど目新しい処理はない。
回復の命令を出した後、タイマーが30カウントすぎるまで
infoDisp=true;
infoWord="全回復した!";
という命令を出していることくらいか。
モードにかかわりなくinfoPaintという命令を読み込み、
infoWordに設定した文字列を表示し続ける。
キー入力で送らせるまでもない簡単なメッセージを出すときに使える。
戦闘画面やステータス画面にに逆輸入して、
無駄な行動をしたときに警告として使ってもいいかもしれない。

このように作っている最中に色々思いついて追加していくので、
同じようなゲームを作っても毎回違う処理になってしまう。

次回は武器屋、防具屋、装具屋、アイテム屋を作る。
そんないっぱい一気につくるの大変じゃない?
と思うかもしれないが、最初にやる売り物の設定が違うだけで
全く同じ処理なのでまとめて作ってもそう変わりない。
買う、売るの処理を作成する。
お金の表示も作ってないので所持金ウィンドウも作る。



・トップページへ戻る
inserted by FC2 system