[WIP] My first Game

Hi guys,

I discovered Phaser a while ago, and finally had the time to try to build my own first try on a platformer:

Graphic Assets are “Super Platformer Assets” from here:

6 Likes

I like! The jumps being high were tricky for the boxed in platforms, but it’s nice that you have coins, enemies + multiple levels. Still working on level 3 right? Keep it up

yeah good work.

This game is cool! I like the way you made the player look, and how he can shoot arrows. How did you make him be able to do that? I have been wondering how to add that element to a game that I’m currently working on.

Uff, that is a complicated qustion.

First: “Preload” the Arrow sprite (simple)

Second: build an arrow physics group in “create”, deactivated Gravity and create an variable with the speed for the Arrows.

  this.arrows = this.physics.add.group({
    allowGravity: false,
  });

  this.arrows.speed = 300;
}

Third: In “Update” I checked if the space key is pressed and start the Animation.
On the First Frame of the animation, I create and set a variable to true (“arrowTimer”)
On every other Frame and if the Variable is true the arrow gets shot.
(I had some timing issues which I only could solve with this extra variable. Without the Variable the player was shooting arrows like an machine gun)

Shooting the arrow is simple:
Reset the “arrowTimer” Variable to false
Create an arrow sprite into the prepared physics group on the position of the player (plus minus a little bit so it fits).
Then set the speed and flipp of the arrow depending on if the player is flipped or not.

if (
this.cursors.space.isDown &&
player.body.velocity.x == 0 &&
player.body.velocity.y == 0
) {

    player.anims.play("player_bow", true);

    if (player.anims.currentFrame.isFirst) arrowTimer = true;

    if (!player.anims.currentFrame.isFirst && arrowTimer) {

      arrowTimer = false;

      this.sound.play("sfx_bow");

      if (player.flipX) {

        this.arrows

          .create(player.x + 8, player.y + 4, "img_arrow")

          .setVelocityX(-this.arrows.speed).flipX = true;

      } else {

        this.arrows

          .create(player.x + 8, player.y + 4, "img_arrow")

          .setVelocityX(this.arrows.speed).flipX = false;
      }
    }
  }

I am pretty sure there are much better ways to do this, it’s just the solution I could clank together ^^"

1 Like

If it helps, feel free to take a look into the code on github:

2 Likes

Hey thanks for the advice, @Paraldos! Keep out the great work on your game!