processing - 如何在基本字母按下游戏中按下正确字母时删除椭圆?
问题描述
我是一个完全的编程初学者,这是一个处理类作业,如果这真的很明显,请道歉。对于这个任务,我正在制作一个简单的游戏,圆圈向顶部浮动,您必须键入屏幕上显示的字母才能一次弹出一个。我完成了程序的大部分部分,除了制作它以便每个正确的字母笔划删除一个圆圈。我该怎么做呢?
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();
}
}
推荐阅读
- awk - 在偶数行中计数 b 或 B
- python - 需要函数在类中分配对象名称
- flutter - Flutter:组合图表和动画包时出错
- python - OR-Tools Python - AddNoOverlap2D 不工作 - 库存切割问题
- python - 通过所有 10 项测试的嵌套列表 HackerRank 问题
- amazon-cloudformation - 具有复杂列类型的 Athena (Presto) 视图
- java - JavascriptExecutor 类型中的方法 executeScript(String, Object[]) 不适用于 Selenium 的参数 (String, WebElement) 错误
- flutter-dependencies - 我正在尝试在颤振中安装 firebase_storage 但出现错误 pod can not install 发生错误
- c# - 绑定到对象的 ListView 内的 TextBox,两种方式绑定不起作用
- php - 如何在 mongodb 中使用 laravel 7 护照?