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

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

はじめまして。ひでふみです。
趣味でスマホ(Android)RPG系のゲームを作成しています。
アプリの作り方等についても初心者なりに紹介していこうと考えています。
皆さんにとって楽しい一時を提供できると幸いです♪

■作成アプリ紹介
・イビル・スレイヤー:3作目のダンジョンRPG(悪魔と契約&図鑑作成)
・サモン・ファミリア:2作目の学園物RPG(ギャグが大目)
・Tower_RPG:1作目のダンジョンRPG(ひたすら塔を攻略)

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

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

スタート画面の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
 

■作品名:イビル・スレイヤー
■ジャンル:ダンジョンRPG
■価格:無料
■リリース時期:2014年1月

■ゲームの特徴
 ・主人公ムットと神剣リクトの物語
 ・悪魔を狩りながらサクサクとダンジョンを突き進みます
 ・魔石を使い悪魔を使い魔として従える事が出来ます
 ・悪魔を従えると悪魔図鑑が埋まって行きます

■コメント
 作者の作成する3作目のアプリです。
 「世界樹の迷宮」の様な、本格的な作品を作ってみたいと頑張りました。
 同ジャンルが好きな人に楽しんで貰えると嬉しいです。


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

<スタート画面>
Screenshot_2014-01-05-09-49-34

<戦闘画面>
Screenshot_2014-01-10-22-15-21


↑このページのトップヘ