Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
Open WebUI
#2
Mein Gott, LM-Studio hatte ich schon längst wieder vergessen.*lol Aber dein Post macht neugierig, also wieder her damit. Dein Model gleich danach installiert und mir ein Spiel ala Space Invader programieren lassen.^^
Code:
// Space Invaders Game in JavaScript

const canvas = document.createElement('canvas');
document.body.appendChild(canvas);
canvas.width = 800;
canvas.height = 600;
const ctx = canvas.getContext('2d');

// Player class
class Player {
  constructor(x, y) {
    this.x = x;
    this.y = y;
    this.width = 50;
    this.height = 20;
    this.speed = 5;
  }

  draw() {
    ctx.fillStyle = 'blue';
    ctx.fillRect(this.x, this.y, this.width, this.height);
  }

  moveLeft() {
    this.x -= this.speed;
  }

  moveRight() {
    this.x += this.speed;
  }
}

// Invader class
class Invader {
  constructor(x, y) {
    this.x = x;
    this.y = y;
    this.width = 30;
    this.height = 20;
    this.speed = 1;
  }

  draw() {
    ctx.fillStyle = 'red';
    ctx.fillRect(this.x, this.y, this.width, this.height);
  }

  moveDown() {
    this.y += this.speed;
  }
}

// Bullet class
class Bullet {
  constructor(x, y) {
    this.x = x;
    this.y = y;
    this.width = 5;
    this.height = 10;
    this.speed = 5;
  }

  draw() {
    ctx.fillStyle = 'yellow';
    ctx.fillRect(this.x, this.y, this.width, this.height);
  }

  moveUp() {
    this.y -= this.speed;
  }
}

// Game initialization
const player = new Player(canvas.width / 2, canvas.height - 30);
const invaders = [];
for (let i = 1; i < 7; i++) {
  for (let j = 0; j < 5; j++) {
    invaders.push(new Invader(i * 70, j * 30));
  }
}
const bullets = [];

// Event listeners
document.addEventListener('keydown', (e) => {
  if (e.key === 'ArrowLeft') {
    player.moveLeft();
  } else if (e.key === 'ArrowRight') {
    player.moveRight();
  } else if (e.key === 'Space') {
    bullets.push(new Bullet(player.x + player.width / 2, player.y));
  }
});

// Game loop
function gameLoop() {
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  player.draw();

  invaders.forEach(invader => {
    invader.draw();
    invader.moveDown();
  });

  bullets.forEach(bullet => {
    bullet.draw();
    bullet.moveUp();
  });

  // Collision detection
  bullets.forEach((bullet, index) => {
    invaders.forEach((invader, invaderIndex) => {
      if (bullet.x < invader.x + invader.width &&
          bullet.x + bullet.width > invader.x &&
          bullet.y < invader.y + invader.height &&
          bullet.y + bullet.height > invader.y) {
        invaders.splice(invaderIndex, 1);
        bullets.splice(index, 1);
      }
    });
  });

  requestAnimationFrame(gameLoop);
}

gameLoop();

Als Anleitung kam:"Um das Spiel zu spielen, fügen Sie einfach den obigen Code in Ihre HTML-Datei ein und führen Sie ihn aus. Mit den Pfeiltasten nach links und rechts können Sie den Spieler bewegen, und mit der Leertaste können Sie schießen. Viel Spaß beim Spielen!"

Teste ich mal morgen.Cool
Zitieren


Nachrichten in diesem Thema
Open WebUI - von Xenos Yifu - 13.05.2026, 19:12
RE: LM Studio - von Dorena Verne - 13.05.2026, 20:48
RE: LM Studio - von Xenos Yifu - 13.05.2026, 20:49
RE: LM Studio - von Xenos Yifu - 13.05.2026, 20:50
RE: LM Studio - von Xenos Yifu - 13.05.2026, 21:44
RE: LM Studio - von Xenos Yifu - 13.05.2026, 23:27
RE: Open WebUI - von Xenos Yifu - 13.05.2026, 23:49
RE: Open WebUI - von Xenos Yifu - 14.05.2026, 12:07
RE: Open WebUI - von Xenos Yifu - 14.05.2026, 12:26
RE: Open WebUI - von Xenos Yifu - 14.05.2026, 12:40
RE: Open WebUI - von Dorena Verne - 14.05.2026, 13:05
RE: Open WebUI - von Xenos Yifu - 14.05.2026, 13:32
RE: Open WebUI - von Xenos Yifu - 14.05.2026, 13:36
RE: Open WebUI - von Dorena Verne - 14.05.2026, 13:49
RE: Open WebUI - von Xenos Yifu - 14.05.2026, 13:54
RE: Open WebUI - von Xenos Yifu - 14.05.2026, 13:56

Möglicherweise verwandte Themen…
Thema Verfasser Antworten Ansichten Letzter Beitrag
  Awesomebump : Map Generator -Open Source Moe McAlpine 0 6.043 05.12.2016, 22:41
Letzter Beitrag: Moe McAlpine

Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste