int screen_width = 800; int screen_height = 600; int player1_score = 0; int player2_score = 0; int game_time = 60; int start_time; int mousePressedTime = 0; boolean game_over = false; PGraphics all_flowers_gfx; void setup() { size(800,600); textAlign(CENTER); textSize(24); start_time = millis(); all_flowers_gfx = createGraphics( width , height ); } void draw() { background(255); // 시간 계산 int elapsed_time = (millis() - start_time) / 1000; // 게임 종료 조건 if (elapsed_time >= game_time) { game_over = true; } // 게임 중인 경우 if (!game_over) { // 점수 표시 fill(255, 0, 0); text("Player 1: " + player1_score, 100, 50); fill(0, 0, 255); text("Player 2: " + player2_score, screen_width - 100, 50); // 마우스 이벤트 감지 if (mousePressed) { int x = mouseX; int y = mouseY; int size = 222;// (int)(Math.min(mousePressedTime / 500.0 * 50, 50)); // Player 1의 경우 if (mouseButton == LEFT) { fill(255, 0, 0); ellipse(x, y, size, size); player1_score++; } // Player 2의 경우 else if (mouseButton == RIGHT) { fill(0, 0, 255); ellipse(x, y, size, size); player2_score++; } } // 게임 시간 표시 fill(0); text("Time: " + (game_time - elapsed_time), width / 2, 50); // draw flower bouqet drawFlowers(); image(all_flowers_gfx, 0,0 ); } // 게임 종료인 경우 else { // 최종 점수 표시 fill(255, 0, 0); text("Player 1: " + player1_score, 100, 50); fill(0, 0, 255); text("Player 2: " + player2_score, screen_width - 100, 50); // 우승자 결정 및 표시 fill(0); String winner = player1_score > player2_score ? "Player 1" : "Player 2"; text(winner + " wins!", width / 2, height / 2); } } int pfap1 = -1; int pfap2 = -1; void drawFlowers(){ //player2_score int fap2 = int(player2_score*.1); if( fap2 != pfap2){ println("NEW: " + fap2); all_flowers_gfx.beginDraw(); all_flowers_gfx.noStroke(); all_flowers_gfx.fill(22,22,222); all_flowers_gfx.circle( random ( width-200,width ) , random ( 44,height ) ,20 ); all_flowers_gfx.endDraw(); pfap2 = fap2; } //player2_score int fap1 = int(player1_score*.1); if( fap1 != pfap1){ all_flowers_gfx.beginDraw(); all_flowers_gfx.noStroke(); all_flowers_gfx.fill(222,22,22); all_flowers_gfx.circle( random ( 00,200 ) , random ( 44,height ) ,20 ); all_flowers_gfx.endDraw(); pfap1 = fap1; } }