Making a Game

Hello guys and gals. I have a big bunch of code that I would like to clean up. It feels very crowded? or maybe just messy. Anyway, I'm not so sure I want to post it here because there is so much. I will anyway, though, cause I rebel.

//Salva los chicos means save the boys in spanish lol.

PImage bee, hive, forest; PFont pixelFont, pixeruFont; boolean opening = false; float timer; float yVal = 40; float yVal2 = 360;

void setup() { size(400, 360); //loading images bee = loadImage("bee.png"); hive = loadImage("hive.png"); forest = loadImage("foresto.png"); pixelFont = createFont("PixAntiqua.ttf", 32); }

void draw() { mouseOptions(); if (opening) { background(0); story(); println(opening); } else if (yVal2 > 0) { background(forest); openingWords(); openingPics(); } else background(255); } // tried to allow more than one mouse press but I am not so good at coding lol void mouseOptions() { if (mousePressed) if ((mouseX >= 155 && mouseX <= 245) && (mouseY >= 215 && mouseY <= 275)) { background(0); opening = true; } } // bees and hives in first screen void openingPics() { //bee.width = 90, height=75 imageMode(CORNER); if (opening) tint(255, 0); else tint(255, 255); image(bee, 160, 55);

//bottom hives imageMode(CORNER); if (opening) tint(255, 0); else tint(255, 255); image(hive, 0, 300);

if (opening) tint(255, 0); else tint(255, 255); image(hive, 335, 300); } // words void openingWords() { textFont(pixelFont); textSize(50); fill(255); text("SAVE", 30, 115); fill(255); text("THE", 275, 115); fill(255); text("BOYS", 150, 190);

textSize(32); fill(255, 255, 0); text("PLAY", 175, 250); }

void story() { textFont(pixelFont); //all of the lines explaining story. String s = ("The year is 2017. Biologists have finally begun taking bees seriously"); String t = ("At this point, bee population had dropped so low, they had to make a new bee."); String o = ("These bees were \"built\" to survive all temperatures, pesticides, and any other limiting factors."); String r = ("This, in turn, allowed their population to grow exponentially."); String y = ("Biologists didn't see anything wrong with it until bees took over the world."); String ready = ("You are one of the last humans on the planet. Ready?"); String beePun1 = ("Better BEElieve it!"); //text effects like making them scroll and the blinking fill(random(255)); textAlign(CENTER); text(s, 0, yVal, 400, yVal2); text(t, 0, (yVal + 360), 400, yVal2 +360); text(o, 0, (yVal + 720), 400, yVal2 + 720); text(r, 0, (yVal + 1080), 400, yVal2 + 1080); text(y, 0, (yVal + 1440), 400, yVal2 + 1440); yVal -= 1; yVal2 -= 1; //I started using yVal2 as a way to continue code? Its kind of odd. I feel like I am using booleans to enter the next scene and so on, need help cleaning this up. if (yVal2 <= -1440) { fill(255); text(ready, 0, 40, 400, 360); }

if (yVal2 <= -1640) { text(beePun1, 0, 200, 400, 360); }

if (yVal2 <= -1650) if (keyPressed) { background(255); opening = false; } }

Answers

  • how come it posted so odd. I am way too new to this.

  • Please format your code. Edit post, select code and hit ctrl+o. Ensure there is an empty line above and below your code.

    Kf

  • edited March 2017

    Ok, so this is like a text adventure with different scenes / screens

    Instead of boolean use one variable sceneCounter (for example) of type int which is first 0 and then 1, 2...

    In draw() and in mousePressed() use switch(sceneCounter) { .... to check it

    See reference for switch()

    For the Strings you could use an array

    When you look into classes and objects (see tutorials) you could make a class Scene which would hold the mouse buttons and texts...

    Another approach

    Maybe when all scenes are basically the same (text above, 2 mouse buttons)

    You could have this part the same for all levels/ scenes and use different texts by using the arrays with sceneCounter as an index

  • If you are using p5.js you can take a look at SceneManager from https://github.com/mveteanu/p5.SceneManager

Sign In or Register to comment.