commit 1c51bcef34ff9ebec42a0819a17fb4dbf102265b Author: Brian Fertig Date: Sun Jul 27 22:58:51 2025 -0600 first commit diff --git a/.continue/rules/new-rule.md b/.continue/rules/new-rule.md new file mode 100644 index 0000000..9381b1a --- /dev/null +++ b/.continue/rules/new-rule.md @@ -0,0 +1,5 @@ +--- +description: Indenting Rules +--- + +All tabs should consist of four spaces. \ No newline at end of file diff --git a/assets/player-thrust.png b/assets/player-thrust.png new file mode 100644 index 0000000..e40552b Binary files /dev/null and b/assets/player-thrust.png differ diff --git a/assets/player.png b/assets/player.png new file mode 100644 index 0000000..fe8d1af Binary files /dev/null and b/assets/player.png differ diff --git a/assets/reticle.png b/assets/reticle.png new file mode 100644 index 0000000..996af3d Binary files /dev/null and b/assets/reticle.png differ diff --git a/assets/starfield.png b/assets/starfield.png new file mode 100644 index 0000000..a0ab78f Binary files /dev/null and b/assets/starfield.png differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..4c29df3 --- /dev/null +++ b/index.html @@ -0,0 +1,20 @@ + + + + + Phaser 3 Spaceship Shooter + + + + + + + \ No newline at end of file diff --git a/main.js b/main.js new file mode 100644 index 0000000..5b71fda --- /dev/null +++ b/main.js @@ -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 + ); + } +} \ No newline at end of file diff --git a/start_web.bat b/start_web.bat new file mode 100644 index 0000000..f266b01 --- /dev/null +++ b/start_web.bat @@ -0,0 +1 @@ +python -m http.server 8000 \ No newline at end of file