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 = {
    // radis
    R: () => [
    sprite('radish'),
    alive(),
    opacity(),
    scale(),
    health(3),
    respawn(),
    body(),
    area({ scale: vec2(1, 0.8) }),
    handSprite(),
    sight({ sight: 560, loosingSight: 800 }),
    shoot(),
    shootAi(),
    pos(32, 32),
    anchor('center'),
    ],
    // player
    '#': () => [
    sprite('bean'),
    platformerController(),
    jumpController(),
    sleep(),
    alive(),
    opacity(),
    scale(),
    health(1, 4),
    area(),
    body(),
    respawn(),
    falling(),
    rotate(),
    pos(0, -20),
    anchor('center'),
    'player',
    ],
    // block
    '=': () => [
    sprite('grass-tileset'),
    offscreen({ hide: true }),
    tile({ isObstacle: true }),
    autoTiling(),
    area(),
    body({ isStatic: true }),
    ],
    };
  4. config.js
    // player
    '#': () => [
    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'),
    'player',
    ],
  5. events.js
    function events() {
    return {
    add() {
    // tirer
    on('shoot', 'shoot', () => play('shoot'));
    on('impact', 'projectile', (obj) => {
    splashFX(obj.worldPos);
    play('bim');
    destroy(obj);
    });
    // personnages
    on('respawn', 'alive', (obj) => (obj.flipY = false));
    on('hurt', 'alive', (obj) => {
    play('hit');
    colorShiftFx(obj, { color: 'ff9b9b' });
    });
    on('death', 'alive', (obj) => {
    obj.flipY = true;
    wait(0.2, () => {
    if (!obj.isAlive) {
    obj.hidden = true;
    obj.collisionIgnore = ['*'];
    obj.isStatic = true;
    }
    });
    });
    // joueur
    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) => {
    play('wooosh');
    obj.play('jump', {
    speed: 4,
    onEnd: () => obj.play('idle'),
    });
    });
    on('drop', 'player', (obj) => {
    play('off');
    obj.play('worry');
    });
    on('hurt', 'player', (obj) => {
    obj.play('worry', {
    speed: 2,
    onEnd: () => obj.play('idle'),
    });
    });
    },
    };
    }
  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: '*',
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',
spriteParam: {},
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: 180,
looseSight: 340,
raycast: false,
tag: 'player',
rayCastExclude: ['pass through'],
offset: vec2(0, 0),
on: true,
offScreenPaused: false,
liveUpdate: false,
onAddOnly: false
}),
danger()
example
config.js
danger({
damage: 1,
collisions: ['top', 'left', 'bot', 'right'],
ongoing: false,
tag: '*',
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: '*'
}),
shootAi()
example
config.js
shootAi({
delay: 2,
tag: 'player',
autoAim: true,
aimMargin: vec2(0, 0),
postureBreak: false,
postureBreakDelay: 1
}),