//#define APPLET
/*-------------------------------------
タイトル:勇者で行こう!Ω ver 0.01
制作:ハルーポッター
HomePage: http://www.ar.wakwak.com/~harupotter/
動作機種:imode503i,504iシリーズ、Javaアプレット
[コンパイル方法]
アプレットにする場合は、一番上の行を
#define APPLET
とする。
iアプリにする場合は、
//#define APPLET
とする。
そして、PPP(Pamuow Preprocessor)を使用する。DL先・・・http://www.and.or.jp/~pamulow/ppp/ppp.html
[使い方]
ppp 入力フォルダ 出力フォルダ
例:ppp . src
[アプレットの場合にHTMLファイルに記述するタグ]
ーーーーーー---------------------------*/
#ifdef APPLET
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
#else
import com.nttdocomo.ui.*;
#endif
//セルクラス
class Cell{
int gra;//グラフィックデータ
int event;//イベント
boolean move_flag;//通過可能フラグ
Cell(int a,int b,boolean c){
gra=a;event=b;move_flag=c;
}
}
#ifndef APPLET
//ポイントクラス
class Point{
int x,y;
Point(int a,int b){x=a;y=b;}
};
//本体
public class Rpg extends IApplication{
//アプリの開始
public void start() {
Display.setCurrent(new RpgCanvas());
}
}
#endif
#ifdef APPLET
public class Rpg extends Applet implements KeyListener{
#else
class RpgCanvas extends Canvas{
#endif
Graphics bufferg;
Image hero;//勇者画像
Image map_image;//マップ画像
#ifdef APPLET
Image buffer;//バッファ
AudioClip se[] = new AudioClip[5];//効果音
#endif
final int WIDTH=7;
final int HEIGHT=6;
final int WPIXEL=120;
final int HPIXEL=130;
Cell celldata[] = {
new Cell(0,0,true),
new Cell(1,0,true),
new Cell(2,0,true),
new Cell(3,1,true),//ハウスワープ
new Cell(4,0,false),
new Cell(5,0,true),
new Cell(6,0,true),
new Cell(7,4,true),//洞窟
new Cell(8,0,false),
new Cell(10,0,false),
new Cell(9,0,true),
new Cell(1,2,true),//外ワープ
new Cell(11,3,true),//手紙
};
//マップデータ(7*6)
int mapdata[][] = {
{1,1,1,1,1, 1,1},
{1,1,1,1,2, 1,1},
{1,1,1,3,1, 1,1},
{1,1,1,1,1, 1,5},
{1,4,1,1,2, 1,1},
{1,1,7,1,1, 1,6},
};
//家マップデータ(7*6)
int housemapdata[][] = {
{ 9, 9, 9, 9, 9, 9, 9},
{ 9,10,10,12,10,10, 9},
{ 9,10,10,10,10,10, 9},
{ 9,10,10,10,10,10, 9},
{ 9,10,10,10,10,10, 9},
{ 9, 9,11,11,11, 9, 9},
};
int now_map,now_string;//現在マップ、現在文字列
Point My = new Point(16,16);//勇者座標
boolean PushFlag=false;//キーを押した状態であるか
//初期化
#ifdef APPLET
public void init(){
//ロード
hero=getImage(getDocumentBase(),"hero.gif");
map_image=getImage(getDocumentBase(),"map.gif");
se[0] = getAudioClip(getDocumentBase(),"se1.au");
se[1] = getAudioClip(getDocumentBase(),"se2.au");
addKeyListener(this);
requestFocus();//フォーカス取得
buffer = createImage(WPIXEL,HPIXEL);
#else
RpgCanvas(){
//ロード
try{
MediaImage m;
m=MediaManager.getImage("resource:///hero.gif");
m.use();
hero=m.getImage();
}catch(Exception e){e.printStackTrace();}
try{
MediaImage m;
m=MediaManager.getImage("resource:///map.gif");
m.use();
map_image=m.getImage();
}catch(Exception e){e.printStackTrace();}
#endif
now_map=0;
now_string=1;
}
//描画
public void paint(Graphics g){
int i,j;
int map;
String str,str2;
//描画領域のロック
#ifdef APPLET
if(bufferg==null){bufferg=buffer.getGraphics();}
#else
bufferg=g;
bufferg.lock();
#endif
//背景色の設定
#ifdef APPLET
bufferg.setColor(Color.black);
#else
bufferg.setColor(bufferg.getColorOfName(bufferg.BLACK));
#endif
bufferg.fillRect(0,0,WPIXEL,HPIXEL);
//背景(マップ)
for(i=0;i=2)return false;//会話中の時
//限界値
if(x/16 == -1 || y/16 == -1 || x/16 == WIDTH || y/16 == HEIGHT)return false;
switch(now_map){
case 0:cell = mapdata[y/16][x/16];break;
case 1:cell = housemapdata[y/16][x/16];break;
default:cell=0;break;
}
if(celldata[cell].move_flag){return true;}
else{return false;}
}
//イベント発生
public void map_event(int x,int y){
int cell;
boolean move_flag=false;
switch(now_map){
case 0:cell = mapdata[y/16][x/16];break;
case 1:cell = housemapdata[y/16][x/16];break;
default:cell=0;break;
}
switch(celldata[cell].event){
case 0:break;
case 1:now_map=1;My.x=16*3;My.y=16*4;move_flag=true;break;//外からハウスへ移動
case 2:now_map=0;My.x=16*3;My.y=16*3;move_flag=true;break;//ハウスから外へ移動
default:break;
}
#ifdef APPLET
if(move_flag){se[0].play();}
#endif
}
//調べる
public void map_search(int x,int y){
int cell;
#ifdef APPLET
se[1].play();
#endif
switch(now_map){
case 0:cell = mapdata[y/16][x/16];break;
case 1:cell = housemapdata[y/16][x/16];break;
default:cell=0;break;
}
//会話スキップ
switch(now_string){
case 2:now_string=3;return;
case 3:now_string=0;return;
case 4:now_string=5;return;
case 5:now_string=0;return;
}
switch(celldata[cell].event){
case 3:now_string=2;break;
case 4:now_string=4;break;
default:now_string=0;break;
}
}
#ifdef APPLET
public void keyTyped(KeyEvent e){}//押した瞬間
public void keyReleased(KeyEvent e){PushFlag=false;}//放された瞬間
public void update(Graphics g){paint(g);}
#endif
}