Aller au contenu

Attraper et lancer

Arthur
  1. load.js
    const PNG = [
    "ball",
    "grass",
    ]
  2. load.js
    const MP3 = [
    "shoot",
    "bim",
    "score",
    "bloup",
    "wooosh",
    "off",
    ]
  3. config.js
    const TILE_CONFIG = {
    "°": () => [ // balle
    sprite("ball"),
    area(),
    anchor("bot"),
    respawn(),
    body(),
    catchable({ type: "ball" }),
    falling(),
    ],
    "#": () => [ // 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
    holdItem(),
    handSprite({ hiddenOnStart: true }),
    facingAimController({aimAngleMargin: -20,}),
    throwItem({
    dangerParam:{on:false},
    }),
    throwItemController(),
    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('bounce', 'catchable', (obj, p) => play('bloup', p))
    on('picked', 'hold', () => play("score"))
    on('grab catch', 'hand', (obj, p) => { tween(p.dist, obj.hand.pos, 0.2, (v) => obj.hand.pos = v, easings.easeOutSine); obj.hand.pos = p.dist })
    on('dropped', 'catchable', (obj, p) => tween(p.parentPos, p.pos, 0.2, (v) => obj.pos = v, easings.easeOutSine))
    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: `
    ===========
    = =
    = =
    = =
    = =
    = ° # =
    ===========
    `,
    },
    ]
holdItem()
example
config.js
holdItem({
pos: vec2(0, -30),
item: "{",
sprite: "key",
holdItemType: "key"
}),
facingAimController()
example
config.js
facingAimController({
aimAngleMargin: 0
}),
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
}),
throwItem()
example
config.js
throwItem({
speed: 800,
pos: vec2(0, 0),
sprite: "bullet",
width: "null",
bulletTag: "null",
impactTag: "body",
dangerParam: {},
bounceParam: {},
startDistance: 80,
gravityScale: 1,
destroyOnImpact: false,
bounciness: 1,
friction: 0,
aimAngle: 40,
type: "item"
}),
throwItemController()
example
config.js
throwItemController({
shootKey: "space",
keyPressToShoot: true,
mousePressToShoot: true
}),