初心者のスマホ(Android)でRPG作成blog

初心者がスマホ(Android)向けのRPGゲームアプリを作っていくブログです。 アプリの作り方やPRの仕方等を試行錯誤しながら紹介して行きます。

タグ:ゲーム

はじめまして。ひでふみと申します。
2013年の1月からスマホ向けにアプリを作り始めた初心者です。
システムエンジニア等を仕事にしていますが、プログラミングはまったくの素人で、
むしろJavaを覚えたくてアプリ作りを始めた位の感じです・・・。

ここまで1年掛けて3作のアプリを公開するまでに至った訳なのですが、
 趣味とはいえ細々とやっても喜ばせれる人があまりに少ないと感じています。
もっと多くの人に楽しんで貰い、意見を貰って更に良い作品を作って行くには、
多くの人の目につく機会が必要と考えてlivedoorブログを始める事にしました。

 これが切っ掛けで多くの人と触れ合うことが出来ると嬉しいです。
それではこれから長く続けて行きたいと考えていますので宜しくお願いします。 

■イビル・スレイヤー
https://play.google.com/store/apps/details?id=com.hidefumi.kasahara.evel_slayer
■サモン・ファミリア
https://play.google.com/store/apps/details?id=com.hidefumi.kasahara.familiar_rpg
■Tower_RPG
https://play.google.com/store/apps/details?id=com.test.example.tower_rpg1


ゲーム制作 ブログランキングへ

多くの人に見て貰える様にランキングへのご協力をお願いします!

ゲーム制作 ブログランキングへ

説明画面のJavaソースとなります。

 HelpActivityというアクティビティ内に以下の処理が含まれています。
<処理内容>
・onCreate : 画面の初期作成処理(レイアウトファイルの読み込み等)
・showDialog : 画面に文字をポップアップさせるプログラム(他のプログラムに呼ばれる)
・onClickXX : 格ボタン毎の処理内容を設定(XXは数字が入る)

クラスの設定開始直後に以下の記載がありますが、
これは「BR」という変数は今後改行を意味するという設定です。
(文字列の表示に改行を入れたい場合は宣言しておくと便利)

 private final static String BR=System.getProperty("line.separator");

今後紹介するJavaファイルでは良く利用する表示方法なのですが、
onCreateの中で「textView1~3」「button1~10」に対して、
「textSetting.setText」で文字列を表示させています。

これにより画面が開いた直後に各ボタンやタイトルに文字が表示され、
「開始」用のボタンだったり、「終了」用のボタンというのがすぐにわかります。

それとこのJavaプログラムの処理は非常にシンプルな作りになっていて、
「終了」ボタンである「onClick0」は「finish()」でアクティビティを終了させ、
その他は「showDialog」で解説用の説明文を表示させるだけです。

簡単な処理から説明を行っていますが、よくわからないという方は
メールやコメント等を頂ければ説明致しますのでご連絡をお願いします!


■HelpActivity.java(Javaファイル)

package com.hidefumi.kasahara.evel_slayer;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

public class HelpActivity extends Activity {
private final static String BR=System.getProperty("line.separator");

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.help);
//文字列表示
TextView textSetting = (TextView)findViewById(R.id.textView1);
    textSetting.setText("《基本情報》");
//文字列表示
TextView textSetting2 = (TextView)findViewById(R.id.textView2);
   textSetting2.setText("《戦闘画面情報》");
//文字列表示
TextView textSetting3 = (TextView)findViewById(R.id.textView3);
   textSetting3.setText("《移動画面情報》");
   
//「目的」の説明
TextView textSettingb01 = (TextView)findViewById(R.id.button1);
   textSettingb01.setText("目的");
//「依頼」の説明
TextView textSettingb02 = (TextView)findViewById(R.id.button2);
   textSettingb02.setText("依頼");
//「能力」の説明
TextView textSettingb03 = (TextView)findViewById(R.id.button3);
   textSettingb03.setText("ステータス");

   //「攻撃」の説明
TextView textSettingb04 = (TextView)findViewById(R.id.button4);
   textSettingb04.setText("攻撃");
//「魔法」の説明
TextView textSettingb05 = (TextView)findViewById(R.id.button5);
   textSettingb05.setText("剣技");
//「回復」の説明
TextView textSettingb06 = (TextView)findViewById(R.id.button6);
   textSettingb06.setText("回復");
//「契約」の説明
TextView textSettingb7 = (TextView)findViewById(R.id.button7);
   textSettingb7.setText("契約");

   //「探索」の説明
TextView textSettingb08 = (TextView)findViewById(R.id.button8);
   textSettingb08.setText("探索");
//「帰還」の説明
TextView textSettingb09 = (TextView)findViewById(R.id.button9);
   textSettingb09.setText("帰還");
//「情報」の説明
TextView textSettingb10 = (TextView)findViewById(R.id.button10);
   textSettingb10.setText("情報");
}

//showDialogの実装
private void showDialog(HelpActivity mainActivity, String title,String text) {
AlertDialog.Builder ad=new AlertDialog.Builder(mainActivity);
ad.setTitle(title);
ad.setMessage(text);
ad.setPositiveButton("OK", null);
ad.show();
}
//「戻る」コマンド実行処理
public void onClick0(View view){
finish() ;
}

//「目的」解説コマンド
public void onClick1(View view){
showDialog(HelpActivity.this,"目的","シナリオのクリアが目的となります。"+BR+BR+"各章の選択肢によりエンディングが変化します。");
}
//「依頼」解説コマンド
public void onClick2(View view){
showDialog(HelpActivity.this,"依頼","各章で達成すべき目的です。"+BR+BR+"酒場で悪魔の討伐等を依頼されます。");
}
//「ステータス」解説コマンド
public void onClick3(View view){
showDialog(HelpActivity.this,"ステータス","[HP]"+BR+"体力。"+BR+"0になると戦闘不能。"+BR+"HPが0になるとお金を奪われ、酒場に強制送還されます。"+BR+BR+"[SP]"+BR+"精神力。"+BR+"剣技利用時に必要。"+BR+BR+"[ATK]"+BR+"攻撃力。"+BR+"攻撃利用時のダメージ量。");
}
//「攻撃」解説コマンド
public void onClick4(View view){
showDialog(HelpActivity.this,"攻撃","通常攻撃です。"+BR+"ATK+武器能力のダメージを与えます。");
}
//「剣技」解説コマンド
public void onClick5(View view){
showDialog(HelpActivity.this,"技能","習得した剣技を使用します。"+BR+BR+"剣技は一定数利用すると成長します。");
}
//「回復」解説コマンド
public void onClick6(View view){
showDialog(HelpActivity.this,"回復","HPを全回復します。"+BR+BR+"ただし、回復には傷薬が一つ必要です。");
}
//「契約」解説コマンド
public void onClick7(View view){
showDialog(HelpActivity.this,"契約","悪魔と契約して使い魔にする事が出来ます。"+BR+BR+"悪魔はそれぞれに異なる能力を持っています。"+BR+"また、情報画面より魔石を一定数付与すると能力が変化します。"+BR+BR+"契約には魔石が必要です。");
}

//「探索」解説コマンド
public void onClick8(View view){
showDialog(HelpActivity.this,"探索","攻略エリアを探索します。"+BR+"100回の探索で現在のエリアを攻略します。"+BR+BR+"また、モンスターとの戦闘やアイテム取得等のイベントも発生します。");
}
//「帰還」解説コマンド
public void onClick9(View view){
showDialog(HelpActivity.this,"帰還","エリアの攻略を中断し、酒場に戻ります。");
}
//「情報」解説コマンド
public void onClick10(View view){
showDialog(HelpActivity.this,"情報","ステータスや所持品等の各種情報を参照します。");
}


■イビル・スレイヤー
https://play.google.com/store/apps/details?id=com.hidefumi.kasahara.evel_slayer 

多くの人に見て貰える様にランキングへのご協力をお願いします!

ゲーム制作 ブログランキングへ

次に紹介するには説明画面のレイアウトファイル。
時際のプログラムであるJavaファイルは2-2で別途説明します。

用途は操作や言葉がわからない時に確認する、良くあるHelp画面ですね。
MainActivity(1-1を参照)の「説明」ボタンを押すと表示されます。

作りは非常に簡単なもので、説明用にサブタイトルの「
ScrollView」と
説明文を表示する為のボタンとして「Button」を縦に並べるだけです。

後は「
ScrollView」で全体を囲う事で画面からはみ出しても、
スクロールする事で全てを表示可能にしていますね。

画像ファイルである「
frame」は黄色枠のフレームでテキスト表示の際に利用。
画像ファイルである「
frame2」は赤枠でボタンの際に利用しています。

一番最後の「終了」ボタンだけは固定なので「
@string/end_button」を使い、
レイアウト側で中に文字を表示させています。
ただ、2種類の表示方法があると面倒という場合は、その他の文字列と同じく
Javaファイルで全て表示させても良いかと思います。


■help.xml


<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#000000"
    android:orientation="vertical" >
    
<LinearLayout 
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@drawable/frame"
        android:gravity="center"
        android:textSize="25sp"
        android:textStyle="italic" />
    
    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/frame2"
        android:onClick="onClick1"
        android:textSize="30sp" />

    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/frame2"
        android:onClick="onClick2"
        android:textSize="30sp" />
    <Button
        android:id="@+id/button3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/frame2"
        android:onClick="onClick3"
        android:textSize="30sp" />
     
    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:background="@drawable/frame"
        android:gravity="center"
        android:textSize="30sp"
        android:textStyle="italic" />
    
       <Button
       android:id="@+id/button4"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:background="@drawable/frame2"
       android:onClick="onClick4"
       android:textSize="30sp" />
       <Button
       android:id="@+id/button5"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:background="@drawable/frame2"
       android:onClick="onClick5"
       android:textSize="30sp" />
      <Button
        android:id="@+id/button6"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/frame2"
        android:onClick="onClick6"
        android:textSize="30sp" />

       <Button
       android:id="@+id/button7"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:background="@drawable/frame2"
       android:onClick="onClick7"
       android:textSize="30sp" />
       
      <TextView
        android:id="@+id/textView3"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:background="@drawable/frame"
        android:gravity="center"
        android:textSize="30sp"
        android:textStyle="italic" />
    
   <Button
       android:id="@+id/button8"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:background="@drawable/frame2"
       android:onClick="onClick8"
       android:textSize="30sp" />
      <Button
        android:id="@+id/button9"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/frame2"
        android:onClick="onClick9"
        android:textSize="30sp" />
       <Button
       android:id="@+id/button10"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:background="@drawable/frame2"
       android:onClick="onClick10"
       android:textSize="30sp" />
       
    <Button
        android:id="@+id/button0"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/frame2"
        android:onClick="onClick0"
        android:text="@string/end_button"
        android:textColor="#990000"
        android:textSize="30sp" />
       
</LinearLayout>
</ScrollView>

補足)
 @string/end_button = 終了

■イビル・スレイヤー
https://play.google.com/store/apps/details?id=com.hidefumi.kasahara.evel_slayer


■完成画面
 

Screenshot_2014-01-18-18-15-19
 

多くの人に見て貰える様にランキングへのご協力をお願いします!

ゲーム制作 ブログランキングへ

スタート画面のJavaソースファイルになります。

 MainActivityというアクティビティに中に以下の処理が含まれています。
<処理内容>
・onCreate : 画面の初期作成処理(レイアウトファイルの読み込み等)
・showYesNoDialog : Yes/No選択肢を表示するプログラム(他のプログラムに呼ばれる)
・showDialog : 画面に文字をポップアップさせるプログラム(他のプログラムに呼ばれる)
・onClick1 : 1番のボタンを押した際のプログラム
・onClick2 : 2番のボタンを押した際のプログラム
・onClick3 : 3番のボタンを押した際のプログラム
・onClick4 : 4番のボタンを押した際のプログラム
・onActivityResult : startActivityForResultで画面が移った際の戻り処理

細かなポイントとしては、画面を「図鑑」や「解説」画面に移動する際は、
「startActivity」を使ってただMainActivityの上に表示させています。

それに対して「開始」ボタンの場合は「startActivityForResult」を使い、
「onActivityResult」による画面が戻った際の処理を行う様にさせています。

これはゲーム開始後のメイン画面で「終了」ボタンを押した際に、
再びスタート画面を表示させない様にする為の工夫です。
(「終了」を押したのに終わらないとイラっとしますよね?)

それとボタン4の「初期化」ではアイテム数やイベントフラグ等の
ゲームに関するデータを消去する処理を組み込んでいます。

ポイントという程では無いですが、私の場合はここにパラメータを入れる事で、
利用中のパラメータ初期値を管理したり、パラメータの修正漏れが無い様に
チェックしたりしています。


■MainActivity.java(Javaファイル)

package com.hidefumi.kasahara.evel_slayer;

import android.os.Bundle;
import android.preference.PreferenceManager;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.view.Menu;
import android.view.View;
import android.view.Window;

public class MainActivity extends Activity {
private final int REQUEST_CODE = 111;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
}
//YesNoDialog実装
private void showYesNoDialog(MainActivity mainActivity, String title,
String text, DialogInterface.OnClickListener listener) {
AlertDialog.Builder ad=new AlertDialog.Builder(mainActivity);
ad.setTitle(title);
ad.setMessage(text);
ad.setPositiveButton("YES", listener);
ad.setNegativeButton("NO", listener);
ad.show();
}
//ShowDialog実装
private void showDialog(MainActivity mainActivity, String title,String text) {
AlertDialog.Builder ad=new AlertDialog.Builder(mainActivity);
ad.setTitle(title);
ad.setMessage(text);
ad.setPositiveButton("OK", null);
ad.show();
}

//「開始」コマンド実行処理
public void onClick1(View view){
Intent intent = new Intent(MainActivity.this, SubActivity.class);
startActivityForResult(intent, REQUEST_CODE);
}

//「説明」コマンド実行処理
public void onClick2(View view){
Intent intent = new Intent();
intent.setClassName("com.hidefumi.kasahara.evel_slayer", "com.hidefumi.kasahara.evel_slayer.HelpActivity");
startActivity(intent);
}
//「図鑑」コマンド実行処理
public void onClick3(View view){
Intent intent = new Intent();
intent.setClassName("com.hidefumi.kasahara.evel_slayer", "com.hidefumi.kasahara.evel_slayer.BookActivity");
startActivity(intent);
}
//「初期化」コマンド実行処理
public void onClick4(View view){
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
showYesNoDialog(this, "初期化", "これまでのデータを消去しますか?",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which==DialogInterface.BUTTON_POSITIVE){
showDialog(MainActivity.this,"初期化","データを初期化しました");
Editor editor = sharedPreferences.edit();
editor.putInt("EV_MAIN", 0);
editor.putInt("STAGE", 1);
editor.putInt("AREA", 1);
editor.putInt("MAJIN", 0);
editor.putInt("LV", 1);
editor.putInt("EXP", 0);
editor.putInt("HP", 20);
editor.putInt("MHP", 20);
editor.putInt("SP", 10);
editor.putInt("MSP", 10);
editor.putInt("ATK", 2);
editor.putInt("WEPON", 1);
editor.putInt("SKILL_LV", 1);
editor.putInt("SKILL_EXP", 0);
editor.putInt("DRAG", 3);
editor.putInt("STONE", 3);
editor.putInt("LIFE", 0);
editor.putInt("GOLD", 100);
editor.putInt("EXP", 0);
editor.putInt("SEL_FAM", 1);
editor.putInt("FMLA", 0);
editor.putInt("FAM01", 0);
editor.putInt("FAM02", 0);
editor.putInt("FAM03", 0);
editor.putInt("FAM04", 0);
editor.putInt("FAM05", 0);
editor.putInt("FAM06", 0);
editor.putInt("FAM07", 0);
editor.putInt("FAM08", 0);
editor.putInt("FAM09", 0);
editor.putInt("FAM10", 0);
editor.putInt("FAM11", 0);
editor.putInt("FAM12", 0);
editor.putInt("FAM13", 0);
editor.putInt("FAM14", 0);
editor.putInt("FAM15", 0);
editor.putInt("FAM16", 0);
editor.putInt("FAM17", 0);
editor.putInt("FAM18", 0);
editor.putInt("SKILL_LV_MOB01", 1);
editor.putInt("SKILL_LV_MOB02", 1);
editor.putInt("SKILL_LV_MOB03", 1);
editor.putInt("SKILL_LV_MOB04", 1);
editor.putInt("SKILL_LV_MOB05", 1);
editor.putInt("SKILL_LV_MOB06", 1);
editor.putInt("SKILL_LV_MOB07", 1);
editor.putInt("SKILL_LV_MOB08", 1);
editor.putInt("SKILL_LV_MOB09", 1);
editor.putInt("SKILL_LV_MOB10", 1);
editor.putInt("SKILL_LV_MOB11", 1);
editor.putInt("SKILL_LV_MOB12", 1);
editor.putInt("SKILL_LV_MOB13", 1);
editor.putInt("SKILL_LV_MOB14", 1);
editor.putInt("SKILL_LV_MOB15", 1);
editor.putInt("SKILL_LV_MOB16", 1);
editor.putInt("SKILL_LV_MOB17", 1);
editor.putInt("SKILL_LV_MOB18", 1);
editor.putInt("SKILL_EXP_MOB01", 0);
editor.putInt("SKILL_EXP_MOB02", 0);
editor.putInt("SKILL_EXP_MOB03", 0);
editor.putInt("SKILL_EXP_MOB04", 0);
editor.putInt("SKILL_EXP_MOB05", 0);
editor.putInt("SKILL_EXP_MOB06", 0);
editor.putInt("SKILL_EXP_MOB07", 0);
editor.putInt("SKILL_EXP_MOB08", 0);
editor.putInt("SKILL_EXP_MOB09", 0);
editor.putInt("SKILL_EXP_MOB10", 0);
editor.putInt("SKILL_EXP_MOB11", 0);
editor.putInt("SKILL_EXP_MOB12", 0);
editor.putInt("SKILL_EXP_MOB13", 0);
editor.putInt("SKILL_EXP_MOB14", 0);
editor.putInt("SKILL_EXP_MOB15", 0);
editor.putInt("SKILL_EXP_MOB16", 0);
editor.putInt("SKILL_EXP_MOB17", 0);
editor.putInt("SKILL_EXP_MOB18", 0); editor.commit();
} else if (which==DialogInterface.BUTTON_NEGATIVE){
showDialog(MainActivity.this,"初期化","初期化をキャンセルしました");
}
}
}
);
}
@Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
   finish();
}
}
 
■イビル・スレイヤー
https://play.google.com/store/apps/details?id=com.hidefumi.kasahara.evel_slayer

多くの人に見て貰える様にランキングへのご協力をお願いします!

ゲーム制作 ブログランキングへ

まずはアプリの顔であるスタート画面のソースから公開して行きます。

「openning」という画像ファイル(剣とタイトル)を背景に設定し、
ボタンを横に2個×2段の配置を行っています。
(「frame3」がボタンに利用している画像)

実際にボタンを押した際の処理は別途Javaファイルに記載される為、
こちらは本当にレイアウトだけの内容となりますね。
(Javaファイルは1-2として別途公開します)

■MainActivity(レイアウトファイル)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/openning"
    android:gravity="bottom|center|clip_vertical"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center" >
        
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/frame3"
        android:onClick="onClick1"
android:layout_weight="1"
        android:text="@string/start_button"
        android:textColor="#990000"
        android:textSize="25sp" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/frame3"
        android:onClick="onClick2"
android:layout_weight="1"
        android:text="@string/help_button"
        android:textColor="#990000"
        android:textSize="25sp" />
    
    </LinearLayout>
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center" >
        
    <Button
        android:id="@+id/button3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/frame3"
        android:onClick="onClick3"
        android:text="@string/Library_button"
        android:textColor="#990000"
        android:textSize="25sp" />

    <Button
        android:id="@+id/button4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/frame3"
        android:onClick="onClick4"
android:layout_weight="1"
        android:text="@string/Delete_button"
        android:textColor="#990000"
        android:textSize="25sp" />
    
    </LinearLayout>
        
</LinearLayout> 

補足)
 @string/start_button = 開始
 @string/help_button = 説明
 @string/Library_button = 図鑑
 @string/Delete_button = 消去

■完成画面
Screenshot_2014-01-05-09-49-34
 

↑このページのトップヘ