first commit
This commit is contained in:
commit
1c51bcef34
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
description: Indenting Rules
|
||||||
|
---
|
||||||
|
|
||||||
|
All tabs should consist of four spaces.
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 42 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 5.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.9 MiB |
|
|
@ -0,0 +1,20 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Phaser 3 Spaceship Shooter</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
canvas {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/phaser@v3.90.0/dist/phaser.min.js"></script>
|
||||||
|
<script type="module" src="main.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -0,0 +1,120 @@
|
||||||
|
const config = {
|
||||||
|
type: Phaser.AUTO,
|
||||||
|
scale: {
|
||||||
|
mode: Phaser.Scale.RESIZE,
|
||||||
|
width: 1920,
|
||||||
|
height: 1080,
|
||||||
|
},
|
||||||
|
parent: 'game',
|
||||||
|
backgroundColor: '#111',
|
||||||
|
physics: {
|
||||||
|
default: 'arcade',
|
||||||
|
arcade: {
|
||||||
|
gravity: { y: 0 },
|
||||||
|
debug: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
scene: {
|
||||||
|
preload: preload,
|
||||||
|
create: create,
|
||||||
|
update: update
|
||||||
|
},
|
||||||
|
pixelArt: true
|
||||||
|
};
|
||||||
|
|
||||||
|
const game = new Phaser.Game(config);
|
||||||
|
|
||||||
|
let ship;
|
||||||
|
let cursors;
|
||||||
|
let bullets;
|
||||||
|
let bulletSpeed = 500;
|
||||||
|
let thrustSpeed = 200;
|
||||||
|
|
||||||
|
function preload() {
|
||||||
|
// Load assets here if needed
|
||||||
|
this.load.image('ship', 'assets/player.png');
|
||||||
|
this.load.image('player-thrust', 'assets/player-thrust.png');
|
||||||
|
this.load.image('starfield', 'assets/starfield.png');
|
||||||
|
}
|
||||||
|
|
||||||
|
function create() {
|
||||||
|
// Prevent right-click context menu
|
||||||
|
this.input.on('contextmenu', (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Change cursor to custom reticle (you need a 'reticle.png' image)
|
||||||
|
this.input.setDefaultCursor('url(assets/reticle.png), auto');
|
||||||
|
|
||||||
|
// Create the spaceship
|
||||||
|
ship = this.physics.add.sprite(400, 300, 'ship');
|
||||||
|
ship.setCollideWorldBounds(true);
|
||||||
|
ship.setDisplaySize(48, 48);
|
||||||
|
|
||||||
|
// Create bullet group
|
||||||
|
bullets = this.add.group({
|
||||||
|
classType: Phaser.Physics.Arcade.Sprite,
|
||||||
|
key: 'bullet',
|
||||||
|
repeat: 10,
|
||||||
|
setXY: { x: 0, y: 0, stepX: 0, stepY: 0 }
|
||||||
|
});
|
||||||
|
|
||||||
|
// Set bullet properties
|
||||||
|
bullets.getChildren().forEach(bullet => {
|
||||||
|
bullet.setActive(false);
|
||||||
|
bullet.setVisible(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Input handling
|
||||||
|
this.input.on('pointerdown', (pointer) => {
|
||||||
|
if (pointer.leftButtonDown()) {
|
||||||
|
fireBullet();
|
||||||
|
} else if (pointer.rightButtonDown()) {
|
||||||
|
ship.setVelocity(0, 0);
|
||||||
|
ship.setAcceleration(0, 0);
|
||||||
|
ship.setDrag(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Mouse movement
|
||||||
|
this.input.on('pointermove', (pointer) => {
|
||||||
|
const angle = Phaser.Math.Angle.Between(
|
||||||
|
ship.x, ship.y,
|
||||||
|
pointer.x, pointer.y
|
||||||
|
);
|
||||||
|
ship.setRotation(angle);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function update(time, delta) {
|
||||||
|
// Thrust on right click - continuous movement towards the mouse
|
||||||
|
if (this.input.activePointer.rightButtonDown()) {
|
||||||
|
const angle = Phaser.Math.Angle.Between(
|
||||||
|
ship.x, ship.y,
|
||||||
|
this.input.activePointer.x, this.input.activePointer.y
|
||||||
|
);
|
||||||
|
ship.setVelocity(
|
||||||
|
Math.cos(angle) * thrustSpeed,
|
||||||
|
Math.sin(angle) * thrustSpeed
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// If not thrusting, apply drag to slow down
|
||||||
|
ship.setDrag(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function fireBullet() {
|
||||||
|
const bullet = bullets.getFirstDead();
|
||||||
|
if (bullet) {
|
||||||
|
bullet.setPosition(ship.x, ship.y);
|
||||||
|
bullet.setActive(true);
|
||||||
|
bullet.setVisible(true);
|
||||||
|
|
||||||
|
// Set direction based on the ship's rotation
|
||||||
|
const angle = ship.rotation;
|
||||||
|
bullet.setVelocity(
|
||||||
|
Math.cos(angle) * bulletSpeed,
|
||||||
|
Math.sin(angle) * bulletSpeed
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
python -m http.server 8000
|
||||||
Loading…
Reference in New Issue