===================================================================
--- original.js
+++ change.js
@@ -1,7 +1,22 @@
/****
* Classes
****/
+// Define the Cactus class
+var Cactus = Container.expand(function () {
+ var self = Container.call(this);
+ var cactusGraphics = self.attachAsset('cactus', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 5;
+ self.update = function () {
+ self.x -= self.speed;
+ if (self.x < -self.width) {
+ self.destroy();
+ }
+ };
+});
// Define the Floor class
var Floor = Container.expand(function () {
var self = Container.call(this);
var floorGraphics = self.attachAsset('floor', {
@@ -79,8 +94,12 @@
// Create floor instance
var floor = game.addChild(new Floor());
floor.x = 2048 / 2;
floor.y = game.groundLevel + 25; // Adjust y position to align with ground level
+// Create cactus instance
+var cactus = game.addChild(new Cactus());
+cactus.x = 1500;
+cactus.y = game.groundLevel - 100; // Adjust y position to align with ground level
// Create player instance
var player = game.addChild(new Player());
player.x = 200;
player.y = game.groundLevel;