Untitled

mail@pastecode.io avatar
unknown
plain_text
24 days ago
1.3 kB
4
Indexable
Never
import kaboom from "kaboom"
import "kaboom/global"

// Höhe und Breite vom Bildschirm bestimmen
kaboom({
  width: 600,
  height: 400,
});

// Sprites laden
loadSprite("hintergrund","sprites/hintergrund.png")

loadSpriteAtlas("sprites/spritesheet frosch.png", {
  "frosch": {
    "x": 0,
    "y": 0,
    "width": 480,
    "height": 100,
    "sliceX": 4,
    "sliceY": 1,
    "anims": {
      "links": { from: 0, to: 1, speed: 4, loop: true },
      "rechts": { from: 2, to: 3, speed: 4, loop: true }
    }
  }
});

loadSpriteAtlas("sprites/spritesheet rubine.png", {
  "rubine": {
    "x": 0,
    "y": 0,
    "width": 240,
    "height": 80,
    "sliceX": 3,
    "sliceY": 1,
    "anims": {
      "drehen": { from: 0, to: 1, speed: 4, loop: true },
      "explodieren": { from: 2, to: 2, loop: false }
    }
  }
});

// Frosch hinzufügen
add([
 sprite("hintergrund", 
 {width:width(), 
 height:height()
 })
]);

const frosch = add([
  sprite("frosch"),
  pos(100,300),
  area(),
  "frosch"
]);

// Bewegung des Frosches
const froschGeschwindigkeit= 300;

onKeyDown("left", () => {
  if (frosch.pos.x > 50) {
    frosch.move(-froschGeschwindigkeit, 0)
    frosch.play('links')
  }
});

onKeyDown("right", () => {
  if (frosch.pos.x < 450) {
    frosch.move(froschGeschwindigkeit, 0)
    frosch.play('rechts')
  }
});
Leave a Comment