week12
打地鼠程式
目標:開始的按鈕,地鼠出現的動,關卡
PImage img,imgb; int state = 0; void setup() { size(1200, 800); } void draw() { if (state == 0) { drawStartScreen(); } else if (state == 1) { drawCircles(); img = loadImage("gopher.png"); image(img, 165, 180, 150, 150); } } void drawStartScreen() { background(255); fill(0); textSize(50); textAlign(CENTER, CENTER); text("START GAME", width / 2, height / 2); } void drawCircles() { imgb = loadImage("grass.png"); image(imgb, 0, 0, width, height); ellipse(width / 5, height / 2.5, 150, 50); ellipse(width / 2, height / 2.5, 150, 50); ellipse(width / 1.25, height / 2.5, 150, 50); ellipse(width / 5, height / 1.25, 150, 50); ellipse(width / 2, height / 1.25, 150, 50); ellipse(width / 1.25, height / 1.25, 150, 50); } void mousePressed() { if (state == 0 && mouseX > width / 2 - 100 && mouseX < width / 2 + 100 && mouseY > height / 2 - 25 && mouseY < height / 2 + 25) { state = 1; } }


沒有留言:
張貼留言