I need to make a text-based RPG game with java. The first part of the assignment is super simple. we just use vertical lines and underscores to make a little rectangle and then add symbols inside the rectangle as things move, act, die, etc.
I've never done this before, so I want to run my idea by you:
What do you think about doing something like angry birds but with flying moving targets? There would be a little "bird tank" at the bottom left of the screen that would shoot birds. Another question: I'm not entirely sure how I would create a gun that shoots at different angles in a text-based format. And how would it work with aiming and shooting and timing, and such?
Update:
I think I'm going to try out a tank game. But I'm confused about how to implemenent the angle of the turret.
I would put the tank in the bottom left corner, put I only have text symbols at my disposal. I don't see how its possible to let the user control the turret, and make it move up and down by small amounts (at least, not until we start using images/gui's.)
Any ideas?
First, in order to make your idea meet the criteria of an RPG, you would have to add a few components. Your gun would need to gain experience as you hit your targets, and would have to level up after enough time. It could gain better speed or accuracy. It could also earn upgrade points that you could spend on different birds to shoot. It would probably also be cool if your targets had hit points and you had to hit some of them multiple times to kill them. You could show the damage by changing the color of the text. These elements will give it more of an RPG feel so that you can meet the criteria of the assignment.
As for the mechanics of the game, you're going to have to write some sort of physics engine. It doesn't have to be very complicated, just enough to be able to calculate or modify a trajectory and determine if there was a collision. This engine would have some sort of a tick() method on it where it would advance the positions of the birds and targets and then you could call a getCollisions() method and handle each one. That's the simple way. The more complex way would involve giving the engine its own thread where it runs constantly, as fast as it can. Then, when there is a collision, it fires off an event to a listener, and you set up some sort of handler to apply the damage to the target, award points, etc.
I would recommend you model the world in finer resolution than your text console. Make the text console simply mark the birds and targets by rounding them to the nearest 80x25 console location, but internally use a much higher resolution. This will keep it looking more realistic, even in an environment with such a poor resolution.
For the controls of the game, I would recommend putting a target reticule on the screen. The user can move it around with their arrow keys to aim and press the space bar to shoot. They wouldn't hit the target because gravity should pull the bird downward, or perhaps because the bird is a special shot that splits into pieces. Regardless, they would learn how to lead their targets appropriately, and that would be the skill of the game.
It's a complicated project. Good luck!
Related
I wasn't sure if this was the correct forums to post this on; I was considering the Game Development site.
I'm developing a game in LibGDX (Java) and I've set up a btKinematicCharacterController to control the player. This handles the jumping, walking, and everything else.
However, I've come across a problem. Imagine that the character is standing on a slope -- even a very gradual one. The character will slowly slide down the slope, which is very annoying for the purpose of my game (and, I imagine, most.) This is because if a player wants to just stand on a slope, they can't.
I think this is happening because of the collision detection resolution. The player may very slightly fall through the floor, and since it's on a slope, would then be pushed out along the normal of the slope. This would mean, simply, they'd be pushed along slightly.
My actual player model is a capsule, and I use a ghost object for the btKinematicCharacterController.
So how can I make sure that my character doesn't slide down slopes? Of course, it needs to still have physics so that it can jump, and collide with other objects.
One of the popular approach is to disable gravity when there are >=1 platforms under the character's foot.
It can be done by :-
sensor (setSensor(true) + collision callback)
For more information about collision callback : http://www.bulletphysics.org/mediawiki-1.5.8/index.php/Collision_Callbacks_and_Triggers
ray test : http://bulletphysics.org/mediawiki-1.5.8/index.php/Using_RayTest
Another approach is to hard code it (link to a short discussion - 2D Metroid related), but it is a hard work and heavily depend on the stage design.
This video may help. It is Unity, not related to Bullet, but seems applicable.
I am also very interested in this problem. Please don't accept if it doesn't solve.
To reader, if there are better answers, feel free to share.
I'm working on a simple game with libGDX and want to make the main character to be fixed in the center of the screen and the world move when I press a button. I was wondering how to do... I was thinking to add a physicsBody to the world that contains other bodies and apply impulses to it when the button is pressed, is this possible in libGDX? And if it is, can i apply other impulses or forces to the bodies contained in the world's physicsBody? I think this way would be the best for me if it is possible, because i have to work a lot with physics, but if you have other ideas tell me please
There's no need to think about applying forces to all the non-character objects, that's just going to get messy very quickly.
The simple solution is to move your camera so that it always looks at your character. So your game loop may look something like:-
Process input
Update physics, character and other entity positions.
Move camera to point at character's new position.
Render
This way, you can update your game world without having to think about the camera at all. Then, when it comes to rendering, you can position your camera and render your graphics without needing to know anything about the game physics. It keeps the physics and rendering relatively independent, and makes it much easier to change things in the future.
For example, you may later decide that you want the camera to follow your character for the most part, but then follow a baddy whilst it is their turn. This is now easy to do, you just specify the character / entity to look at in your game logic, and then position the camera to look at whatever target that is, before you render.
As it stands, I have a map with roads on it and vehicles are able to drive back and forth from south to north and east to west (and opposite ways as well). I have used JPanels thus far to represent the vehicles. However now it's becoming a bit difficult to handle because I want to turn the vehicles at junctions and smooth lane changing etc.
So it doesn't seem like JPanel is the optimal choice for this. What I've tried so far is to use the Shape interface to draw polygons and use these as vehicles, however I'm not sure that this is the right choice.
I will eventually want to construct my own vehicle image so the solution will have to either be able to add the image as it's background or something similar and still be able to perform operations such as rotation, transformation etc.
Any guidance on this will be much appreciated.
Personally, using JPanel isn't a bad choice, what you need to be able to do is extend it's capabilities to allow you to paint changes in orientation of the vehicle as it turns.
This is going to require some animation - you going to want to know how long it would take a vehicle to complete a turn so you can calculate the angel of the vehicle over time.
For this, I would be using AffineTransformation, check here for some examples.
You will also need to change the size of the component as the vehicle turns, check here for the answer.
Lane changes would be a similar (if easier) concept. The basic idea would be to have a start position and end position of the translation and move to that position over time. Again, you would need to know the amount of time it would take to complete the translation.
I'm currently working on my 2D game project (Java), but so far any kind of game logic or AI has been crudely implemented. For instance, say I need to randomly position a bunch of sprites a long the top of the screen, I'd be using the Random class to do this. I'd simply use Random.nextInt( size of x axis on which to spawn ); Although this does work I'd be interested to hear how I should really be going about this kind of thing.
As a second scenario (this is why I put AI in the title, although it's not really AI), say I want to have my characters randomly blink in a life-like fashion. What I'd do here is use the Random class to calculate a % (say 20% chance) of blinking and call it every second.
Any suggestions on how I should really be going about this would be greatly appreciated.
Google for a paper titled "Steering Behaviors" by Craig Reynolds. It address just this and you'll find great ideas to start with specifically some nice ideas for giving groups of sprites the appearance of 'intelligent' movement. The key for him in his different behaviors, i.e. flocking, etc. is making properties of any given sprite dependent on those of some other sprite. You could even go so far as to say, like -- any given sprite will blink only if it's two neighbors just have blinked. Something or other along those lines.
Hope this helps!
Are you using an OOP (Object-Oriented approach)? If not, you should definitely look into it. It's really simple with java and can speed up your development time and neaten your code.
I would make a sprite class, and give them a function, say actionSpawn, or actionMove (I like to start my "action" functions with the word action so they are easily identifiable). In this function you would encapsulate the Random.nextInt function, to set the sprite's x and/or y position.
You could use the same approach to make them blink.
Im making small 2D game and i would like how should, theoretically work jumping and standing on objects.
For jumping should there be some kind of gravity?Should i use collision detection?
Good example of what i want to undestand is jumping in Mario.
I think for jumping it would be best to create some simple model which use "game time". I would personally create some physical model based on gravity, but you can go for whatever you want.
If you want your character to "stand" on object, you will have to create some collision detection. Good start is to approximate object by one or more circles (or lines) compute collision of them and in case the approximation collides determine the final state by some more precise method.
In terms of should there be gravity and collision detection - personally for such a thing I'd say yes and yes! It doesn't have to be complicated but once you have those things in place the pseudocode for the "main loop" becomes relatively simple:
if not colliding with object underneath, apply gravity
if user presses jump key and not colliding with surface //i.e. if we're in the air already, don't jump again
apply upward velocity
That is of course oversimplified and there are other corner cases to deal with (like making sure when you're coming down after jumping, you don't end up embedded or potentially going through the floor.
You might want to take a look at Greenfoot which handles a lot of things like all the Java2d stuff, collision detection etc. for you. Even if you don't stick with it it'd be a good platform for building a prototype or playing around with the ideas talked about.
Standing on objects implies collision detection, you can approximate the characters and the environment objects with primitive shapes (rectangles, circles etc.).
To check if to shapes are colliding, check axis one by one (X and Y axis in your case). Here is an explanation of the "separating axis theorem" (Section 1).