xxxxxxxxxx
94
let tx = 0,
ty = 0;
let tiles = [];
let items = [];
function preload() {
bg = loadImage("pre.png");
eggs = loadImage("items.png");
document.addEventListener('touchstart', {});
}
function setup() {
createCanvas(displayWidth, displayHeight);
for (i = 0; i < 250; i++) tiles[i] = 0;
for (i = 0; i < 5; i++) {
r = floor(random(100));
while (items.includes(r)) r = floor(random(80));
items[i] = r;
}
}
function draw() {
background(bg);
if (touches.length >0) {
tx = floor(touches[0].x / (displayWidth / 10));
ty = floor(touches[0].y / (displayHeight / 10));
tiles[ty * 10 + tx] = 1 + items.includes(ty * 10 + tx);
} else {
tx = floor(mouseX / (displayWidth / 10));
ty = floor(mouseY / (displayHeight / 10));
tiles[ty * 10 + tx] = 1 + items.includes(ty * 10 + tx);
}
for (i = 0; i < 250; i++) {
noStroke();fill(color(255, 64));
if (tiles[i] > 0) noFill();
rect(
((i % 10) * displayWidth) / 10,
(floor(i / 10) * displayHeight) / 10,
displayWidth / 10,
displayHeight / 10
);
if (tiles[i] == 2) {
noFill();
item = items.indexOf(i);
image(
eggs,
((i % 10) * displayWidth) / 10,
(floor(i / 10) * displayHeight) / 10,
displayWidth / 8,
displayWidth / 8,
32 * item,
0,32,32
);
}
}
}
function mousePressed() {
if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
let fs = fullscreen();
if (!fs) {
fullscreen(true);
} // print (items)
}
tx = floor(mouseX / (displayWidth / 10));
ty = floor(mouseY / (displayHeight / 10));
tiles[ty * 10 + tx] = 1 + items.includes(ty * 10 + tx);
}
/*
function touchStarted() {
if (touches[0].x > 0 && touches[0].x < width && touches[0].y > 0 && touches[0].y < height) {
let fs = fullscreen();
if (!fs) {
fullscreen(true);
} // print (items)
}
tx = floor(touches[0].x / (displayWidth / 10));
ty = floor(touches[0].y / (displayHeight / 10));
tiles[ty * 10 + tx] = 1 + items.includes(ty * 10 + tx);
}
*/
function touchStarted(){
return false;
}
function touchMoved(){
return false;
}
function touchEnded(){
return false;
}