Jump to content

How to implement complex enemies on a plataform game


julianMatox
 Share

Recommended Posts

First, let me introduce myself, I'm a web developer since a few years ago, this year in particular my work started to get tedious and boring so I decided on my spare time to try something new (game development), and while searching for options I stumbled upon Phaser. Since I'm familiar with HTML5 and Javascript I'm advancing at a fast pace, I already made some tutorials and small simple games, but as my current challenge I decided go forth and make an clone of a NES game.

My game is a standard 2D plataform game were you control a ninja. Currently have my player class working (using a sprite atlas, with all the controls that I need), my level using tiles (using tiled as a level editor), and now I started to work on enemies.

In my previous games the enemies were simple (if the player hit them, they simply dissipated, so it was a simply collision test against the enemy group). The thing is, in this game the enemies are a little bit more complex: they patrol and they stay on a platform, they can "fall" into lesser platforms (based on certain conditions) and they can fire at the player if he's in range.
I haven't actually started programming them yet (just a generic enemy class), Looking for answers I found an image (IMPORTANT: NOT FROM MY GAME) that can help me out convey what I'm trying to do:

64R1nqk.png.e6cbaa78feec2b97095611dc0089ee73.png

Let's assume I want to add an enemy like this. This enemy has a small collision box (the blue box in the center), two sensors (blue at the bottom) for detecting if the floor is there, and two (red) sensors to determine the patrol distance (and if the player is in range, triggering the attack), I want to implement this but I'm not sure if this is even possible on phaser. So my question are:

- How can I add sensor on phaser (its this approach even possible?)
- What physic system I must adhere to make this work (currently using ARCADE physics)?
- its a good idea to have all those sensors on a single sprite or the memory will explode and the game will lag?
- There's a "good way" or a standard practice to write enemies/behavior?

Any help on how to tackle this issue will be greatly appreciated!
and thanks in advance

 

Link to comment
Share on other sites

For sensors you can use blank, Arcade Physics-enabled child sprites of the main sprite. Then you just test for overlaps. Should be no memory problems.

You may not even need separate sensors on both sides, since you can usually locate the collision when it happens.

There's a Behavior plugin that uses a component model you could follow.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...