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

8 years ago by sleenee

Hello all!

I am very new to all of this (both javascript and the impact js engine) so please forgive me if this is regarded as a retarded question but I am wondering if someone could help me with the following:

I am trying to build an RPG but I don't quiet get how you would have to move your character between rooms (levels) if the player goes through a door.

I tried building an entity that detects collision with the player and that then should load another level however I must be making some fatal mistakes here:

ig.module(
'game.entities.loadlevel'
)
.requires(
'impact.entity'
)
.defines(function(){

EntityLoadlevel = ig.Entity.extend({

size: {x:48, y:24},
_WMDrawBox: true,
_WMBoxColor: 'rgba(255,0,0,0.5)',
_WMScalable: true,

checkAgainst: ig.Entity.TYPE.A,


update: function() {
this.parent();
},
check: function (other) {
ig.MyGame.loadLevel( LevelTest );
},

});

});


Also, what is the common practice to do these venue-transitions? If you would have a room with multiple entrances, is the spawn-location of your player then hard-coded with map-coordinates dependent on which room they came from?

If anyone could give me some pointers or common practices for this I would be very gratefull.

greetings

8 years ago by Hareesun

There's already a levelchange entity available within the Biolab Disaster Entity Pack on your download page. :)

Also, wrap your code in ##'s above and below it to format it. There's a Show Formatting Help link above your post-edit box thing. :)

8 years ago by stahlmanDesign

If you're only concerned about doors that are fixed when you design a map, then you could use an approach I used in another game.

For example, you'd have your trigger warp you to: level02_A (door A in level 2)

Then in level 2 you'd have a warp point leading to level01_A (door A in level 1)

You could also have level02_B so you'd come into level 2, but at door B etc.

When loading your level, you'll have to have some code remove the _A at the end of the filename and save it as a variable. That way the level loads, and you just tell it where to place the player depending on that variable. Your Door entity will have the name:A

It takes a bit of planning and testing to make sure you've got all your warp points going to the right doors, but it works and is probably easy to implement using existing the levelChange Entity.

8 years ago by Hareesun

I've got a ton of doors and stuff in my games too, and the way I'm getting around it is by having a slightly bigger than normal level, but having the doors actually teleport you to other parts of the level. So it's the illusion of multiple rooms but all in the same level file.

To make this look a little more authentic than just warping the player i've got the door triggering an fade-to-black and when it reaches the top level it teleports the player behind the black-cover and then fades the black out. Looks and works great.

8 years ago by sleenee

Thank you very much people, the levelchange entity combined with a trigger does the trick just fine. (didn't know it was there :s )

@stahlmanDesign:
so you would sugest having different instances of the same level , exact copies expect for the level entry point? I guess that is a pretty good solution, a little high in maitenance maybe but to be honest I don't immediately see an alternative approach so I'll go for that.

Thank you very much everyone!

8 years ago by stahlmanDesign

@sleenee, no, you don't need different instances of the same level. See this guide:

/>			</div>
		</div>
			<div class=

8 years ago by RomainT

How do you place the hero at a given position ?

8 years ago by fugufish

does the level load a fresh copy every time the player warps to a different screen?

If that's the case, we're gonna need some global variables to keep track. Or else the same monsters/powerups get generated every time we enter said screen.

8 years ago by sleenee

@stahlmanDesign

Ah i see, so you have another entity in place , the "warppoint" where your player spawns at levelload. And you probably enhanced the "levelchange" code with a variable that contains the designated warppoint.

Would you mind showing some code for this warppoint principle? Because now I just used the player entity itself and just put that in the map but that will just create 2 or more players in this case. :)

already a lot of thanks for the explanation you just gave.

8 years ago by stahlmanDesign

I don't have it working in Impact yet. I haven't had time. I did it in another Objective-C project and the way I described it here is how I would do it if I did it all over again in Impact. If I get around to it, I'll share the code.

8 years ago by sleenee

i see,

well already a lot of thanks for sharing you know :), it's very helpfull

8 years ago by BlackDolphinMedia

what you need are the levelchange and the void entitie out of the biolab entitie pack


the levelchange needs a slight adjustment
...
	_wmDrawBox: true,
	_wmBoxColor: 'rgba(0, 0, 255, 0.7)',
	
	size: {x: 8, y: 8},
	level: null,
	spawn : "s0", // NAME OF THE VOID FOR THE POS
	
	......
// CHANGE THE LOAD METHOD AND ATTACH THE CODE
			ig.game.loadLevel( ig.global['Level'+levelName] );
                 
			if(this.spawn)
			{
				var spawnpoint = ig.game.getEntityByName(this.spawn);
				if(spawnpoint)
				{
					ig.game.spawnEntity(EntityPlayer, spawnpoint.pos.x, spawnpoint.pos.y);
				}
	....

spawn takes the name of the void in the other level

to avoid a duplicated player spawing in the main level you probably want to load you player in the main.js
like that:

var spawnpoint = ig.game.getEntityByName("mainspawnpoint");
ig.game.spawnEntity(EntityPlayer, spawnpoint.pos.x, spawnpoint.pos.y);

8 years ago by sunnybubblegum

Hi,
I'm having trouble getting my player to spawn at different coordinates based on the room he came from, despite trying to follow some of the tips from this thread. I'm using the levelchange.js and trigger.js entities. Here's what I've got.

main.js
currentLevel: null,
lastLevel: null,

init: function() {

	this.loadLevel( LevelCave001 );
	this.currentLevel = LevelCave001;
	ig.game.spawnEntity( EntityPlayer, 802, 548 );

},

update: function() {
	this.parent();

	var player = this.getEntitiesByType( EntityPlayer )[0];

	// screen follows player
	if( player ) {
		this.screen.x = player.pos.x - ig.system.width/2 + 18;
		this.screen.y = player.pos.y - ig.system.height/2 + 30;
	}

},

loadLevel: function( data ) {
	this.parent( data );
		
	if( this.currentLevel == LevelCave001 && this.lastLevel == LevelCave002 ) {
		this.lastLevel = this.currentLevel;
		this.currentLevel = LevelCave001;
		ig.game.spawnEntity( EntityPlayer, 812, 932 );
	}
	else if( this.currentLevel == LevelCave002 && this.lastLevel == LevelCave001 ) {
		this.lastLevel = this.currentLevel;
		this.currentLevel = LevelCave002;
		ig.game.spawnEntity( EntityPlayer, 942, 72 );
	}
	else if( this.currentLevel == LevelCave002 && this.lastLevel == LevelField001 ) {
		this.lastLevel = this.currentLevel;
		this.currentLevel = LevelCave002;
		ig.game.spawnEntity( EntityPlayer, 1096, 2768 );
	}
	else if( this.currentLevel == LevelField001 && this.lastLevel == LevelCave002 ) {
		this.lastLevel = this.currentLevel;
		this.currentLevel = LevelField001;
		ig.game.spawnEntity( EntityPlayer, 1038, 308 );
	}
		
},

He always begins correctly-positioned in the first room. But upon changing rooms, the screen goes to the top-left corner of the map. I can't tell if the player's even been spawned or not.

Also I will probably need to kill the player off from the last room so there aren't two of them. Just not sure where or when to do this. Thanks in advance!

8 years ago by gashiss

Please could anyone post this kind of teleport exemple?
I am a bit confused working with this.
Thanks.

7 years ago by amadeus

I'm still very much an ImpactJS newbie, but I handled it by creating 2 types of entities.

1) a Goto entity, that when triggered takes the user to the defined level: https://gist.github.com/45b2d972cce997023a0f

2) a StartFrom entity, that is used to start the character from that specified location when coming from defined previous map: https://gist.github.com/966d6872b6c04e8779a5

I then have a special 'gotoLevel' function in my game that looks like this: https://gist.github.com/721f7ee710b950a0d980 that can take the strings passed around and convert them into actual level names.

Basically it allows me to use the level editor to design my levels, my goto points, then I just add the gotoLevel variable to that instance to specify the level name, then I set my startFrom entities, and add the level property, which is the string corresponding from the level they started from.

I realize this is an old thread, but I figured I'd reboot it with my technique. Perhaps someone could offer improvements or find it useful.
Page 1 of 1
« first « previous next › last »