Les Morgan wrote:Zayaan,
please take note of Campbell's comments: in object oriented development you should keep your GUI separate from your process as much as possible, they are really very different. your GUI is just that, the Graphical User Interface, the view of what is happening in your game--it is only a view and not the game play itself. if done right, it becomes the animation engine that you can drop any amount of diverse graphics objects into it and use it for a base for many different projects.
As far as your transforms for walls, as others have said: why? many, including myself champion the ease of having a separate image for each wall type you will have in your game, don't over complicate things, keep it simple and the game will play faster and have less resource conflicts.
As far as your image on a label: if it works for you, then go for it. it's my preference to have 1 image in a JPanel for the GUI and write the portions of the grid that you need to change. yes, there is some elementary Math there to keep it all strait, but imo, you get a cleaner game out of it. you have one image you work on and swap into the rendering process as it is ready. the grid is only defined mathematically across your large image and your graphic objects are easily overlaid onto the image to be rendered.
Les
Rob Camick wrote:
That sounds an inefficient way to do it...
Not understanding your comment.
The code is using an Image to represent a wall. Not sure what a Rectangle2D has to do with an image.
My suggestion is to create one horizontal image/icon and one vertical image/icon. Then you just paint the Icon in the required location.
Campbell Ritchie wrote:Of course, you can have long thin rectangles to represent vertical barriers and turned the other way to repesent horizontal barriers, so we get the same conclusion that we have made the rotation redundant.
Campbell Ritchie wrote:Please don't play the game in this code, nor in this class. . . .
The Graphics object passed is a subtype of Graphics2D, . . . .
Rob Camick wrote:Note, in your looping code you do NOT need create a new image/icon for every label you create. . . .rem create a single rotated image of the horizontal image than can then be used as a vertical wall?
Rob Camick wrote:
but I just want to have many circles displayed at different (x, y) coordinates
And you were given a complete working example in your last question showing how to use an ArrayList to hold all the objects you want to paint
then the KeyListener stops working and the snake cannot move.
You should NOT be using a KeyListener. A KeyListener only works when a component has focus. When you click on the button your drawing panel loses focus. Instead you should be using Key Bindings. Key Bindings allow you to use the keyboard even when a component doesn't have focus. Read the Swing tutorial on How ot Use Key Bindings for more information.