AS3 Question about OOP, interacting from a Player class to an Enemy class

Started by
4 comments, last by ilicos 8 years, 10 months ago

Problem solved, thanks!!!


public static function

var enemy:CGenericEnemy
			
		deleted
Advertisement

Where does it crash, and with what kind of message?

It is at least wrong to run the trace statement as done, because it accesses members of the object enemy although that variable may be null (see the implementation of CEnemyManager.collides(...)). So that trace must be protected like so:


if (enemy != null) trace(…);

HI, i don't use that one, maybe i forgot to erase it , i use boxcolission... but the main question would be about OOP, how do you interact with the enemy from the Player class?

I don't think the enemy should know about the player or the other way around either.

Better to have a class that has a list of enemies and a reference to the player and it handles the collisions.

The player/enemy classes could have an isColliding method, but if it is simple box vs box all the time you might as well keep that logic in your collision handling system.

I don't think the enemy should know about the player or the other way around either.

Better to have a class that has a list of enemies and a reference to the player and it handles the collisions.

The player/enemy classes could have an isColliding method, but if it is simple box vs box all the time you might as well keep that logic in your collision handling system.

So i create a public class, instantiate the enemies there and handle all the logic, then i call it on the level/room and "update" it?

Hello',

I'm a young french game developper... but...

DisplayObjects have hitTestObject method

Why do you don't use it?

->


if (enemy.hitTestObject(player)){
    enemy.onPlayerCollision();
    player.onEnemyCollision();
}

you can add player in enemy method or enemy in player method.

Why do you put "C" as prefix in all your class names?

ilicos

This topic is closed to new replies.

Advertisement