xxxxxxxxxx
95
/*
keyboard interaction
by Qingyun Zhu
MoveSound01 by
https://freesound.org/people/AbdrTar/sounds/558117/
MoveSound02 by
https://freesound.org/people/dwengomes/sounds/409468/
*/
var x=200;
var y=200;
var speed=2;
var moveSound01;
var moveSound02;
var text01="In order, press keys, 'A,S,D,F Z and X'"
var text02="to hear and see what happens. "
function setup() {
createCanvas(400, 400);
}
function preload() {
moveSound01 = loadSound("Move01.mp3");
moveSound02 = loadSound("Move02.mp3");
}
function draw() {
background('#FDE496');
//text
noStroke();
fill('#000D55');
textFont('impact');
textSize(20);
text(text01, 60, 350);
text(text02, 80, 370);
stroke('#9B65F9');
strokeWeight(5);
fill('#E861FF');
ellipse(x,y,30,30);
if(keyIsPressed){
if(keyCode === 90){
//z
x-=speed;
moveSound02.play()
}
if(keyCode === 88){
//x
x+=speed;
moveSound02.play()
}
}
}
function keyReleased() {
if ( keyCode === 90) {
// z
moveSound02.stop();
}
if ( keyCode === 88) {
// x
moveSound02.stop();
}
}
function keyPressed(){
if(keyCode === 65){
//a
x-=20;
moveSound01.play();
}
if(keyCode === 68){
//d
x+=20;
moveSound01.play();
}
if(keyCode === 87){
//w
y-=20;
moveSound01.play();
}
if(keyCode === 83){
//s
y+=20;
moveSound01.play();
}
}