Creating a Simple Game Discussion

Hi Mike,

I have fixed the issue by typing the following instead of the instructions by Ivan:

python -m http.server

Hope it works for you too

1 Like

I love the course! Please let people know in this course there will be an issue with the security. IMPORTANT!

Everyone has to understand that if you build a dapp that is using assets, you have to implement specialities in the backend. If you don’t you will get scammed!
In this case the there is very easy to give yourselt Super Boots by just changing a variable in the console log. Or you could even change you bag of coin to whatever you like, which will make your ERC20 token worthless.

Please add this in this course,
Cheers!

Hey,

Having no luck with the powershell command
I have typed “python -m http.server 8000” then i press enter and it goes to the next line
PS C:\Users\BLITZ\Desktop\GameCode>

Hi @blitz
Can you shared your versions ?

python --version

And

pip list

Oh, thanks gabba, i have found the problem!!!
I had renamed the directory.

Thanks for the reply though, much appreciated!

1 Like

Hello, when I try to load the crate I just have a a small green box on the screen and an error message in console saying…
:8000/assets/crate.png:1 Failed to load resource: the server responded with a status of 404 (File not found)

The Knight loads with no problems though.

HELP!

@ivan @Gabba maybe.
As soon as I uncomment the anims section my game screen goes completely white.
I’ve tried moving the anims around in the create() function but it didn’t seem to help.

What am I doing?
This is actually where I gave up and quit the Academy last year.
:open_mouth:

Help!

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>Making your first Phaser 3 Game - Part 2</title>
    <script src="//cdn.jsdelivr.net/npm/[email protected]/dist/phaser.js"></script>
    <style type="text/css">
        body {
            margin: 0;
        }
    </style>
</head>
<body>

<script type="text/javascript">

var config = {
  type: Phaser.AUTO,
  width: 800,
  height: 600,
  physics: {
    default: 'arcade',
    arcade: {
        gravity: { y: 200 },
        debug: true
      }
},


scene: {
  preload: preload,
  create: create,
  update: update
}
};

var cursors;
var knight;
var star;

var game = new Phaser.Game(config);

function preload() {
  this.load.image('ground', 'assets/platform.png');
  this.load.image('background', 'assets/background.png');
  this.load.image('star', 'assets/star.png');
  this.load.image('crate', 'assets/crate.png');
  this.load.image('knight', 'assets/knight.png');
  this.load.image('run_frame_1', 'assets/knight/run/Run (1).png');
  this.load.image('run_frame_2', 'assets/knight/run/Run (2).png');
  this.load.image('run_frame_3', 'assets/knight/run/Run (3).png');
  this.load.image('run_frame_4', 'assets/knight/run/Run (4).png');
  this.load.image('run_frame_5', 'assets/knight/run/Run (5).png');
  this.load.image('run_frame_6', 'assets/knight/run/Run (6).png');
  this.load.image('run_frame_7', 'assets/knight/run/Run (7).png');
  this.load.image('run_frame_8', 'assets/knight/run/Run (8).png');
  this.load.image('run_frame_9', 'assets/knight/run/Run (9).png');
  this.load.image('run_frame_10', 'assets/knight/run/Run (10).png');

  this.load.image('idle_frame_1', 'assets/knight/run/Idle (1).png');
  this.load.image('idle_frame_2', 'assets/knight/run/Idle (2).png');
  this.load.image('idle_frame_3', 'assets/knight/run/Idle (3).png');
  this.load.image('idle_frame_4', 'assets/knight/run/Idle (4).png');
  this.load.image('idle_frame_5', 'assets/knight/run/Idle (5).png');
  this.load.image('idle_frame_6', 'assets/knight/run/Idle (6).png');
  this.load.image('idle_frame_7', 'assets/knight/run/Idle (7).png');
  this.load.image('idle_frame_8', 'assets/knight/run/Idle (8).png');
  this.load.image('idle_frame_9', 'assets/knight/run/Idle (9).png');
  this.load.image('idle_frame_10', 'assets/knight/run/Idle (10).png');
}

function create() {
  platforms = this.physics.add.staticGroup();

  platforms.create(400, 608, 'ground').setScale(2, 0.5).refreshBody();
  this.add.image(400, 300, 'background');
  //this.add.image(200, 100, 'star');
  //this.add.image(500, 200, 'star');

  crates = this.physics.add.staticGroup();

  crates.create(100, 560, 'crate');
  crates.create(400, 560, 'crate');
  crates.create(475, 330, 'crate');

  knight = this.physics.add.sprite(100, 350, 'knight');
  knight.body.setSize(400, 600, 50, 50);
  knight.scaleX = 0.2;
  knight.scaleY = 0.2;
  knight.setBounce(0.3);
  knight.setCollideWorldBounds(true);


  cursors = this.input.keyboard.createCursorKeys();

  stars = this.physics.add.group({
      key: 'star',
      repeat: 11,
      setXY: { x: 12, y: 0, stepX: 70 }

  });


  stars.children.iterate(function (child) {

      child.setBounceY(Phaser.Math.FloatBetween(0.8, 0.9));

  });

  /*this.anims.create({
    key = 'knight_run',
    frames:[
    {key: 'run_frame_1'},
    {key: 'run_frame_2'},
    {key: 'run_frame_3'},
    {key: 'run_frame_4'},
    {key: 'run_frame_5'},
    {key: 'run_frame_6'},
    {key: 'run_frame_7'},
    {key: 'run_frame_8'},
    {key: 'run_frame_9'},
    {key: 'run_frame_10'},
    ],
    frameRate: 10,
    repeat: 1

  });

  this.anims.create({
    key = "knight_idle",
    frames:[
    {key: "idle_frame_1"},
    {key: "idle_frame_2"},
    {key: "idle_frame_3"},
    {key: "idle_frame_4"},
    {key: "idle_frame_5"},
    {key: "idle_frame_6"},
    {key: "idle_frame_7"},
    {key: "idle_frame_8"},
    {key: "idle_frame_9"},
    {key: "idle_frame_10"},
    ],
    frameRate: 10,
    repeat: 1

  });*/


  this.physics.add.collider( crates, knight);
  this.physics.add.collider(stars, crates);
  this.physics.add.collider(knight, platforms);
  this.physics.add.collider(stars, platforms);
  //this.physics.add.overlap(knight, stars, collectStar, null, this);

}

function update() {
 if (cursors.left.isDown)
  {
      knight.setVelocityX(-160);
      //knight.play("knight_run", true);

      //knight.anims.play('left', true);
  }
  else if (cursors.right.isDown)
  {
      knight.setVelocityX(160);
      //knight.play("knight_run", true);
      //knight.anims.play('right', true);
  }
  else
  {
      knight.setVelocityX(0);

      //knight.anims.play('turn');
  }

  if (cursors.up.isDown /*&& knight.body.touching.down*/)
  {
      knight.setVelocityY(-330);
  }//need to set bottom of frame as ground for knight to jump.

  function collectStar (knight, star)
  {
      star.disableBody(true, true);
  }


}



</script>

</body>
</html>

Ok, I ended up with cloning Phaser from GitHub, which seems to be working Very Well Indeed.

I’ve been fiddling with the tutorial on the Phaser website.
I still had their assets with the code and had loaded those
into the project inadvertently. Finally got everything loading and going.

Very fun.

1 Like

I hope you already solved the issue.
It’s usually the path set for the file I think.

1 Like

this line of code helped me a lot!

do you know why it says no file exists on mac? “jessiebarbee@Jessies-MacBook-Pro ~ % cd/Users/jessiebarbee/Desktop/Crypto/Game\ Programming
zsh: no such file or directory: cd/Users/jessiebarbee/Desktop/Crypto/Game Programming”

Amazing course guys,
I don’t have any programming background. Feels so good to finish this game. Looking forward to the next courses!

I changed it a little :wink:

@ivan This is a fantastic course that I could envision my kids (ages 4, 8, 10, and 12) all getting into and LEARNING rather than passively playing games. With Covid homeschooling is now a trendy thing. Would you consider tailoring a division of the academy to children? I would love my kids learning about ‘physics’ from practical gaming rather than those boring school lab experiments…and earning NFT tokens…man, I can see that really taking off and doing well, as a parent (unfortunately divorced with a not so cooperative mothers though) I would pay top dollar for an educational platform like this and you guys are the crew for this task…if anything like you new Reports, top quality…consider seriously!

So I had a problem I thought I would share.

my code - var game = new Phaser.game(config);
I had an error saying

Uncaught TypeError: Phaser.game is not a constructor

after a lot of head scratching and some help on another forum it turns out that a common mistake is the capital letter causing a problem . I should have had a capital G in Phaser.game :

var game = new Phaser.Game(config);

hope that helps anyone in a similar position.

I ran into situation that my knight image won’t show up on the screen. Attached is the code and error message in the Brave console. Can someone help ?

<html>

  <head>
    <title>Our awesome game</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/phaser.min.js"></script>
  </head>

  <body>
      <h1>Game title</h1>
      <h2>H2 title</h2>

      <script>
        //configure the game(hight, width, render-type, game loop)
        var config ={
          width: 800,
          height: 500,
          type:Phaser.AUTO,
          scene:{
            preload: gamePreload,
            create: gameCreate,
            update: gameUpdate
          }
        }

        function gamePreload(){
          // loading assets
          console.log("game is loading assets");
          this.load.image("knight","assets/knight.png");
        }

        function gameCreate(){
          // initial setup logic on the asset and othere setup
          console.log("game is setting up the assets etc");
          this.add.image(400,0,"knight");
        }

        function gameUpdate(){
          // monitoring input and telling game how to update
          //console.log("game is updating");
        }

        var game = new Phaser.Game(config);
      </script>

  </body>
</html>

I just realized I missed the step of setting up the local server. I will go ahead to try that first.

Hello, Leon here, i just finished the 1st part of the course (making the game), and i wanted to add two things to it, but i really couldnt figure out how, after several times trying.

1st thing: How can i end the game if the knight falls off?
2nd thing: How can i make coins delete themselves after 5 seconds ?

if anyone can help i would appreceate it a lot!

I am currently stuck on loading sprites, hoping to find some help. @ivan




2 Likes

The server seems to be running fine as well

1 Like

Hey @Pigott, hope you are great.

Now that issue happens some times, it can be solved by installing the last version of your library (Phaser Game Library).

Carlos Z.

thanks for the help Carlos!