<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Basic Free Fire Copy</title>
<style>
body {
margin: 0;
overflow: hidden;
background-color: #87CEEB; /* Sky color */
}
canvas {
display: block;
margin: auto;
background-color: #FFFFFF; /* Game area */
}
</style>
</head>
<body>
<canvas id="gameCanvas"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p2.js/0.7.0/p2.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/3.55.2/phaser.min.js"></script>
<script>
const config = {
type: Phaser.AUTO,
width: window.innerWidth,
height: window.innerHeight,
physics: {
default: 'arcade',
arcade: {
gravity: { y: 0 },
debug: false
}
},
scene: {
preload: preload,
create: create,
update: update
}
};
const game = new Phaser.Game(config);
function preload() {
this.load.image('player', 'assets/player.png'); // Add your player image
this.load.image('enemy', 'assets/enemy.png'); // Add your enemy image
}
let player;
let enemies;
function create() {
player = this.physics.add.sprite(100, 450, 'player');
enemies = this.physics.add.group();
// Create enemies
for (let i = 0; i < 5; i++) {
let enemy = enemies.create(Phaser.Math.Between(200, 800), 0, 'enemy');
enemy.setVelocityY(Phaser.Math.Between(50, 100));
enemy.setBounce(1);
enemy.setCollideWorldBounds(true);
}
// Add collision detection
this.physics.add.collider(player, enemies, hitEnemy, null, this);
}
function update() {
// Player movement logic
if (this.input.keyboard.isDown(Phaser.Input.Keyboard.KeyCodes.LEFT)) {
player.setVelocityX(-160);
} else if (this.input.keyboard.isDown(Phaser.Input.Keyboard.KeyCodes.RIGHT)) {
player.setVelocityX(160);
} else {
player.setVelocityX(0);
}
}
function hitEnemy(player, enemy) {
// Logic for when the player hits an enemy
console.log('Hit!');
}
</script>
</body>
</html>