123456789101112131415161718192021222324252627282930313233343536 |
- const keys = {};
-
- document.addEventListener('keydown', (e) => {
- keys[e.key] = true;
- });
- document.addEventListener('keyup', (e) => {
- keys[e.key] = false;
- });
-
- class ShootingPad extends Entity {
- constructor() {
- super(0.5, 0.95, 0.04, 0.03);
- this.element.className = 'shooting-pad';
- this.lastShootTime = Date.now();
- }
-
- update() {
- if (keys['ArrowLeft']) {
- this.x -= VELOCITY[0] * 2;
- }
- if (keys['ArrowRight']) {
- this.x += VELOCITY[0] * 2;
- }
- if (this.x < X_BOUND) {
- this.x = X_BOUND;
- }
- if (this.x > 1 - X_BOUND) {
- this.x = 1 - X_BOUND;
- }
- if (keys[' '] && Date.now() - this.lastShootTime >= 300) {
- this.lastShootTime = Date.now();
- const bullet = new Bullet(this.x, this.y - 0.009);
- bullets.add(bullet);
- }
- }
- }
|