반응형
Dora pt; // doraenmon can move with keybords
Icecream[] icecream = new Icecream[50] ; // list of ice-cream
PImage LogoC, Logo, Doraending, Prize, bg, bg2;
PFont DORAFont;
float speed = 10;
String l;
int time;
int score;
int gameScreen = 0;
boolean moveRight= false;
boolean moveLeft= false;
boolean onDora = false;
boolean canHit = true;
boolean beforeGame;
boolean endGame;
float StackTopY = 0;
// ------------------------------------------------------------
void setup () {
size(700, 800);
pt = new Dora();
for (int i=0; i<icecream.length; i++) {
if(i % 3 == 0)
icecream[i] = new Icecream ( "tungtung.png", -1);
else if(i % 3 == 1) {
int value = int(random(2));
icecream[i] = new Icecream ( "dorayaki" + value + ".png", 1);
}
else
icecream[i] = new Icecream ( "heart.png", 2);
}
StackTopY=pt.y;
}
void draw() {
if (gameScreen == 0) {
initScreen();
} else if (gameScreen == 1) {
gameScreen();
} else if (gameScreen == 2) {
gameOverScreen();
} else if (gameScreen == 3) {
gameWinScreen();
} else if (gameScreen == 4) {
scoreScreen();
}
}
// ------------------------------------------------------------
void initScreen() {
background(255);
color c1 = color(0, 61, 167);
color c2 = color(255);
gradientBackground(c1, c2);
LogoC = loadImage("doracircle.png");
LogoC.resize(380, 300);
image(LogoC, 150, 200);
textAlign(CENTER);
fill(random(0,200), random(0,140), 0);
DORAFont = createFont("DORAEMON.ttf",80);
textFont(DORAFont);
text("!Feed DORAEMON!", 350, 120);
fill(100,0,150);
textFont(DORAFont, 30);
text("Let Doraemon eat the heart and dorayaki", 350, 550);
textFont(DORAFont, 30);
text("if Doraemon eats ugly face then you will lose the point", 330, 590);
fill(200,30,50);
textFont(DORAFont, 80);
text("Press Mouse Button!", 350, 700);
}
void scoreScreen() {
background(255,255,0);
color c1 = color(167, 61, 167);
color c2 = color(255);
gradientBackground(c1, c2);
LogoC = loadImage("heart.png");
LogoC.resize(200, 200);
image(LogoC, 90, 100);
fill(0, 0, 255);
textFont(DORAFont, 60);
text("Heart +2pt", 430, 230);
LogoC = loadImage("dorayaki0.png");
LogoC.resize(200, 200);
image(LogoC, 30, 250);
LogoC = loadImage("dorayaki1.png");
LogoC.resize(200, 200);
image(LogoC, 90, 250);
fill(0, 0, 255);
textFont(DORAFont, 60);
text("Dorayaki +1pt", 430, 380);
LogoC = loadImage("tungtung.png");
LogoC.resize(200, 200);
image(LogoC, 90, 430);
fill(255, 0, 0);
textFont(DORAFont, 60);
text("Ugly Face -1pt", 430, 530);
fill(200,30,50);
textFont(DORAFont, 80);
text("Click to start!", 350, 700);
}
void gameScreen() {
bg = loadImage("bg.jpg");
bg.resize(700,800);
background(bg);
Logo = loadImage("logo1.png");
Logo.resize(240, 70);
image(Logo, 200, 120);
//Logo.resize(150, 40);
score();
pt.move();
pt.display();
for (int i=0; i<icecream.length; i++) {
icecream[i].display();
}
hitDora();
reachBottom();
}
void gameOverScreen() {
bg2 = loadImage("bg2.jpeg");
bg2.resize(700,800);
background(bg2);
Doraending = loadImage("jingu.png");
Doraending.resize(430, 500);
image(Doraending, -40, 110);
textAlign(CENTER);
fill(0,random(50,150),random(100,250));
textSize(100);
text("Do It Again!", width/2, 140);
fill(43, 106, 176);
textSize(180);
text(score, width/2, 395);
textSize(35);
text("Press Enter or Click to Restart", width/2, 740);
}
void gameWinScreen() {
color c1 = color(3, 96, 176);
color c2 = color(222, 91, 167);
gradientBackground(c1, c2);
Prize = loadImage("brwin.png");
Prize.resize(420, 390);
image(Prize, 90, 230);
textAlign(CENTER);
fill(255);
textSize(120);
text("YOU WIN!", width/2, 210);
textSize(30);
text("Press Enter or Click to Restart", width/2, height-125);
}
// ------------------------------------------------------------
void keyPressed() {
if (key == CODED) {
if (keyCode == RIGHT) {
moveRight = true;
} else if (keyCode == LEFT) {
moveLeft = true;
}
}
if (key== ENTER || key == RETURN) {
if (gameScreen==2) {
restart();
}
if (gameScreen==3) {
restart();
}
}
}
void keyReleased() {
if (key == CODED) {
if (keyCode == RIGHT) {
moveRight = false;
} else if (keyCode == LEFT) {
moveLeft = false;
}
}
}
public void mousePressed() {
if (gameScreen==0) {
startScoreScreen();
return;
}
if (gameScreen==2) {
restart();
return;
}
if (gameScreen==3) {
restart();
return;
}
if (gameScreen==4) {
startGame();
return;
}
}
//can restart when pressing both mouse/enter
void startGame() {
gameScreen=1;
}
void startScoreScreen() {
gameScreen=4;
}
void gameOver() {
gameScreen=2;
}
void youWin() {
gameScreen=3;
}
void restart() {
score = 0;
pt = new Dora();
for (int i=0; i<icecream.length; i++) {
if(i % 3 == 0)
icecream[i] = new Icecream ( "tungtung.png", -1);
else if(i % 3 == 1)
icecream[i] = new Icecream ( "dorayaki1.png", 1);
else
icecream[i] = new Icecream ( "heart.png", 2);
}
gameScreen = 1;
StackTopY=pt.y;
}
// ------------------------------------------------------------
void score() {
fill(222, 71, 150);
textSize(40);
text("DORA POINTS: " + score, width/2, 70);
if (score==15) {
youWin();
}
}
void hitDora() {
for (int i=0; i<icecream.length; i++) {
if (!icecream[i].attached &&
canHit &&
dist(icecream[i].x, icecream[i].y,
pt.x, pt.y) < 52) {
if(score == 0 && icecream[i].score < 0) {
gameOver();
return;
}
icecream[i].l++;
score+= (icecream[i].score);
icecream[i].yFixed=min(icecream[i].y, StackTopY);
StackTopY=icecream[i].yFixed-22;
icecream[i].attached=true;
}
}
}
void reachBottom() {
for (int i=0; i<icecream.length; i++) {
if (icecream[i].y > height - 20) {
if(icecream[i].score < 0 && score <= 0)
gameOver();
}
}
}
void gradientBackground(color c1, color c2) {
for (int i=0; i<=width; i++) {
for (int j = 0; j<=height; j++) {
color c = color(
(red(c1)+(j)*((red(c2)-red(c1))/height)),
(green(c1)+(j)*((green(c2)-green(c1))/height)),
(blue(c1)+(j)*((blue(c2)-blue(c1))/height))
);
set(i, j, c);
}
}
}
반응형