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 sunnybubblegum

This has to do with general game logic practices more than with Impact.

My problem is that upon re-entering a level, the items placed using Weltmeister regenerate despite being picked up previously. How is it usually set up in games that an item 'gotten' will no longer be available?

How can I incorporate this into the instructions for my item entities and main game? Thanks.

(expounds on post Buried items)

1 decade ago by alexandre

What about using the storage plugin to record the level and coordinates of picked up items, and checking against that every time a level was loaded?

1 decade ago by sunnybubblegum

Thanks for the idea alexandre. I didn't think of the storage plugin for this task. I just checked it out; it seems like it can record a lot of things in your game. Do you think that attempting what you suggested would require any modification to the plugin? I'm a novice with JavaScript/programming.

1 decade ago by alexandre

I haven't used the plugin but doubt you'll have to make any mods. Anyway, this is rough, untested, certainly buggy, but I did that for practice (I'm a JS noob meeself and that's how I would start doing it, for better or for worse). Hope it helps.

ig.module(
	'game.entities.item'
)
.requires(
	'impact.entity'
)
.defines(function()
{
	EntityPlayer = ig.Entity.extend (
	{
		size: {x:8, y:8},
	
		type: ig.Entity.TYPE.A,
		checkAgainst: ig.Entity.TYPE.B,
		collides: ig.Entity.COLLIDES.PASSIVE,

		inventory: new Inventory (this),
		
		enteredLevel: function (levelObject)
		{
			// for each item in level, if item is in inventory
			// remove it from level
		},

		check: function (other)
		{
			// friend, foe, or treasure?
			if (typeof (other) == EntityItem)
			{
				// remove from world
				this.collector.take (other);
			}
		},
		
		// ...
	},

	EntityItem = ig.Entity.extend (
	{
		size: {x:8, y:8},
	
		type: ig.Entity.TYPE.B,
		checkAgainst: ig.Entity.TYPE.NONE,
		collides: ig.Entity.COLLIDES.PASSIVE,

		animSheet: new ig.AnimationSheet ('media/generic-item.png', 8, 8),

		init: function( x, y, settings )
		{
			this.parent (x, y, settings);
			this.addAnim ('idle', 0.2, [0,1]);
		}
	}),
	
	ItemCollector = ig.Class.extend (
	{
		init: function ()
		{
			// setup local storage here
		},
		
		take: function (item)
		{
			// write entry to local storage,
			// specifying level id and coordinates
		}
		
		items: function ()
		{
			// retrieve all local storage items
		}
	}),
	
	Inventory = ig.Class.extend (
	{
		owner: null,
		collector: new ItemCollector (),

		init: function (someone)
		{
			this.owner = someone;
			this.collector = ItemCollector;
		},

		items: function ()
		{
			return this.collector.items();
		}
	});
});

1 decade ago by sunnybubblegum

Thanks alexandre! That's very helpful of you to draw that up. I will certainly try my hand at making this work over the next day or so.

1 decade ago by alexandre

Sure thing. Though upon review, I think that, conceptually, the enteredLevel function does not belong where I put it.

It might be easier to do something like:

MyGame = ig.Game.extend (
{
    loadLevel: function (levelObject)
    {
        this.parent(loadLevel);

        // for each picked up item found in local storage
        // if it's level ID matches this one's, set "items"
        // layer data at item's tile coordinates to 0
        }
    }
});

Anyway I'm new at Impact too. A simpler answer probably exists.
Page 1 of 1
« first « previous next › last »