Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Joncom

Is it possible to make a player entity, and then make entities that "extend" that very entity, adding on to it?

What I'm trying to do is have 3 types of players: LocalPlayer, NetworkPlayer, and ComputerPlayer. All of them will share some common code, so I was hoping to put that code in player.js and extend from that.

1 decade ago by alexandre

Absolutely. EntityPlayer is ig.Entity subclass, and LocalPlayer, NetworkPlayer, and ComputerPlayer are EntityPlayer descendants.

If you don't want to pollute the WM entity popup with common (~abstract) class EntityPlayer, you can hide it from WM by putting it some place other than lib/game/entities, e.g.,:

lib/
lib/game/
lib/game/entities/
lib/game/entities/common/
lib/game/entities/common/player.js
lib/game/entities/local-player.js
lib/game/entities/network-player.js
lib/game/entities/computer-player.js

1 decade ago by Joncom

Thx for the WM tip!

Just wondering if you might be so king as to give a code example of how I might make a LocalPlayer entity. How will the first few lines look (the part that normally says that EntityPlayer extends ig.Entity)?

Will it just say instead that EntityLocalplayer extends ig.EntityPlayer?

1 decade ago by alexandre

Here's some kickstarting code:

lib/game/entities/common/player.js
ig.module(
	'game.entities.common.player'
)
.requires(
	'impact.entity'
)
.defines(function(){

EntityPlayer = ig.Entity.extend({
	
	size: {x: 8, y:14},
	offset: {x: 4, y: 2},
	init: function(x, y, settings)
	{
		// ...
	}
});
});

lib/game/entities/local-player.js
ig.module(
	'game.entities.local-player'
)
.requires(
	'game.entities.common.player'
)
.defines(function(){

EntityLocalPlayer = EntityPlayer.extend({
	
	size: {x: 8, y:14},
	offset: {x: 4, y: 2},
	init: function(x, y, settings)
	{
		// ...
	}
});
});

lib/game/entities/network-player.js
ig.module(
	'game.entities.network-player'
)
.requires(
	'game.entities.common.player'
)
.defines(function(){

EntityNetworkPlayer = EntityPlayer.extend({
	
	size: {x: 8, y:14},
	offset: {x: 4, y: 2},
	init: function(x, y, settings)
	{
		// ...
	}
});
});

1 decade ago by Joncom

Just what I needed to get started! :) Thanks alexandre.
Page 1 of 1
« first « previous next › last »