如何在基本的字母按压游戏中按正确的字母时删除椭圆?
How do i remove an ellipse while pressing the correct letter in a basic letter pressing game?
我是编程的初学者,这是处理 class 作业,如果这真的很明显,我们深表歉意。对于这个作业,我正在制作一个简单的游戏,圆圈漂浮在顶部,你必须键入屏幕上显示的字母,一次弹出一个。我完成了程序的大部分部分,除了使每个正确的字母笔划都删除了一个圆圈。我该怎么做?
int l=97;
int s=0;
int visa = 0;
Bubble[] bubbles = new Bubble[20];
void setup(){
size(640,360,P2D);
for (int i = 0; i< bubbles.length; i++){
bubbles [i] = new Bubble (random(40,40));
}
}
void draw(){
background(255);
char c=char(l);
fill(0, 102, 153);
textSize(22);
text("Press this letter: "+c,160, 100);//text(stringdata, x, y, width, height)
if(millis()< 300000000&&key==c)//30 seconds
{
l=int(random(97,122));s++;
}//here is where the score gets added! s++
//random(low, high)
for (int i = 0; i < bubbles.length; i++){
bubbles[i].display();
bubbles[i].acsend();
bubbles[i].top();
}
}
class Bubble{
float x;
float y;
float diameter;
float yspeed;
Bubble(float tempD){
x = random(width);
y = height;
diameter = tempD;
yspeed = random(0.5,1.5);
}
void display(){
stroke(255);
fill(60,120,200,100);
ellipse(x,y,diameter,diameter);
}
void acsend(){
if (y > 0){
y = y - yspeed;
x = x + random(-0.5, 0.5);
}
}
void top(){
if (y < diameter/2){
y = height;
x = random(width);
}
}
}
将初始气泡数存储到变量中:
Bubble[] bubbles = new Bubble[20];
int noOfBubbles = bubbles.length;
使用 keyPressed()
,判断是否按下了正确的键。
减少气泡数量,增加分数并创建一个新的随机字符:
void keyPressed() {
char c=char(l);
if (key == c) {
if (noOfBubbles > 0) {
noOfBubbles --;
s ++;
l=int(random(97,122));
}
}
}
只画出剩余的气泡数(for (int i = 0; i < noOfBubbles; i++)
):
void draw(){
background(255);
fill(0, 102, 153);
textSize(22);
char c=char(l);
text("Press this letter: "+c,160, 100);//text(stringdata, x, y, width, height)
for (int i = 0; i < noOfBubbles; i++){
bubbles[i].display();
bubbles[i].acsend();
bubbles[i].top();
}
}
我是编程的初学者,这是处理 class 作业,如果这真的很明显,我们深表歉意。对于这个作业,我正在制作一个简单的游戏,圆圈漂浮在顶部,你必须键入屏幕上显示的字母,一次弹出一个。我完成了程序的大部分部分,除了使每个正确的字母笔划都删除了一个圆圈。我该怎么做?
int l=97;
int s=0;
int visa = 0;
Bubble[] bubbles = new Bubble[20];
void setup(){
size(640,360,P2D);
for (int i = 0; i< bubbles.length; i++){
bubbles [i] = new Bubble (random(40,40));
}
}
void draw(){
background(255);
char c=char(l);
fill(0, 102, 153);
textSize(22);
text("Press this letter: "+c,160, 100);//text(stringdata, x, y, width, height)
if(millis()< 300000000&&key==c)//30 seconds
{
l=int(random(97,122));s++;
}//here is where the score gets added! s++
//random(low, high)
for (int i = 0; i < bubbles.length; i++){
bubbles[i].display();
bubbles[i].acsend();
bubbles[i].top();
}
}
class Bubble{
float x;
float y;
float diameter;
float yspeed;
Bubble(float tempD){
x = random(width);
y = height;
diameter = tempD;
yspeed = random(0.5,1.5);
}
void display(){
stroke(255);
fill(60,120,200,100);
ellipse(x,y,diameter,diameter);
}
void acsend(){
if (y > 0){
y = y - yspeed;
x = x + random(-0.5, 0.5);
}
}
void top(){
if (y < diameter/2){
y = height;
x = random(width);
}
}
}
将初始气泡数存储到变量中:
Bubble[] bubbles = new Bubble[20];
int noOfBubbles = bubbles.length;
使用 keyPressed()
,判断是否按下了正确的键。
减少气泡数量,增加分数并创建一个新的随机字符:
void keyPressed() {
char c=char(l);
if (key == c) {
if (noOfBubbles > 0) {
noOfBubbles --;
s ++;
l=int(random(97,122));
}
}
}
只画出剩余的气泡数(for (int i = 0; i < noOfBubbles; i++)
):
void draw(){
background(255);
fill(0, 102, 153);
textSize(22);
char c=char(l);
text("Press this letter: "+c,160, 100);//text(stringdata, x, y, width, height)
for (int i = 0; i < noOfBubbles; i++){
bubbles[i].display();
bubbles[i].acsend();
bubbles[i].top();
}
}