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 jaems

I'm a total newbie and following the Jesse Freeman HTML5 textbook.
Anyway for my first game, I have 4-way movement with a little dot.

i want it so that if my player dot collects 3 "food", the next level will automatically load, and so on and so on. I already gave my Player Entity a "food" attr, and have it so that when he touches a collectible, it kills() itself, and food attr increments by 1.

So now I just need to find a way to check for each level if player has collected certain amount of food. Something like if (player.food >= 3){ //load next level and reset player.food }

I was thinking that I would have to code this in js file for the first level that I loaded (room.js), but I'm not sure on the best way to go about doing this.

1 decade ago by jaems

also another question I might as well ask:

what is the best way to have in-between level screens that just have text? should i make another level.js for each screen? thanks

1 decade ago by Joncom

In main.js, if you haven't already, make a pointer to your player.

MyGame = ig.Game.extend({
    player: null,
    init: function() {
        /* load level */
        this.player = this.getEntitiesByType(EntityPlayer)[0];
    }
});

Then, if you're keeping track of how much food the player has consumed, you can load the level once he has eaten 3 times.

MyGame = ig.Game.extend({
    player: null,
    init: function() {
        /* load level */
        this.player = this.getEntitiesByType(EntityPlayer)[0];
    },
    update: function() {
        this.parent();
        if(this.player.food >= 3) {
            this.loadLevel(LevelNext);
        }
    }
});

1 decade ago by jaems

Thanks, I just got home so I'm gonna try this now.

1 decade ago by jaems

Alright I tried this, but I can't seem to figure out how to reset the player's foodcount.
Page 1 of 1
« first « previous next › last »