Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

deater07

2
Posts
1
Topics
1
Following
A member registered 29 days ago · View creator page →

Recent community posts

(1 edit)

Thank you so much for your reply 🙏. I completely understand your vision of keeping Pocket Platformer clean and generic, and I really appreciate the clarity. For me this enemy is part of a personal project, so your suggestion to download the repo and add the code myself is perfect. I’ll follow that path and integrate this enemy into my own project built on Pocket Platformer, while respecting the foundation you created. I’m also excited to see your future work on a generic enemy creator — that aligns beautifully with what I’m exploring. Thanks again for sharing Pocket Platformer with the community, it’s a wonderful base to create from 🌟.

(1 edit)

### Creating the Enemy Chaser (Step by Step)

**Overview:** Add a heart-shaped Enemy Chaser that patrols, bounces on walls, and defeats the player on touch. Created with Copilot and shared as a chapter of memory and code.

---

#### 1) Create the object class

- **File:** objects/EnemyChaser.js

```js

class EnemyChaser extends InteractiveLevelObject {

  constructor(x, y, tileSize, type, tileMapHandler, extraAttributes = {}) {

    super(x, y, tileSize, type, tileMapHandler, extraAttributes);

    this.tileMapHandler = tileMapHandler;

    this.speed = extraAttributes.speed || 1;

    this.direction = 1; // 1 = right, -1 = left

    this.collidesWithWalls = extraAttributes.collidesWithWalls ?? true;

    this.animation = SpritePixelArrays.ENEMY_CHASER.animation[0];

  }

  draw(spriteCanvas) {

    const newX = this.x + this.speed * this.direction;

    // Next tile check

    const tileX = this.tileMapHandler.getTileValueForPosition(

      this.direction > 0 ? newX + this.tileSize - 1 : newX

    );

    const tileY = this.tileMapHandler.getTileValueForPosition(this.y);

    const tileType = this.tileMapHandler.getTileLayerValueByIndex(tileY, tileX);

    // Wall collision bounce

    if (this.collidesWithWalls && tileType !== 0) {

      this.direction *= -1;

    } else {

      this.x = newX;

    }

    // Player collision

    const player = this.tileMapHandler?.player;

    if (

      player &&

      Math.abs(this.x - player.x) < this.tileSize / 2 &&

      Math.abs(this.y - player.y) < this.tileSize / 2

    ) {

      PlayMode.playerDeath();

    }

    super.draw(spriteCanvas);

  }

}

```

---

#### 2) Register the script

- **File:** index.html

```html

<script src="objects/EnemyChaser.js"></script>

```

---

#### 3) Add the type

- **File:** utils/ObjectTypes.js

```js

static get ENEMY_CHASER() {

  return 'enemyChaser';

}

```

- **Map at the end:**

```js

[this.ENEMY_CHASER]: EnemyChaser

```

---

#### 4) Add sprite and attributes

- **File:** utils/SpritePixelArray.js

```js

this.ENEMY_CHASER = {

  name: ObjectTypes.ENEMY_CHASER,

  type: this.SPRITE_TYPES.object,

  descriptiveName: "Enemy Chaser",

  changeableAttributes: [

    { name: this.changeableAttributeTypes.speed, defaultValue: 1, minValue: 1, maxValue: 5 },

    {

      name: this.changeableAttributeTypes.collidesWithWalls,

      defaultValue: true,

      formElement: this.changeableAttributeFormElements.checkbox,

      checkboxDescription: "Chaser collides with walls"

    }

  ],

  squishAble: false,

  rotateable: false,

  description: "Un enemigo feroz con forma de corazón que patrulla y mata al jugador al tocarlo.",

  animation: [{

    sprite: [

      ["transp","AA0000","AA0000","transp","transp","AA0000","AA0000","transp"],

      ["AA0000","FF0000","FF0000","AA0000","AA0000","FF0000","FF0000","AA0000"],

      ["AA0000","FF0000","FFFFFF","FF0000","FF0000","FFFFFF","FF0000","AA0000"], // 👀 white eyes

      ["AA0000","FF0000","FF0000","FF0000","FF0000","FF0000","FF0000","AA0000"],

      ["transp","AA0000","FF0000","FF0000","FF0000","FF0000","AA0000","transp"],

      ["transp","transp","AA0000","AA0000","AA0000","AA0000","transp","transp"],

      ["transp","transp","transp","AA0000","AA0000","transp","transp","transp"],

      ["transp","transp","transp","transp","transp","transp","transp","transp"]

    ]

  }]

};

```

---

#### Closing note

With Copilot the Enemy Chaser was created.  

This heart-shaped foe patrols the level, collides with walls, and defeats the player on touch.  

A chapter of memory and code, now shared with you.