Aller au contenu

Épée

Anton & Paul
  1. load.js
    const PNG = [
    "sword",
    "turnip",
    "grass",
    ]
  2. load.js
    const MP3 = [
    "sword",
    "wooosh",
    "off",
    ]
  3. config.js
    "#": () => [ // player 1
    swordController({
    moveSequence: [
    {
    bladeSwingAmp: 90,
    bladeSwingDuration: 0.15,
    wristSwingAmp: 90,
    wristSwingDuration: 0.15,
    },
    {
    bladeSwingAmp: -90,
    bladeSwingDuration: 0.15,
    wristSwingAmp: -90,
    wristSwingDuration: 0.15,
    },
    {
    stabDistance: 20,
    stabDuration: 0.1,
    },
    ],
    onJumpMoveSequence: [
    {
    wristSwingAmp: 360,
    wristSwingAngle: 45,
    wristSwingDuration: 0.3,
    duration: 0.3,
    delay: 0.3,
    },
    ],
    }),
    sword(),
    facingAimController(),
    sprite("bean"),
    platformerController(),
    jumpController(),
    sleep(),
    alive(),
    opacity(),
    scale(),
    health(1, 4),
    area(),
    body(),
    respawn(),
    falling(),
    rotate(),
    pos(0, -20),
    anchor("center"),
    ],
  4. config.js
    const TILE_CONFIG = {
    "t": () => [ // navet
    sprite("turnip"),
    swordAi(),
    sword({
    stabDistance: 20,
    stabDuration: 0.1,
    }),
    sight(),
    alive(),
    opacity(),
    scale(),
    health(3),
    anchor("bot"),
    respawn(),
    body(),
    area(),
    pos(0, -20),
    anchor("center"),
    rotate(),
    ],
    "#": () => [ // player 1
    sprite("bean"),
    platformerController(),
    jumpController(),
    sleep(),
    alive(),
    opacity(),
    scale(),
    health(1, 4),
    area(),
    body(),
    respawn(),
    falling(),
    rotate(),
    pos(0, -20),
    anchor("center"),
    ],
    "=": () => [ // block
    sprite("grass"),
    area({ collisionIgnore: ["agent"] }),
    body({ isStatic: true }),
    anchor("bot"),
    offscreen({ hide: true }),
    tile({ isObstacle: true }),
    ],
    }
  5. game.js
    scene("game", () => {
    const tiles = { ...TILE_CONFIG, ...LEVELS[CURRENT_LEVEL].tiles }
    const config = { ...LEVEL_CONFIG, ...LEVELS[CURRENT_LEVEL].config, ...{tiles:tiles}}
    const map = LEVELS[CURRENT_LEVEL].map.split('\n')
    const level = addLevel(map, config)
    const utility = add([
    multiplayerCamera(),
    ])
    setGravity(config.gravity)
    setBackground(config.backgroundColor)
    on('sword impact', 'blade', () => play('sword'))
    on('jump', 'player', () => play('wooosh'))
    on('drop', 'player', () => play('off'))
    on('respawn', 'player', (obj) => obj.play('idle'))
    on('sleep', 'player', (obj) => obj.play('sleep'))
    on('awake', 'player', (obj) => obj.play('idle'))
    on('jump', 'player', (obj) => obj.play('jump', { speed: 4, onEnd: () => obj.play('idle') }))
    on('drop', 'player', (obj) => obj.play('worry'))
    }
  6. level.js
    const LEVELS = [
    {
    map: `
    t # t
    ===========
    `,
    },
    ]
sword()
example
config.js
sword({
bladePos: vec2(38, 0),
jointPos: vec2(0, 0),
onGuardRotation: 20,
onGuardPos: vec2(28, 10),
onGuardSpeed: 0.4,
rotation: 90,
coolDownDelay: 0.4,
sprite: "sword",
width: 29,
danger: true,
flipX: true,
danger: {},
duration: 0.2,
anchor: vec2(0, 0.8),
areaScale: vec2(0.8, 0.6),
areaOffset: vec2(0, -20),
bladeSwingAngle: 0,
bladeSwingAmp: 0,
bladeSwingDuration: 0,
wristSwingAngle: 0,
wristSwingAmp: 0,
wristSwingDuration: 0,
stabDistance: 0,
stabDuration: 0,
impactPower: 6,
impactDuration: 0.15,
aimAngle: 0
}),
swordController()
example
config.js
swordController({
shootKey: "space",
keyPressToShoot: true,
mousePressToShoot: true,
sequenceBreakDelay: 0.2,
delay: 0.1,
postureBreak: true,
postureBreakDelay: 0.2,
moveSequence: [],
onJumpMoveSequence: []
}),
handSprite()
example
config.js
handSprite({
sprite: "gun",
handDistance: 40,
jointPos: vec2(0, 0),
anchor: vec2(0, 0),
flipY: true,
rotation: 0,
rotate: true,
aim: true,
hiddenOnStart: false
}),
facingAimController()
example
config.js
facingAimController({
aimAngleMargin: 0
}),
sight()
example
config.js
sight({
sight: 600,
raycast: true,
tag: "collectible",
pos: vec2(0, 0)
}),
danger()
example
config.js
danger({
damage: 1,
collisions: ["top", "left", "bot", "right"],
ongoing: false,
tag: "alive",
on: true
}),
swordAi()
example
config.js
swordAi({
delay: 1,
tag: "player",
autoAim: true,
horizontalAim: false,
aimMargin: vec2(0, 0),
postureBreak: true,
postureBreakDelay: 1,
moveSequence: [],
sight: 180
}),