int[][] world;
int ROWS, COLS;
int C_SIZE = 25; // CELL SIZE (how many pixels is a cell across/up&down)
int GRASS = 0; // constant variables - not going to change
int WATER = 1; // stand-in for actual numbers - usually all-caps
int SAND = 2;
int LAVA = 3;
double health = 10.0;
double regen = 0;
boolean initialHeal = false;
double breath = 10.0;
double respiration = 0;
float blockType;
// to store where the player is
int pr, pc;
void setup() {
size(800, 600);
ROWS = height / C_SIZE;
COLS = width / C_SIZE;
// noiseSeed(5);
initBoard();
pr = ROWS / 2;
pc = COLS / 2;
}
void keyPressed() {
if (keyCode == RIGHT) {
pc++;
}else if(keyCode == LEFT){
pc--;
}else if(keyCode == UP){
pr--;
}else if(keyCode == DOWN){
pr++;
}
}
void initBoard() {
world = new int[ROWS][COLS];
//filled with 0s
for (int r = 0; r < ROWS; r++) {
for (int c = 0; c < COLS; c++) {
// 80% chance of grass, 20% chance of water
// 0.0-----0.2-----0.4-----0.6----0.8------1.0
// |-------- GRASS ----------------|- WATER -|
// 80% 20%
// float rand = random(3); // even chance b/w 0.0 and 1.0
float rand = noise(c / 10.0, r / 10.0);
if (rand <= 0.4) { // 0.0 - 0.8 -> 80%
world[r][c] = GRASS;
}
else if(rand < 0.5){ // 0.8 - 1.0 -> 20%
world[r][c] = WATER;
}else if(rand < 0.7){
world[r][c] = SAND;
}else{
world[r][c] = LAVA;
}
}
}
}
void draw() {
drawWorld();
drawPlayer();
fill(0,180);
rect(40,140,100,50);
fill(255);
textSize(18);
text("Health"+ nf((float)health, 0, 2),50,160);
text("Breath"+breath,50,180);
}
void drawPlayer() {
float x = pc * C_SIZE;
float y = pr * C_SIZE;
fill(255);
ellipseMode(CORNER);
ellipse(x, y, C_SIZE - 5, C_SIZE - 5);
// player is slightly smaller than cell
if(world[pr][pc] == LAVA && frameCount %10 == 0){
health -=0.5;
}else if(world[pr][pc] == WATER && frameCount %10 == 0){
breath -=0.5;
}else{
if(health >=10){
health = 10;
initialHeal = false;
}else if(breath > 10){
breath = 10;
}else if (health < 10){
if(initialHeal == false&&frameCount%60 ==0){
health+=0.5;
initialHeal = true;
}else if(initialHeal == true && frameCount%10==0){
health += 0.2;
}
}else if (breath < 10 && frameCount %60 ==0){
breath += 0.5;
}
}
}
void drawWorld() {
for (int r = 0; r < ROWS; r++) {
for (int c = 0; c < COLS; c++) {
int x = c * C_SIZE;
int y = r * C_SIZE;
if (world[r][c] == GRASS) {
fill(0, 255, 0); // light green
}
else if (world[r][c] == WATER) {
fill(0, 0, 100); // dark blue
}else if(world[r][c] == SAND){
fill(193, 154, 107); // yellowish
}
else {
fill(200,0,0); // darkgreen
}
rect(x, y, C_SIZE, C_SIZE);
}
}
}
/*void drawWorld() {
for (int r = 0; r < ROWS; r++) {
for (int c = 0; c < COLS; c++) {
int x = c * C_SIZE;
int y = r * C_SIZE;
if (world[r][c] == GRASS) {
fill(0, 255, 0); // dark green
}
else if (world[r][c] == WATER) {
fill(0, 0, 100); // dark blue
}else if(world[r][c] == SAND){
fill(193, 154, 107);
}
else {
fill(128); // black
}
rect(x, y, C_SIZE, C_SIZE);
}
}
}*/