1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

自作ニコ生ゲームのテンプレート 【魔物社長の簡易版】

Posted at

akashic init -t javascript-shin-ichiba-ranking

このコマンドでテンプレートを作成することはできた!でも、いらない部分削るのとかめんどくさい・・

なのでテンプレートとしてよく使ってるコードを記載します。

ただ前準備がいるのでまずはその説明から!

image.png

↑これがコマンドで生成した直後のフォルダ内。これを・・・

こうする↓

image.png

※やったこと
text、 images、 audioのフォルダを削除してassetsフォルダを追加

その作ったassetsフォルダの中に
audio, images, textのフォルダを作る。
※今後素材追加するときは
SEやBGMならaudio、
キャラ画像やアイテムの画像とかはimageに保存するよ。
自分はtextフォルダ基本使わないから作らないよ。

image.png

これで前準備終わり。

この時点で使いたい画像、SEがあったら対応したフォルダに入れて

akashic scan assetしておいてね!

ここからがテンプレート改造版

main.js

exports.main = void 0;
function main(param) {
    const scene = new g.Scene({
        game: g.game,
        // このシーンで利用するアセットのIDを列挙し、シーンに通知します
        assetPaths: [

            "/assets/images/player.png",

        ]
    });
    let time = 60; // 制限時間
    if (param.sessionParameter.totalTimeLimit) {
        time = param.sessionParameter.totalTimeLimit; // セッションパラメータで制限時間が指定されたらその値を使用します
    }
    // 市場コンテンツのランキングモードでは、g.game.vars.gameState.score の値をスコアとして扱います
    g.game.vars.gameState = { score: 0 };
    scene.onLoad.add(() => {
        // ここからゲーム内容を記述します
        // 各アセットオブジェクトを取得します

        //フォントに縁取り
        let borderFont = new g.DynamicFont({
            game: scene.game,
            fontFamily: "UD デジタル 教科書体 NP-B",      //任意のフォント
            fontColor: "#FFF", strokeColor: "#657cb3ff",   //fontColorが文字の色、strokeCOlorが縁の色
            strokeWidth: 6,  //ここの数字が縁の太さ
            size: 60         //文字の大きさ
        });
       
        // プレイヤーを生成します
        const player = new g.Sprite({
            scene: scene,
            src: scene.asset.getImage("/assets/images/player.png"),
            x: -100, y: 100
        });
        scene.append(player);
        
       
        // スコア表示用のラベル
        const scoreLabel = new g.Label({
            scene: scene,
            text: "SCORE: 0",
            font: borderFont,
            x: 20, y: 10
        });
        scene.append(scoreLabel);
        // 残り時間表示用ラベル
        const timeLabel = new g.Label({
            scene: scene,
            text: "TIME: 0",
            font: borderFont,
            x: 1000, y: 10
        });
        scene.append(timeLabel);

        /* 関数 */
        function addScore(add){
                g.game.vars.gameState.score+=add;
                scoreLabel.text = "SCORE: " + g.game.vars.gameState.score;
                scoreLabel.invalidate();
        }

        // ↑ スコアの加点減点を単純にしたやつ

        /* 使い方 */
         
        // 処理を実行したい場所でaddScore()を記載する。
        // ()の中に任意の数字を入れる。
        // addScore(10); こうすると10加点 ※1
        // addScore(-10); こうすると10減点
        
        
        // 画面をタッチしたとき、SEを鳴らします
        scene.onPointDownCapture.add(() => {
            // 制限時間以内であればタッチ1回ごとにSCOREに+10します
            if (time > 0) {
               addScore(10);  // ※1
            }
         
        });
        const updateHandler = () => {
            if (time <= 0) {
                scene.onUpdate.remove(updateHandler); // カウントダウンを止めるためにこのイベントハンドラを削除します
            }
            // カウントダウン処理
            time -= 1 / g.game.fps;
            timeLabel.text = "TIME: " + Math.ceil(time);
            timeLabel.invalidate();
        };
        scene.onUpdate.add(updateHandler);
        // ここまでゲーム内容を記述します
    });
    g.game.pushScene(scene);
}
exports.main = main;


画像は自分で用意したものだけどこれを実行したときはこんな感じになるよ!
image.png

※本当はfunction(関数)をもう少し作って楽にするけど混乱しないようになるべくそのままで削っています。
assetID追加する部分がいつもと違う!?って感じた方は公式のこのページに詳しい説明が載ってるので見てみてね↓
https://akashic-games.github.io/shin-ichiba/breakout/getting-started.html

人それぞれの好みの問題だと思うけど、自分はこのやり方がいい気がする!詳しいことはわかんないけど、とにかくいい気がする!

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?