Hey guys! I hate arrays... a LOT.
To the point where I don't use them.
Why? Because I fail to understand how to use arrays and why to use them effectively.
I've come into a situation in game development where I feel I NEED TO USE AN ARRAY.
So, now is the time!
Here is my situation:
I have a "player" class, where players inherit the images to be displayed.
I also have a "main" class, where the players are initialized as variables.
So somewhere in my code I have:
player p1 = new player()
player p2 = new player()
Lets say I want to create a boundary obstacle.
My p1 is created through paintComponent, which I initialize a new instance of the "player" graphic.
Graphics2D Player1GFX = playergfx.create();
When the new Graphics2D variable, Player1GFX, is drawn with the DrawGraphics() method (via paintComponent) I specify the x and y variables, as well as the "p1" class we created to grab the image.
Because I am using paintComponent, I have to use "ClipBounds" to determine when intersection occurs.
Question:
How do I properly create a new "boundary" class that will have the SAME image, but all act as separate pieces that I can call upon individually? I want to specify that all 'player' variables that inherit from player() class will have a specific reaction to colliding with a "boundary" brick. I feel I need to make an array of "bricks" to achieve this.
To the point where I don't use them.
Why? Because I fail to understand how to use arrays and why to use them effectively.
I've come into a situation in game development where I feel I NEED TO USE AN ARRAY.
So, now is the time!
Here is my situation:
I have a "player" class, where players inherit the images to be displayed.
I also have a "main" class, where the players are initialized as variables.
So somewhere in my code I have:
player p1 = new player()
player p2 = new player()
Lets say I want to create a boundary obstacle.
My p1 is created through paintComponent, which I initialize a new instance of the "player" graphic.
Graphics2D Player1GFX = playergfx.create();
When the new Graphics2D variable, Player1GFX, is drawn with the DrawGraphics() method (via paintComponent) I specify the x and y variables, as well as the "p1" class we created to grab the image.
Because I am using paintComponent, I have to use "ClipBounds" to determine when intersection occurs.
Question:
How do I properly create a new "boundary" class that will have the SAME image, but all act as separate pieces that I can call upon individually? I want to specify that all 'player' variables that inherit from player() class will have a specific reaction to colliding with a "boundary" brick. I feel I need to make an array of "bricks" to achieve this.