Sorry i was mistaken, i meant to type that it is in my game class instead of my drawing one.
Also i guess it goes down to own preferableness as well. I like having it in my player class. Since the player has to move with the keys, inventory from the player. Also how would you handle animation? just curious.
And what is the advantage of using .getplayer() instead of making a static class where you make the player in?
And i disagree with the booleans. I dont see how this is harder to read in the slightest.
It isn’t that it’s more complex, it’s more like it doesn’t flow too well. This is how I see code:
The higher level of your code (main), should be as high level as possible. So, pretty much just start().
The next level should the design of the game and should be like 90% calling other methods. This is basically just your loop and input/output.
Next level is something like a player class where there are still method calls, but there’s a lot more logic here. More like behavior.
Etc., etc., but it’s definitely a tier system (to me anyway).
I think that at like tiers 1-3, the code should read as close to english as possible. (ie if (player.isAlive()) player.draw(g)
For animation I’d have an Animation class (in the Entity/Player class) that held an array of images and kept track of what frame it was on, and every paint(), player just asks the animation what frame it’s on and draws it. Animation would be tier 4-ish.
You could do that as well. That just depends on how you want to keep track of entities. You could have an EntityManager or GameManager class that keeps track of that stuff. Either way, more or less all of your class-level variables should at least have getters.
A. Applets are mostly fine on Windows but they are quite unreliable on Linux and Mac. As beginners, it is best to stick with applets, indeed you get more feedback here in the forums if it’s an applet
B. How will it turn out bad with more tiles? A Tile class that stores the 2D array should be good enough and dynamic enough for any tile map.
C. As others have pointed out (and ehm argued over ;)) the problem is with how keyboards work. Do you notice how when typing it only prints out 1 letter instead of many letters? This is because the OS only sends 1 initial event, followed by a slight pause, then if the key is still held down it delivers a continuous stream of events until the key is released. What you do is simply set a boolean flag (only useful if you have few keys you need to monitor) or better yet is to use an array so that the game loop polls the flags if the key is pressed or not.
D. Your professor is correct. Applets are limited in function due to security. They cannot save any files and cannot read from the user file system. They can only read from their current directory (the website) and their JAR. They also cannot connect to any IP address other than the website that hosts them. To enable these functions, you need to sign your applet, a relatively simple procedure that requires user permission for the applet to run.
F. Most would say that as long as you understand the code and can get something running quickly then that is best. Others would say that you need to stick with conventions, strict rules, and certain “traditional” game designs. I am in between. You should not get caught up in making these pretty and super organized but you should also not be slacking off and putting everything in your main class. Separate logic logically (hehe pun intended ;)). Code that controls the Player should not be in Game. Code that controls the Level should not be in Player. Most importantly, Logic should not depend on Rendering. Your render code should only depend on the available data.
Your error about using a static reference to a non-static method/value is most likely due to bad design. What I do is visualize the game design in your head. Think about the intended job of every piece of code. What does it control? Who calls it? Where does it make most sense to put it? If you have a hard time visualizing things, draw it out. White boards or a pen and paper are best for this. In fact, I absolutely recommend a white board to just brainstorm before you write a single line of code. Trust me, it will help.
About what ReBirth said considering “RPG as your first project”, I do agree with that statement. An RPG is way too large for a first project. The probability that beginners give up in frustration due to unmanageable code, not enough understanding, and/or complete frustration is most likely 99%. Even though elamre pointed out that RPGs contain many basic game principles, usually it is too late to modify the entire code in a new way since it has become huge. Starting small and slowly getting bigger is always the best solution, in programming and in real life.
Wow so many replies! I see a lot of good things that will help me rewrite my mess of a program
Medals for everyone! I’m still open for more input; it’s likely that I’ll try everyone’s examples that they posted and see which one will fit best
with the way my team wants the game to feel.
I’m still in shock that everyone has been so helpful and noob friendly. I think I’ll be spending quite a bit of time here as I develop my java skills
And I guess to cut back on spam, I’ll just continue to use this thread in-case I need help with anything! :]
It’s usually best to start with a game like Pong, then get slightly more complex with each subsequent project. RPGs are very likely to induce frustration, even for experienced programmers.
I don’t see any reason why an RPG couldn’t work as a first game as long as you have the patience and motivation to stick with it even when you get frustrated. Although, it will be significantly harder to learn the basic constructs of making games while dealing with the depth of an RPG.