Charger une image
load.jsconst PNG = [ "bullet" , "grass" , "bean" , ]
Charger des effets sonores
load.jsconst MP3 = [
"shoot" , "bim" ,"wooosh" , "off" , ]
Créer un composant
component.js// Ajoutes ici tes propres composants
function shootBulletController( shootKey = "space" ) { const marginX = 36 const marginY = 32 const bulletSpeed = 1200 const direction = vec2(1,0) const duration = 4 const fadeDuration = 0.4 const stopOnCollide = 0.4 const particule_life_span = 1 const particule_anim_speed = 30 return { add() { onKeyPress( shootKey , () => this.shoot() ) }, shoot() { const x = this.facing < 0 ? this.pos.x - marginX : this.pos.x + marginX const y = this.pos.y - marginY const d = this.facing < 0 ? vec2(-direction.x,direction.y) : direction const ball = add([ sprite("bullet"), pos(x,y), lifespan(duration,{fade:fadeDuration}), move(d.angle(vec2(0,0)),bulletSpeed), area(), anchor("center"), opacity(), "projectile", ]) ball.onCollide("body",() => this.hitTarget(ball)) play("shoot") }, hitTarget(b){ splashFx(b.pos) destroy(b) play("bim") }, } }
Modifier un symbole
level.jslevelConf"#": () => [ // player shootBulletController(), sprite("bean"), platformerController(), health(1), character(), area(), anchor("bot"), body(), ],
les contrôles du joueur
shootBulletController( "space" ),