I am currently working on enhancing the classic game Duck Hunt by adding different characters to different levels. I have obtained the original source code from GitHub (https://github.com/MattSurabian/DuckHunt-JS) and have successfully created 3 levels with unique .png files for each level through CSS. However, I am unsure about where in the JavaScript scripting to make adjustments so that each level features a different character. My assumption is that I will need to use an if statement specifying the character based on the level ID.
The section of JavaScript code below is responsible for handling the ducks (duckA / duckB):
{var e=t%2===0?"duckA":"duckB";this.duckMax++,this.liveDucks.push(new Duck(this.duckMax.toString(),e,this.level.speed,this.playfield).fly())}},
killDuck:function(t){this.levelStats.ducksKilled+=1,this.liveDucks=_(this.liveDucks).reject(function(e){return e.id===t.id}),
0===this.liveDucks.length&&this.playfield.trigger("wave:end",this.curWave)},
drawDucks:function(){var t="",e=this.level.ducks*this.curWave-this.levelStats.ducksKilled;e=e>25?25:e;
Here are the details of the Levels:
levels=[
{id:1,title:"Level 1",waves:1,ducks:10,pointsPerDuck:100,speed:2,bullets:15,time:25},
{id:2,title:"Level 2",waves:1,ducks:10,pointsPerDuck:150,speed:4,bullets:15,time:20},
{id:3,title:"Level 3",waves:1,ducks:10,pointsPerDuck:200,speed:6,bullets:15,time:18}],
I aim to introduce duckC / duckD in Level 2 (id 2) and duckE / duckF in Level 3 (id 3). Can anyone provide assistance?
UPDATE:
I have made modifications to the sections of code in duckhunt.min.js as shown below, but only the default two ducks are being loaded. Any thoughts on why this might be happening?
Duck.prototype.hatch=function(){
$('<div id="'+this.id+'" class="duck1 '+this.className+'"></div>').appendTo(this.game),
this.DOM=$("#"+this.id),
this.bindEvents()
$('<div id="'+this.id+'" class="duck2 '+this.className+'"></div>').appendTo(this.game),
this.DOM=$("#"+this.id),
this.bindEvents()},
releaseDucks:function(){
for(var t=0;t<this.level.ducks;t++)
{var e=t%2===0?"duckA":"duckB";
this.duckMax++,
this.liveDucks.push(new Duck(this.duckMax.toString(),e,this.level.speed,this.playfield).fly())
}
{var e=t%2===0?"duckC":"duckD";
this.duckMax++,
this.liveDucks.push(new Duck(this.duckMax.toString(),e,this.level.speed,this.playfield).fly())
}
},