Aller au contenu

Tirer

Enam
  1. load.js
    const PNG = [
    "bullet",
    "gun",
    "radish",
    "cross-cursor",
    "grass",
    ]
  2. load.js
    const MP3 = [
    "shoot",
    "bim",
    "wooosh",
    "off",
    ]
  3. config.js
    const TILE_CONFIG = {
    "R": () => [ // radis
    sprite("radish"),
    alive(),
    opacity(),
    scale(),
    health(3),
    respawn(),
    body(),
    area({ scale: vec2(1, 0.8) }),
    handSprite(),
    sight(),
    shoot(),
    shootAi(),
    pos(0, -20),
    anchor("center"),
    ],
    "#": () => [ // 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 }),
    ],
    }
  4. config.js
    "#": () => [ // player 1
    shoot(),
    handSprite(),
    shootController(),
    mouseAimController(),
    sprite("bean"),
    platformerController(),
    jumpController(),
    sleep(),
    alive(),
    opacity(),
    scale(),
    health(1, 4),
    area(),
    body(),
    respawn(),
    falling(),
    rotate(),
    pos(0, -20),
    anchor("center"),
    ],
  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('shoot', 'shoot', () => play('shoot'))
    on('impact', 'projectile', (obj) => splashFX(obj.pos))
    on('impact', 'projectile', () => play('bim'))
    on('impact', 'projectile', (obj) => destroy(obj))
    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: `
    R
    =
    R
    =
    R
    = =
    #
    ===========
    `,
    },
    ]
shoot()
example
config.js
shoot({
speed: 1200,
pos: vec2(0, 0),
lifespan: 0.01,
fadeOut: 0.4,
sprite: "bullet",
width: "null",
bulletTag: "null",
impactTag: "body",
dangerParam: {},
bounceParam: {},
startDistance: 64,
gravityScale: 0,
destroyOnImpact: true,
bounciness: 0,
friction: 0,
aimAngle: 0
}),
shootController()
example
config.js
shootController({
shootKey: "space",
keyPressToShoot: true,
mousePressToShoot: true,
delay: 0.2
}),
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
}),
mouseAimController()
example
config.js
mouseAimController({
sprite: "cross-cursor",
width: 26,
margin: vec2(0, 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
}),
destroyOnEvent()
example
config.js
destroyOnEvent({
delay: 0.4,
event: "death",
on: true
}),
bounce()
example
config.js
bounce({
direction: vec2(0, 0),
speed: 0,
bounciness: 0.8,
friction: 0.5,
detuneAmp: 400,
tag: "body"
}),
shootAi()
example
config.js
shootAi({
delay: 2,
tag: "player",
autoAim: true,
aimMargin: vec2(0, 0),
postureBreak: false,
postureBreakDelay: 1
}),