RPG01
MAGI JAVA -Make a game in Java- JAVA Game作成講座2 09回 オブジェクトエディター作成1
RPGkouza2-09 zipファイル
[起動方法]
1. Java Runtime Environmentをインストールする。
http://java.com/ja/download/
2.ファイルを適当な場所で解凍する。
3.コマンドプロンプトのアイコンが入っているので起動。
4.j 一文字だけ入力して「Enter」。
これでゲームが始まるはず。
[オブジェクトエディター作成1]
どこかで書いたかもしれないが、イベント全般の起動に使うものを「オブジェクト」と呼称している。
宝箱、会話キャラ、場所移動イベント…全てオブジェクトとして扱っている。
調子にのってどんどん先へ行くところだった。まだ全然序盤だが、新処理ができたのでここでカットする。
そういいながら大分手を付けているが、ほとんどマップエディタでやった処理なので目新しい部分は一部しかない。
新しく作った部分は一つだけ。
「テンキーで数値入力できるようにした」
ちょっと長くなるが、ObjectEditorクラスを丸ごとコピペしておく。
まだ未完成なのでセーブやロードはこれから作っていく。
最低限に近い状態のプログラムなので、改造の母体として使いやすいと思う。
ボタンの位置とかは適当なので自由にいじっても支障はない。
絵の表示場所とクリックする位置をリンクさせること。
[ObjectEditor クラス]
import java.awt.Graphics;
public class ObjectEditor {
public Graphics g;
private GameData gData=null;
public GraphicSet gSet=null;
public boolean editEnd=false;
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 mode=0;
public int[][] oData=null;
public int mapNumber=0;
public int floorNumber=0;
public int mouseX=0;
public int mouseY=0;
public int click=0;
public int mouseClicked=0;
public int mouseCX=0;
public int mouseCY=0;
public int clickC=0;
public int releaseC=0;
public int keepObjNumber=0;
public int keepNum1=0;
private final int OBJMAX=99;
public int[] setNumber=null;
public int setNumber_max=0;
public ObjectEditor() {
gData=new GameData();
gSet=new GraphicSet();
init();
}
public void init() {
editEnd=false;
mode=1;
for (int i=0;i<=59;i++) {
cursorX[i]=0;
cursorY[i]=0;
cursorPos[i]=0;
cursorMax[i]=0;
}
cursorMax[1]=99;
cursorMax[2]=9;
cursorMax[3]=10;
oData=new int[101][16];
for (int i=0;i<=99;i++) {
for (int j=0;j<=15;j++) {
oData[i][j]=0;
}
}
setNumberInit(4);
mapNumber=0;
floorNumber=0;
keepObjNumber=0;
keepNum1=0;
}
public void setNumberInit(int max) {
setNumber=new int[11];
for (int i=0;i<=10;i++) {
setNumber[i]=0;
}
setNumber_max=max;
}
public void dataSet(GameData gdt) {
init();
gData=gdt;
}
public void eventStart(GameData gdt) {
gData=gdt;
int pushKey=0;
int cPlus=0;
int modeChange=0;
mouseX=gData.pPlatform.mouseEvDragged[1];
mouseY=gData.pPlatform.mouseEvDragged[2];
click=gData.pPlatform.mouseEvDragged[0];
mouseCX=gData.pPlatform.mouseEv[1];
mouseCY=gData.pPlatform.mouseEv[2];
releaseC=gData.pPlatform.mouseEv[3];
clickC=gData.pPlatform.mouseEv[0];
if (releaseC==1 && mouseClicked==1) {
System.out.println("mouseRelease sitayo");
mouseClicked=0;
}
if (gData.pPlatform.keyPush[4]) {
gData.pPlatform.keyPush[4]=false;
pushKey=1;
gData.sePlay(1);
}
if (gData.pPlatform.keyPush[5]) {
gData.pPlatform.keyPush[5]=false;
pushKey=2;
gData.sePlay(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;
if (mode==1) cPlus=-20;
}
if (gData.pPlatform.keyPush[3]) {
gData.pPlatform.keyPush[3]=false;
if (mode==1) cPlus=20;
}
if (gData.pPlatform.keyPush[6]) {
gData.pPlatform.keyPush[6]=false;
pushKey=6;
}
if (gData.pPlatform.keyPush[7]) {
gData.pPlatform.keyPush[7]=false;
pushKey=7;
}
for (int i=10;i<=19;i++) {
if (gData.pPlatform.keyPush[i]) {
gData.pPlatform.keyPush[i]=false;
pushKey=i;
}
}
cursorPos[mode]+=cPlus;
if (cursorPos[mode] > cursorMax[mode]) cursorPos[mode]=0;
if (cursorPos[mode] < 0) cursorPos[mode]=cursorMax[mode];
int cpos=cursorPos[mode];
switch (mode) {
case 1://総合メニュー
if (pushKey==1) {
keepObjNumber=cpos;
modeChange=2;
}
if (pushKey==2) {
editEnd=true;
}
break;
case 2:
if (pushKey==1) {
oData[keepObjNumber][0]=cpos;
modeChange=3;
}
if (pushKey==2) modeChange=1;
break;
case 3:
//このコメントは数値の場所を参照するためにコピペした物。意味はない。
//basic
//public void objKariSet2(int x,int y,int shift,int granum,int evnum,int dt1,int dt2) {
//設定データを増やしたパターン。指定要素の多い場所移動イベントに使う。1行き先固定か否か 2mapnum 3floor 4x 5y 6shift
//public void objKariSet3(int x,int y,int shift,int granum,int evnum,int dt1,int dt2,int dt3,int dt4,int dt5,int dt6) {
//特殊命令セット。フラグ状態により、消したり出したりする。2とほとんど同じだが、変数の設定が一要素増えている。
//public void objKariSet4(int x,int y,int shift,int granum,int evnum,int dt1,int dt2,int dt3) {
if (pushKey==1) {
keepNum1=cpos;
setNumberInit(4);
modeChange=4; //数値入力モードに入る
}
if (pushKey==2) modeChange=2;
break;
case 4: //数値入力モード
if (pushKey==1 || pushKey==6) {
String word="";
for (int i=0;i<=setNumber_max-1;i++) {
word+=setNumber[i];
}
oData[keepObjNumber][keepNum1]=Integer.parseInt(word);
modeChange=3; //入力後は一個前に戻す。
}
if (pushKey==7) {
int[] setNumber2=new int[11];
for (int i=0;i<=10;i++) {
setNumber2[i]=0;
}
for (int i=1;i<=setNumber_max-1;i++) {
setNumber2[i]=setNumber[i-1];
}
setNumber=setNumber2;
}
if (pushKey>=10 && pushKey<=19) {
if (setNumber[0]==0) {