Hello all,
For school i have to make a kind of snake game. The game has the following rules:
Rules of game:
- 1 player needs to make as many points before all particles of body dissapeared.
- game should be a field of 16 by 8 blocks.
- 20 bananas are hidden in the game and are invisible. when snake eats them player gains 10 points.
- game has 10 animals on random location in the field. if snake goes over them it loses a part of the body.
- when only the head is left it should be Game Over and show score.
- no classes in the coding.
I have made a start but it is difficult to get out. I have the feeling that my base is not good either. Hopefully someone can help me on my way… Here below is the code i made so far.
int rups, fruit, score1 = 0, score2 = 0, scherm = 0, i;
int radius = 30, richtingX = 1, richtingY = 0;
float rupsX = 30, rupsY = 40;
float snelheid = 2.5;
boolean bananen = false;
boolean kersen = false;
void setup() {
size(1000, 800);
smooth();
ellipseMode(RADIUS);
}
void draw() {
background(250);
if (scherm == 0) {
scherm();
} else if (scherm == 1) {
scherm1();
} else if (scherm == 2) {
scherm2();
}
}
void fruit() {
// if (rupsX > 170 && rupsX <230 && rupsY > 480 && rupsY < 520) {
// for loop maken for fruit
bananen = !bananen;
if (rupsX > 193 && rupsX <206 && rupsY > 493 && rupsY < 506) {
fill(150, 50, 11);
noStroke();
//kers 5 punten
ellipse(200, 500, radius, radius);
textAlign(CENTER);
// score1++;
text("Score = "+score1, 450, 40);
score1++;
text("Score = "+score1, 450, 40);
} else if (rupsX > 684 && rupsX < 710 && rupsY > 184 && rupsY < 210) {
fill(255, 250, 2);
noStroke();
//banaan 10 punten
ellipse(700, 200, radius, radius);
score1++;
}
}
void keyPressed() {
if (key == CODED) {
if (keyCode == LEFT) {
richtingX = -1;
richtingY = 0;
} else if (keyCode == RIGHT){
richtingX = 1;
richtingY = 0;
} else if (keyCode == DOWN){
richtingX = 0;
richtingY = 1;
} else if (keyCode == UP){
richtingX = 0;
richtingY = -1;
}
}
}
void rups() {
//bepaling x,y rups
rupsX = rupsX + snelheid * richtingX;
rupsY = rupsY + snelheid * richtingY;
//rups mag niet uit het spel kruipen
if (rupsX > width-radius) {
richtingX = richtingX * -1;
} else if (rupsX < 30) {
richtingX = richtingX * -1;
} else if (rupsY > height-radius) {
richtingY = richtingY * -1;
} else if (rupsY < 30) {
richtingY = richtingY * -1;
}
fill(50, 168, 111);
noStroke();
ellipse(rupsX, rupsY, radius, radius);
fill(250);
ellipse(rupsX+10, rupsY-5, 5, 2);
ellipse(rupsX-10, rupsY-5, 2, 3);
fill(50, 168, 111);
}
void scherm() {
fill(0);
textAlign(CENTER);
textSize(30);
text("THE CENTIPEDES GAME", width/2, height/2-195);
rectMode(CENTER);
fill(0);
rect(width/2, height/2-100, 300, 30);
fill(255);
textAlign(CENTER);
textSize(20);
text("1 SPELER", width/2, height/2-95);
fill(0);
rect(width/2, height/2, 300, 30);
fill(255);
textAlign(CENTER);
text("20 BANANEN", width/2, height/2+5);
fill(0);
rect(width/2, height/2+100, 300, 30);
fill(255);
textAlign(CENTER);
text("16 x 8 SPEELVELD", width/2, height/2+105);
fill(0);
rect(width/2, height/2+200, 200, 30);
fill(255);
textAlign(CENTER);
text("START SPEL", width/2, height/2+205);
if (mouseX > width/2-100 && mouseX < width/2+100 && mouseY > height/2+190 && mouseY < height/2+220) {
fill(80, 20, 20);
rect(width/2, height/2+200, 200, 30);
fill(255);
textAlign(CENTER);
text("START SPEL", width/2, height/2+205);
}
}
void mousePressed() {
if (mouseX > width/2-100 && mouseX < width/2+100 && mouseY > height/2+190 && mouseY < height/2+220) {
scherm = 1;
}
}
void scherm1() {
textSize(12);
fruit();
rups();
println(richtingX, richtingY, rupsX, rupsY);
score();
//score eenmalig maken
}
void scherm2() {
// GAME OVER
}
void score() {
textAlign(CENTER);
fill(50, 168, 111);
text("SPELER 1", 380, 40);
text("Score = "+score1, 450, 40);
}