LoginSignup
0
0

More than 1 year has passed since last update.

SKT豆腐屋と「Screeps: Arena」 のチュートリアル#3「First attack」を進めよう

Posted at

Screeps: Arenaとは

 「JavaScript」などのプログラミング言語を使って自軍の「駒」を動かし他プレイヤーと戦うゲーム
Steamからダウンロードできる。https://store.steampowered.com/app/1137320/Screeps_Arena/?l=japanese
Screepsの公式discordはこちら(英語):https://discord.gg/screeps
超全茶discord(日本語)では一緒に楽しみたい人を募集中:https://discord.gg/Am9Rz4w (discord)

Screeps: Arenaのチュートリアルを始めよう

コメント付きサンプルコード #3「First attack」

import { } from '/game/utils';
import { } from '/game/prototypes';
import { } from '/game/constants';
import { } from '/arena';

//指定した種類のオブジェクトを全て取得する関数を使えるようにインポート
import { getObjectsByPrototype } from '/game/utils';
//駒「Creep」を使えるようにインポート
import { Creep } from '/game/prototypes';
//「射程範囲外エラー」定数を使えるようにインポート
import { ERR_NOT_IN_RANGE } from '/game/constants';

export function loop() {

    //自軍の駒を取得する
    var myCreep = getObjectsByPrototype(Creep).find(creep => creep.my);
    //敵軍の駒を取得する
    var enemyCreep = getObjectsByPrototype(Creep).find(creep => !creep.my);
    
    //自軍の駒で敵軍の駒を攻撃する。結果が、射程外エラーなら敵軍の駒に向かって進む
    if(myCreep.attack(enemyCreep) == ERR_NOT_IN_RANGE) {
        myCreep.moveTo(enemyCreep);
    }
}

実行結果

image.png

first_attack.gif

以上

よかったよかった

0
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
0
0