- Hello! I just want to ask, how can I make that if I drag ANY of the geometric shapes will be where my mouse, and when I release my mouse, it will stay in the place where I dragged it to? Thank you!
Also, when I will get answer to 1. , I want to ask how to do that all of the shapes will fall when I click for example ‘g’.
CODE FOR BOTH QUESTIONS >
import javafx.scene.effect.Bloom;
int playerX = 400;
int playerY = 300;
color col = 0;
color col2 = 0;
color col3 = 0;
color col4 = 0;
color col5 = 0;
color col6 = 0;
int index;
int len;
int randomIndex;
int l = width / 4 ;
int m = height / 2;
int u = width / 6;
int f = height / 6;
color cComp;
String colText = "BLUE > ";
float rx, ry;
int collisionX = 266;
int collisionY = 200;
String randomFun[] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
String randomInt[] = {"0", "1", "2", "3", "4" , "5", "6", "7", "8", "9"};
void setup() {
surface.setTitle("The Playground!");
index = int(random(randomFun.length));
randomIndex = int(random(randomInt.length));
size(800, 600);
frameRate(320);
col = color (0, 0, 255);
col2 = color(0);
col3 = color(255);
col4 = color(255, 0, 0);
col5 = color(0, 255, 0);
col6 = color(255, 112, 245);
rx = random(800);
ry = random(600);
}
void draw() {
background(255);
strokeWeight(2.877);
keyPressed();
fill(0, 0, 255);
rect(collisionX, collisionY, 100, 100);
fill(col2);
rect(l, m, 20, 20);
fill(col4);
ellipse(u, f, 12, 12);
fill(col5);
ellipse(rx, ry, 70, 70);
noFill();
stroke(0);
fill(255);
ellipse(playerX, playerY, 20, 20);
noFill();
if(playerX > width - 20) {
playerX = width - 20;
}
if(playerX < 10) {
playerX = 10;
}
if(playerY > height - 20) {
playerY = height - 20;
}
if(playerY < 10) {
playerY = 10;
}
// START(())
fill(255, 112, 245);
text("FPS > " + frameRate, CENTER, CENTER + 15);
text("KEY > " + key, CENTER, CENTER + 30);
text("KEY-PRESSED > " + keyPressed, CENTER, CENTER + 45);
text("MOUSE-POSITION-X > " + mouseX, CENTER, CENTER + 60);
text("MOUSE-POSITION-Y > " + mouseY, CENTER, CENTER + 75);
text("MOUSE-CLICKED > " + mousePressed, CENTER, CENTER + 90);
text("KEY-CODE > " + keyCode, CENTER, CENTER + 105);
text("DATE > " + second() + " - " + minute()+ " - " + hour() + " - " + day() + " - " + month() + " - " + year(), CENTER, CENTER + 120);
text("RANDOM-CHARACTER > " + randomFun[index], CENTER, CENTER + 150);
text("RANDOM-INTEGER > " + randomInt[randomIndex], CENTER, CENTER + 165);
if(col == cComp) {
;
fill(0, 0, 255);
text("COL > BLUE ", CENTER, CENTER + 135);
}
if(col2 == cComp) {
;
fill(0);
text("COL > BLACK ", CENTER, CENTER + 135);
}
if(col3 == cComp) {
;
text("COL > WHITE ", CENTER, CENTER + 135);
}
if(col4 == cComp) {
;
fill(255, 0, 0);
text("COL > RED ", CENTER, CENTER + 135);
}
if(col5 == cComp) {
;
fill(0, 255, 0);
text("COL > GREEN ", CENTER, CENTER + 135);
}
if(col6 == cComp) {
;
fill(255, 112, 245);
text("COL > PINK ", CENTER, CENTER + 135);
}
// END(())
}
void keyPressed() {
if(keyPressed == true && key == 'd' || key == 'D') {
playerX = playerX + 1;
}
if(keyPressed == true && key == 'a' || key == 'A') {
playerX = playerX - 1;
}
if(keyPressed == true && key == 's' || key == 'S') {
playerY = playerY + 1;
}
if(keyPressed == true && key == 'w' || key == 'W') {
playerY = playerY - 1;
}
}
void mousePressed() {
cComp = get(pmouseX, pmouseY);
}