Okay I've got a top-down game where the player can find items buried in the grass. While stepping or standing over a buried item, I have a 'Press action button!' graphic that is supposed to flash on screen. So far I've had partial success using distanceTo and collideWith, but I'm a JavaScript dummy and I'm having a hard time knowing where to go. I figured there must be some standard ways to execute this in games that someone here would know. I don't know if it's best to troubleshoot my progress, or to start anew.
My overarching problem is figuring out how to set up the buried item system in general. Not all buried items will be the same. Like treasure chests common in RPGs, some contain currency (and in differing amounts), some contain health, some ammunition and so on. So far I've been using instances of the same 'buried item' entity, thinking I would assign each instance a value somehow. But maybe you can't? Maybe I should create separate entities for every single type of item you can pick up, i.e. '$10', '$20', '10 health'? I can share my progress so far if I am in fact on the right track. I have some other more immediate problems as well.
I'm just an artist who's learning to program games by doing. I've learned a ton so far by pouring over these forums and trying stuff. I'm just not very programmatically inclined. I hope that's okay here.
hi there! you can create seperate entities with the SAME base class.
eg:
// BASE CLASS - item.js
ig.module(
'game.entities.item'
)
.requires(
'impact.entity'
)
.defines(function(){
EntityItem=ig.Entity.extend({
animSheet:null,
init: function( x, y, settings ) {
// stuff
},
update: function() {
// stuff
this.parent();
}
});
});
// buried-item-one.js
ig.module(
'game.entities.buried-item-one'
)
.requires(
'game.entities.item'
)
.defines(function(){
EntityBuriedItemOne=EntityItem.extend({
size:{x:50,y:50},
animSheet::new ig.AnimationSheet('media/some-sheet.png',50,50),
init: function( x, y, settings ) {
// stuff
},
update: function() {
// stuff
this.parent();
}
});
});
oops, forgot to add : you can set all relevant properties of your buried item like this:
// buried-item-one.js
ig.module(
'game.entities.buried-item-one'
)
.requires(
'game.entities.item'
)
.defines(function(){
EntityBuriedItemOne=EntityItem.extend({
// properties you wanted
price:10
health:80
size:{x:50,y:50},
animSheet::new ig.AnimationSheet('media/some-sheet.png',50,50),
init: function( x, y, settings ) {
// stuff
},
update: function() {
// stuff
this.parent();
}
});
});
1 decade ago
by Jib
Hello!
Just a quick thought/question: are you placing those treasures yourself (in WM?) or are they randomly placed in the map?
fugufish's way is the right way if you want to manually control those chests (and in this case you can place a "healthChest" and give it 20 in its value in WM directly) but you also could execute a open() function made completly random when you find the treasures.
The quality of what's inside could then be controled by different params like a number representing the depth (deeper = more coins/health/rare stuff) or a value representing the last type you found (so you have less chances to find the same type 2 times in a row).
Hope this helps ;)
Alright so I think I've got it working like you described, fugufish. Thanks for helping me with this, I'm grateful.
However I've been having a related problem. If I have more than one buried item on a map, only the last one I placed in WM will trigger the 'Press action button!' graphic. I can still pick up any of the other buried items just fine. But I get no flashing graphic for any of them. It's like only one instance of the entity can be recognized at a time. Do you see what I mean?
I'm using distanceTo, by the way. I can display my code if you think it's necessary.
Hi Jib, I'm placing the treasures myself in WM. However I didn't know you could give them values in WM directly. As it is, I have a notification when you pick up an item that prints 'You found 5 gold!'. This text string is currently set in the entity itself. With individual values in WM, how then would I get the notification to grab the value and type of item you just picked up? (Tell me if this isn't very clear) p.s. thank you
1 decade ago
by Jib
Yep, just check the doc on WM 'Manipulating entities'.
Basically you can add a "gold chest" and then add a key "money" to that entity in WM with a value at 10 for example.
Then in your code you have access to "this.money".
Could you or anybody show me an example of how to access a key like "this.money" once it is set? I'm still confused about what I can do with keys in WM that is useful.
so you've set up an EntityBuriedItemOne
I'm assuming you want your player to get 50 gold when he interacts with EntityBuriedItemOne (could be a collision interaction)
// buried-item-one.js
ig.module(
'game.entities.buried-item-one'
)
.requires(
'game.entities.item'
)
.defines(function(){
EntityBuriedItemOne=EntityItem.extend({
// properties you wanted
gold:50 // we plan to give player 50 gold when he finds the treasure
type:ig.Entity.TYPE.NONE,
checkAgainst:ig.Entity.TYPE.A, // only interacts with TYPE A entities
size:{x:50,y:50},
animSheet::new ig.AnimationSheet('media/some-sheet.png',50,50),
init: function( x, y, settings ) {
// stuff
},
update: function() {
// stuff
this.parent();
} ,
// interaction happens here
check:function(other){
if(other==ig.game.player){ // make sure you define player in main.js, using getEntitiesByType(EntityPlayer)[0]
other.gold+=this.gold;
}
}
});
});
code for player
// player.js
ig.module(
'game.entities.player'
)
.requires(
'impact.entitiy'
)
.defines(function(){
EntityPlayer=ig.Entity.extend({
// properties you wanted
gold:0 // player doesn't have any gold when he started out
type:ig.Entity.TYPE.A, // player is of TYPE A
size:{x:50,y:50},
animSheet::new ig.AnimationSheet('media/player-sheet',50,50),
init: function( x, y, settings ) {
// stuff
},
update: function() {
// stuff
this.parent();
}
});
});
typo
// player.js
'impact.entitiy' should be 'impact.entity'
Could you please show how and where to define 'player' in main.js?
// in main.js
loadLevel:function(level){
this.player=this.getEntitiesByType(EntityPlayer)[0];
},
it's an example, there're other ways like getEntityByName, etc.
1 decade ago
by Jerczu
Hah! Fugufish you just answered the question I wanted to ask great!!!
Thanks for your help on this.
Page 1 of 1
« first
« previous
next ›
last »