Embarking on a journey into the world of version control and collaborative coding? GitHub, a powerhouse in the tech industry, is an excellent place to start. This comprehensive tutorial will guide you through creating your first game on GitHub, from setting up your repository to pushing your code and playing your game. Let's dive in!
Getting Started: Setting Up Your GitHub Account and Repository
Before we begin, ensure you have a GitHub account. If you don't, sign up at github.com. Once logged in, follow these steps to create a new repository:
- Click the '+' icon in the top-right corner and select 'New repository'.
- Name your repository (e.g., 'MyFirstGame'), write a short description, and click 'Create repository'.
Choosing Your Game Engine
For this tutorial, let's use Phaser, a popular JavaScript framework for creating 2D games. First, make sure you have Node.js and npm installed on your computer. Then, install Phaser globally using:

npm install -g phaser
Initializing Your Project
Navigate to your local repository folder (e.g., 'MyFirstGame') in your terminal and run:
phaser3-project

This command will generate a new Phaser 3 project with the necessary files and folders.
Creating Your First Game Scene
Open the 'index.html' file in your text editor. You'll see the basic structure of a Phaser game. Now let's create our first scene. In the 'src' folder, create a new JavaScript file called 'GameScene.js'. Add the following code:
```javascript class GameScene extends Phaser.Scene { constructor() { super('game'); } preload() { this.load.image('sky', 'assets/sky.png'); this.load.image('ground', 'assets/platform.png'); this.load.image('star', 'assets/star.png'); this.load.spritesheet('dude', 'assets/dude.png', { frameWidth: 32, frameHeight: 48 }); } create() { this.add.image(400, 300, 'sky'); const platforms = this.physics.add.staticGroup(); platforms.create(400, 568, 'ground').setScale(2).refreshBody(); platforms.create(600, 400, 'ground'); platforms.create(200, 250, 'ground'); this.player = this.physics.add.sprite(100, 450, 'dude'); this.player.setBounce(0.2); this.player.setCollideWorldBounds(true); this.anims.create({ key: 'left', frames: this.anims.generateFrameNumbers('dude', { start: 0, end: 3 }), frameRate: 10, }); this.anims.create({ key: 'turn', frames: [{ key: 'dude', frame: 4 }], frameRate: 20, }); this.anims.create({ key: 'right', frames: this.anims.generateFrameNumbers('dude', { start: 5, end: 8 }), frameRate: 10, }); this.stars = this.physics.add.group(); this.stars.create(120, 200, 'star'); this.stars.create(600, 200, 'star'); this.stars.create(100, 400, 'star'); this.score = 0; this.scoreText = this.add.text(16, 16, `Score: ${this.score}`, { fontSize: 24, color: '#ffffff' }); } update(time, delta) { const cursors = this.input.keyboard.createCursorKeys(); if (cursors.left.isDown) { this.player.setAngularVelocity(-300); this.player.anims.play('left', true); } else if (cursors.right.isDown) { this.player.setAngularVelocity(300); this.player.anims.play('right', true); } else { this.player.setAngularVelocity(0); this.player.anims.play('turn'); } this.physics.world.overlap(this.player, this.stars, this.collectStar, null, this); } collectStar(player, star) { star.disableBody(true, true); this.score += 10; this.scoreText.text = `Score: ${this.score}`; } } ```
This code creates a simple game scene with a player that can move left and right, collect stars, and has a score display.

Adding Your Scene to the Game
Open the 'main.js' file and add the following line inside the 'config' object:
```javascript scene: 'GameScene', ```
Now, your game will use the 'GameScene' you created.
Pushing Your Code to GitHub
To push your code to GitHub, open your terminal in the project folder and run:
git add .
git commit -m "Initial commit"
git remote add origin https://github.com/yourusername/MyFirstGame.git
git push -u origin main
Playing Your Game on GitHub Pages
To deploy your game to GitHub Pages, follow these steps:
- In your repository, click on the 'Settings' tab.
- Scroll down to the 'GitHub Pages' section and select 'main' as the source.
- Click 'Save'.
After a few minutes, your game will be live at https://yourusername.github.io/MyFirstGame/.
Congratulations! You've just created and deployed your first game on GitHub using Phaser. Happy coding!




















![How to Make a Game on Scratch | Step-by-Step [Tutorial] for Beginners](https://i.pinimg.com/originals/3e/1b/cb/3e1bcb3be84195a49f389be7b868f819.png)

