私はAS2からAS3 + OOPへの移行を試みているフラッシュゲーム開発者です。余分なものがたくさんありますが、私は2〜3日を過ごしていますが、いくつかのことを頭で囲んでいますが、今はそれを試して試してみたいと思っています。私が行ったように(ちょうど私がAS2でやったように)。私のクラスレスAS2プログラミングは、OOPに精通していますか?
私はOOPの(ほとんどの側面)の利点を得て、かつて私はいくつかのクラスを書いていたプロセッシングでいくつかのゲームをすることを覚悟しました。そして、私は本当に全体の継承を好きでした私が引っ越したいと思う理由、私は思う。
私はゲームの構造について質問したがっています。私の現在のAS2プログラミングの方法(以下の例をいくつかの擬似コードで示しています)は、OOPで物事を整理する方法に近いか、私が見ることができない私のゲームロジック/構造?私がAS3/OOPで違ったやり方をしなければならないことを理解する方法は、プレイヤー、ヒーロー、ミサイルなどの物を動かすためのクラスを持ち、そのクラスを拡張する敵クラスを持ってから、敵クラスではなく、それぞれの「クラス」がメインゲームループから呼び出されるオブジェクトと関数であり、代わりにサブクラスが「if」 - 各関数内に存在します。しかしそれ以外は、私のプログラミングスタイルは正しい軌道にあるのか、AS3/OOP環境で効果的に働くためには自分のコードの背後にあるロジックを再考する必要がありますか?
アドバイスをいただければ幸いです!
function initializeF() {
initializeVariablesF();
startGameF();
}
function initializeVariablesF() {
enemyO = new Object(); //which will contain each enemy instance
enemyA = new Array(); //which will be a list of all the enemies, maybe superfluous?
playerShotsA=new Array();
//and so on...
enemyDataO = new Object();
enemyDataO.goblin = new Object();
//and then some vars relating to the goblin, sort of a class without methods, right?
}
function startGameF() {
this.onEnterFrame = function() { //my game loop
checkKeysF(); //checks which keys are pressed, saves it to a global object
playerMovementF(); //moves the player about depending on which keys are pressed
playerShotsF(); //deals with the missiles/shots/lasers the player has shot
enemyCreatorF(); //decides when to create a new enemy
enemyF(); //deals with all enemies in the enemyA
enemyShotsF(); //deals with the missiles/etc the enemies have created
};
}
function enemyCreatorF(){
//randomly creates an enemy through a "factory" function:
if (random(20)==1){
attachEnemyF(enemyDataO.goblin, ...and some values like position etc)
}
}
function attachEnemyF(a_enemyType, ... a bunch of values like position){
//create a new enemy object
var enemy=enemyO[new unique enemy name]
enemy.enemyType=a_enemyType
enemy.clip=attachMovie(a_enemyType,"clip", [values like x and y passed on])
enemyA.push(enemy)
}
function playerShotsF(){
for (every shot in playerShotsA){
//move it about
for (every enemy in enemyA){
//if it hits an enemy, add damage to the enemy
}
}
}
function enemyF() {
for (every enemy in enemyA) {
//check if it's dead/less health than zero, if so remove it from the array, remove it's clip, null it's object
//if it's not, move it about, maybe have it shoot
//if it touches the player, decrease the player's health
//different behavior depending on the enemy's type by "if" or "switch" statements
}
}
1つの敵に関係するものを処理する敵クラスを作成します。また、敵クラスの関数と追跡を扱う敵クラスを作成する –