This is my first post here ever so I’m gonna format it intuitively. I’m attempting to remake a game I already made months ago (using scratch) into processing. Here’s the game in scratch…
https://scratch.mit.edu/projects/240948644/ (if it doesnt load I’ll try to post link that does)
Here’s the code in processing…
float x = 0;
float y = 0;
Level[] level1 = {
Wall[] walls = new Wall[100];
Player1[] player = new Player1[1];
void setup(){
// Scratch area size = (480, 360)
//scratch + 20% X and Y (624, 468)
//Size I originally wanted size(1210, 610);
//Size of actual scratch area plus 5% of each X and Y size(504, 378);
//Size of scratch area doubled then added 5% (1008, 756);
size(624, 468);
}
void draw(){
//Default background to every level
background(255);
walls[1] = new Wall(-20, -20, 60, height+20);
walls[1].draw();
walls[2] = new Wall(width-40, -20, width+20, height+20);
walls[2].draw();
walls[3] = new Wall(-20, -20, width+20, 60);
walls[3].draw();
walls[4] = new Wall(-20, height-40, width+20, height+20);
walls[4].draw();
//All 4 "rect"s are the walls of the game universally
/*fill(0);
rect(-20, -20, 60, height+20);
fill(0);
rect(width-40, -20, width+20, height+20);
fill(0);
rect(-20, -20, width+20, 60);
fill(0);
rect(-20, height-40, width+20, height+20);
*/
//Level 1
fill(0);
rect(40, 40, width/3, height/2);
fill(0);
rect(width0.6, height0.35, 564, 387);
/*
//Level 2:
//right-most wall
fill(0);
rect(width0.65, 0, width0.15, height*0.7);
//bottom left chunk
fill(0);
rect(0, height0.5, width0.5, height*0.5);
//middle wall
fill(0);
rect(width0.3, height0.2, width0.2, height0.3);
//top left lip
fill(0);
rect(width0.15, height0.2, width0.2, height0.1);
*/
/*
//Level 3:
//Top portion
fill(0);
rect(0, 0, width, height*0.3);
//Bottom portion
fill(0);
rect(width0.3, height0.6, width*0.4, height);
*/
//Level 4:
//fill(0);
}
class Key{
float x;
float y;
float xS;
float yS;
float red;
float green;
float blue;
Key(){
}
Key(float xPos, float yPos, float xSize, float ySize, float r, float g, float b){
float x = xPos;
float y = yPos;
float xS = xSize;
float yS = ySize;
float red = r;
float green = g;
float blue = b;
}
void draw(){
fill(red, green, blue);
ellipse(x, y, xS, yS); //need to draw key universally
}
}
class Player1{
float x;
float y;
float xSi;
float ySi;
float xSp;
float ySp;
//boolean isTouchingOuterWall;
//boolean isTouchingInnerWall;
boolean collisionWithRect;
Player1(){
}
Player1(float xPos, float yPos, float xSize, float ySize, float xSpeed, float ySpeed){
float x = xPos;
float y = yPos;
float xSi = xSize;
float ySi = ySize;
float xSp = xSpeed;
float ySp = ySpeed;
}
void draw(){
fill(255, 255, 0);
rect(x, y, xSi, ySi); //will make it more than just a rectangle
}
void move(){
if (keyPressed){
if (key == CODED){
if (keyCode == LEFT){
x -= xSp;
if (collisionWithRect == true){
x -= -xSp;
}
} else if (keyCode == RIGHT){
x += xSp;
if (collisionWithRect == true){
x += -xSp;
}
} else if (keyCode == DOWN){
y += ySp;
if (collisionWithRect == true){
y += -ySp;
}
} else if (keyCode == UP){
y -= ySp;
if (collisionWithRect == true){
y += -ySp;
}
}
}
}
}
}
/*boolean collision(Wall wall){
}*/
class Wall{
float x = 0;
float xSize = 0;
float y = 0;
float ySize = 0;
Wall (float xOne, float yOne, float xTwo, float yTwo){
x = xOne;
y = yOne;
xSize = xTwo - xOne;
ySize = yTwo - yOne;
}
void draw(){
fill(0);
rect(x, y, xSize, ySize);
}
}
My general question is what is the most efficient/easy way to “save” each level’s walls, keys, doors, and anything that stays stationary into an object array called “level1[]” and so on. And boolean statements which make the entire array turn off and on. “on” means everything in array draws itself and is visible, and “off” means the entire array hides.
At first, I want an array of walls and keys up to 100 or so, and when I need to use 1/100 of them for a level, I simply create it specifically for the level but then add it to an array titled “level1”.
All the logic to do with collision only needs to do with the walls. Keys can be moved right through, and enemies anyway reset everything. I want a universal “reset” boolean for each level.