We are about to switch to a new forum software. Until then we have removed the registration on this forum.
When I test this easy game, println() works but the text doesn't. Any idea? Thanks!
//VAR CANVAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
var wid = 1000;
var hei = 650;
//DEFINE
var units = 2;
var myBlocks = [];
var p = [];
var check = {
r: wid / 14,
x: wid / 2 - wid / 20, // half of the screen - half of the lenght of the rect
y: hei * 5 / 6,
name: "CHECK",
};
var into = false;
var uncorrect = 'NOT QUITE, TRY AGAIN!';
var correct = 'GOOD EAR';
var wave;
var A = 1;
var distance = (1 / units) * .1;
//SETUP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
function setup() {
createCanvas(wid, hei);
middleC = loadSound('CRhodes.mp3');
//middleC = loadSound('middleC.mp3');
//middleC = loadSound('AGlockenspiel.mp3');
//VAR BLOCKS;;;;;;;;
var dis = (1 / units) * .1; //54 is the aprox distance between A4 and B4.
var wideCount = (wid - 10) / units;
var space = 10;
//SHUFFLE XPOS
var xpos = [];
for (var i = 0; i < units; i++) {
append(xpos, i); //* wideCount + 100); append(myArray, "Peach") //print(myArray) // ["Mango", "Apple", "Papaya", "Peach"]
}
var shuffledxpos = shuffle(xpos);
println(xpos);
println(shuffledxpos);
//INITIALIZE BLOCKS,POSITIONS AND CHECK
for (i = 0; i < units; i++) {
var xposDef = shuffledxpos[i] * wideCount + space;
var yposDef = hei / 4;
var widDef = 25;
var heiDef = 70;
var wave = A + (i * dis);
myBlocks[i] = new Block(wave, xposDef, yposDef, widDef, heiDef, "block" + i);
p[i] = new Position(wave, i * wideCount + space, hei / 2, wideCount - space, hei / 4, "Position" + i);
println(shuffledxpos[i]);
}
}
//DRAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
function draw() {
background(170);
//DRAW POSITIONS, THEN BLOCKS
for (i = 0; i < units; i++) {
p[i].display();
}
for (i = 0; i < units; i++) {
myBlocks[i].display();
}
// DRAW CHECK
stroke(15);
fill(0, 255, 0);
rect(check.x, check.y, check.r, check.r);
stroke(15);
fill(0);
text(check.name, check.x + 15, check.y + 45);
//DRAW MORE AND LESS BUTTONS
fill(50, 0, 0);
rect(wid - 50, 10, 40, 20);
rect(wid - 50, 40, 40, 20);
fill(255);
text("more", wid - 43, 25);
text("less", wid - 43, 55);
}
//MOUSES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
function mousePressed() {
//if we press on blocks
for (i = 0; i < units; i++) {
myBlocks[i].mousePressedOn(mouseX, mouseY);
//middleC.rate(myBlocks[i].mousePressedOn(mouseX, mouseY));
//if we press on Check
if (mouseX > check.x && mouseX < check.x + check.r && mouseY > check.y && mouseY < check.y + check.r) {
test();
}
}
//if we pressed on MORE
if (mouseX > wid - 50 && mouseX < wid - 10 && mouseY > 10 && mouseY < 30 && units < 24) {
background(170);
var _units = units + 1;
units = _units;
println(units);
middleC = loadSound('CRhodes.mp3');
//middleC = loadSound('middleC.mp3');
//middleC = loadSound('AGlockenspiel.mp3');
//VAR BLOCKS;;;;;;;;
var dis = (1 / units) * .1; //54 is the aprox distance between A4 and B4.
var wideCount = (wid - 10) / units;
var space = 10;
//SHUFFLE XPOS
var xpos = [];
for (var i = 0; i < units; i++) {
append(xpos, i); //* wideCount + 100); append(myArray, "Peach") //print(myArray) // ["Mango", "Apple", "Papaya", "Peach"]
}
var shuffledxpos = shuffle(xpos);
println(xpos);
println(shuffledxpos);
//INITIALIZE BLOCKS,POSITIONS AND CHECK
for (i = 0; i < units; i++) {
var xposDef = shuffledxpos[i] * wideCount + space;
var yposDef = hei / 4;
var widDef = 25;
var heiDef = 70;
var wave = A + (i * dis);
myBlocks[i] = new Block(wave, xposDef, yposDef, widDef, heiDef, "block" + i);
p[i] = new Position(wave, i * wideCount + space, hei / 2, wideCount - space, hei / 4, "Position" + i);
println(shuffledxpos[i]);
}
}
//if we pressed on LESS
else if (mouseX > wid - 50 && mouseX < wid - 10 && mouseY > 40 && mouseY < 60 && units > 1) {
background(170);
_units = units - 1;
units = _units;
println(units);
middleC = loadSound('CRhodes.mp3');
//middleC = loadSound('middleC.mp3');
//middleC = loadSound('AGlockenspiel.mp3');
//VAR BLOCKS;;;;;;;;
dis = (1 / units) * .1; //54 is the aprox distance between A4 and B4.
wideCount = (wid - 10) / units;
space = 10;
//SHUFFLE XPOS
xpos = [];
for (i = 0; i < units; i++) {
append(xpos, i); //* wideCount + 100); append(myArray, "Peach") //print(myArray) // ["Mango", "Apple", "Papaya", "Peach"]
}
shuffledxpos = shuffle(xpos);
println(xpos);
println(shuffledxpos);
//INITIALIZE BLOCKS,POSITIONS AND CHECK
for (i = 0; i < units; i++) {
xposDef = shuffledxpos[i] * wideCount + space;
yposDef = hei / 4;
widDef = 25;
heiDef = 70;
wave = A + (i * dis);
myBlocks[i] = new Block(wave, xposDef, yposDef, widDef, heiDef, "block" + i);
p[i] = new Position(wave, i * wideCount + space, hei / 2, wideCount - space, hei / 4, "Position" + i);
println(shuffledxpos[i]);
}
}
}
function mouseDragged() {
//change the position
for (i = 0; i < myBlocks.length; i++) {
if (myBlocks[i].weAreMoving) {
// change the position
myBlocks[i].x = mouseX;
myBlocks[i].y = mouseY;
}
myBlocks[i].display();
}
}
function mouseReleased() {
for (i = 0; i < myBlocks.length; i++) {
myBlocks[i].display();
if (myBlocks[i].weAreMoving) {
myBlocks[i].weAreMoving = false;
}
}
}
//CHECKING;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
function inPosition() {
println('checking inPosition');
for (i = 0; i < units; i++) {
if (myBlocks[i].x > p[i].x && (myBlocks[i].x + myBlocks[i].wid) < (p[i].x + p[i].wid) && myBlocks[i].y > p[i].y && (myBlocks[i].y + myBlocks[i].hei) < (p[i].y + p[i].hei)) {
into = true;
println(myBlocks[i] + 'into is ' + into);
} else {
into = false;
println(myBlocks[i] + 'into is ' + into);
}
}
}
function test() {
inPosition();
println('checking testing');
println('Global ' + 'into is ' + into);
if (into === false) {
println(uncorrect);
fill(0);
text(uncorrect, 300, 300);
return true;
} else {
println(correct);
return false;
fill(0);
text(correct, 300, 300);
}
}
//CLASSES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
function Block(_wave, _x, _y, _wid, _hei, _name) {
this.wave = _wave;
this.x = _x;
this.y = _y;
this.wid = _wid;
this.hei = _hei;
this.name = _name;
this.weAreMoving = false;
}
Block.prototype.display = function() {
fill(255);
rect(this.x, this.y, this.wid, this.hei);
}
Block.prototype.mousePressedOn = function(mouse_X, mouse_Y) {
if (mouseX > this.x && mouseX < this.x + this.wid && mouseY > this.y && mouseY < this.y + this.hei) {
println("clicking on " + this.name);
this.weAreMoving = true;
println('wave equal to ' + this.wave);
middleC.rate(this.wave)
middleC.play();
return wave;
}
}
function Position(_wave, _x, _y, _wid, _hei, _name) {
this.wave = _wave;
this.x = _x;
this.y = _y;
this.wid = _wid;
this.hei = _hei;
this.name = _name;
}
Position.prototype.display = function() {
fill(255, 0, 0);
rect(this.x, this.y, this.wid, this.hei);
}
Answers
Which text doesn't work? When I run this code (after removing all the audio stuff which I can't run without the sound file) I see text 'more', 'less', 'CHECK'...