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 vitinho444

Hello dear community,

I'm a new ImpactJS user, and i wish to make a simple top down shooter game.

I searched for 2 hours in the forums, google etc etc and i couldn't find a way that was noob friendly.

I have the player entity and a bullet entity, they are very similar except bullet doesn't have update function for the key events.

Thanks a lot for any help.

1 decade ago by drhayes

Watch all the tutorial videos first. They explain the basics pretty well.

You have to wire up a lot of separate concepts all together. I don't know what your level of experience is so I'm going to go super slow. Let's dive in!

It sounds like you&039;ve defined two entities. Let's call them #EntityPlayer and EntityBullet. You&039;ve defined two classes, but you still need to instantiate them. In Weltmeister, make a new level and save it as "first.js". Select the "entities" button in the upper-right to select the entity layer. This layer lets you paint entities, like the ones you've defined, into your new level. Press the spacebar to bring up a menu. You should see your entities in there, #Player and Bullet (they won&039;t have the #Entity prefix on them). Select Player and click on the visible area of the editor to put one down. If you&039;ve assigned an <4> for your #EntityPlayer by assigning to its animSheet property you should see it drawn inside Weltmeister.

Go to your main.js file. That&039;s where you define the #Game class that runs your game. You&039;ll probably end up defining multiple of these but I'm getting ahead of myself. Somewhere in the #init method of your Game class type in this:

this.loadLevelDeferred(LevelFirst);

You need to make sure that you put game.levels.first in the requires section at the top of main.js. That should load the level you've defined in Weltmeister when you start up your game. The tutorial videos cover a lot of this stuff, so I'm skimping on detail here.

Getting to the good stuff: Impact is going to call the update method of your entities every frame. Your EntityPlayer is going to have an update method where you can ask it to check to see if the "fire" button is getting hit and, if it is, to spawn an EntityBullet.

Add this to the init method in main.js:

ig.input.bind(ig.KEY.SPACE, 'fire');

You&039;re telling Impact that when the player presses the space bar it will trigger the "fire" key. You can check it by looking at #ig.input.pressed('fire') in the update method of your EntityPlayer like this:

update(): function() {
  if (ig.input.pressed('fire')) {
    var bullet = ig.game.spawnEntity('EntityBullet', this.pos.x, this.pos.y, {
      vel: {
        x: 0,
        y: -100
      }
    });
  }
}

This tells Impact to spawn a new EntityBullet when the EntityPlayer presses the fire button. The new EntityBullet instance will start in the same position as the EntityPlayer instance but will have a velocity that sends it up the screen.

After that you have to set the collision type of EntityBullet correctly so that it collides with your bad guys. Check out the collision documentation for help there.

1 decade ago by vitinho444

Wow, thanks, i already knew the first parts, i watched the pong video.

I finally did it. Thanks a lot. But can i ask one more thing? You said Watch all the tutorial videos first. Is there more than one?

Thank you for your great help.

1 decade ago by drhayes

Maybe by "all" I meant "that one". ( = Sorry 'bout that.

1 decade ago by vitinho444

No problem man, you helped me alot thanks for existing :)
Page 1 of 1
« first « previous next › last »