I'm working on a game which I'm writing in Javascript and then porting to iOS/Android via phonegap/cordova.
For the most part, I understand how to code and how to get what I want to happen, BUT I have a major struggling point in using proper techniques and avoiding redundancy and over-complexity.
For example, one of my first forays into game dev, I had tried to answer a question on how to simplify a set of actions or functions that are related (you can check out my bad answer here How can I design lots of different attack types that can be combined? )
Now, I'm sort of at a similar pass at my game, I have different 'enemy types' that are supposed to trigger a different action when they touch the player. I have a if/else structure right now to change between these different circumstances.
Sean Middleditch did a good job of answering why 'data-driven' design works better than 'procedural' design, but for the life of me I can't figure out HOW to employ this. It seems to me that no matter how I want to structure my objects in my game, and which properties I give them, at some point I will need an if/else or switch statement, can anyone help me work past this?
if(enemyType == 'black'){ // enemyType is a color
done(index); // done is a function that removes the enemy after it touches the player
updateScore(score); // black is score point so it updates score
}else if(enemyType == 'red'){ // red is a death so gameOver
done(index);
if(!gameVars.invincible && gameVars.lives == 1){ // but the player might be invincible or have extra lives
gameOver();
}else if (!gameVars.invincible){ // in that case we manage the lives or ignore the hit completely
manageLives(-1);
}
}else if(enemyType == 'blue'){ // the rest are power ups of types
done(index);
setInvincible();
}else if(enemyType == 'grey'){
done(index);
setSlowTime();
}else if (enemyType == 'green') {
done(index);
gameVars.teir_reducer += 2;
}else if (enemyType == 'yellow') {
done(index);
gameVars.speed_reducer += 10;
}else if (enemyType == 'orange') {
done(index);
updateScore(1000);
}else if (enemyType == 'purple') {
done(index);
manageLives(1);
}else if (enemyType == 'violet') {
done(index);
setMagenetic();
}else if (enemyType == 'gainsboro') {
done(index);
setWarp();
}