Android traffic game developing - java

I'm developing simple traffic educational game like https://market.android.com/details?id=cz.allianz.krizovatky.android . When the player taps on car sprite, it started to move with other cars. If player made a mistake in choosing car, collision happens.
My question is: what is the best way for implementing such game (game engine or direct Canvas drawing)? I'm not game developer, it is my first game. Now, I'm trying to use Andengine, it looks great, but I have not enough experience :( The main problems are:
1) How to make car automatically move along specified path with smooth turns?
2) How generate random map with crossroads?
Please, help me choose the right way of development this game. If I should use game engine, how I can solve my problems with car moving and maps?

Depending on your experience with Java, I would say that tweaking your own Canvas would give you more control for more work, but a Game Engine would let you get started faster with more design/implementation restrictions.
You might also find better answers if you asked the same question over at : https://gamedev.stackexchange.com/

Related

Best way to handle sprites in games with different screens in libgdx

Another day, another problem.
I have a sprite which has fields such as livesRemaining.
Let's say in the main game screen I fall off and I switch the screen to a "Lives Remaining" screen using the setScreen method. My problem is that the livesRemaing field is now lost.
My question is what is the best way to handle these "global game variables" which should be transition between screens.
Should I:
Create one sprite in the game class and pass this to the different screens?
Create a new sprite every screen and keep the "global game variables" in the main Game class?
I'm not sure if there is a best approach to this or if it is just a matter of taste.
Any suggestions would be appreciated.
Thanks in advance!
Using cache is good to avoid objects creation/destruction (that are expensive on java due to garbage collector on a "real time" game). It seems that you need a better data structure to handle all the game design to avoid that problems. Your option 1 is the closest approach to be a good one, but it depends on the general design.
I have a static class which contains a static reference to my game, gamescreen, and game camera.
I you do that, you can have access to any component of your game anywhere.
IE
game.player
Or
gamecamera.unproject()
I found your question very interesting because, I ended up having even problem / doubt. In case I ended up creating an ECS (System of Entities) system I ended up seeing that passing sprite values ​​to the next screen in addition to memory costs brought with it a bad ECS system practice, so I decided to create global variables for the player, because if you realize the world is rotated on top of the player and it has the importance of storing the information of the player's lives, but one thing I can tell you is that this is very delicate because we can have systems in different ways and just as francogp spoke , it all depends on the design and design patterns you are using.

jMonkey: How to have in game Terrain Modification

I'm working on programming a game, and the game environment is going to be near complete environmental control. Part of that is going to have a player dig/mine and modify the terrain in the Game.I was looking at a bloxel type environment, however I would like a nicer/realistic looking terrain. What I would like help finding/learning, is what is the algorithm/code in jmonkey to make terrain that you could modify (like Space engineers or Sub-nautica)
What I have thought of for a algorithm in short hand:
get point in terrain that the player is attempting to modify
in/decrease its height by 1
do something...
The problem I have with this algorithm, is that it will not allow for players to build caves/mines as well as other things, and the terrain will get stretched. I thought well maybe I can then turn the stretched plane into a bunch of smaller planes/points, and then just use the players orientation so they can make indentations/caves, however I do not see a way to do this in jMonkey and I think this will consume a large amount of resources. How would I do this or, would there be a more efficient way

Android only allow entry through one side of rectangle

I am creating a game where the user can move certain objects into others (these are rectangles), however I only want to be able to enter the rectangles through one side, and it will be blocked by the rest.
I have no idea how to go about doing this, I have googled and found nothing that will help me understand what I need to do. Also, how would I go about doing this if the rectangle was at an angle, say 45 degree slope?
Any help appreciated.
Thanks
Tom
Tom, if you are new to Game world you need to search more about game engine for android.
Actually you need to search more about collision detection in android.
for more help try to read more about this game engine :
http://www.andengine.org/
there are lots of engines but you need to learn them.
Regards,

designing a project in java

I don't know exactly how to design a project. It's my first year at my computer science department. I'm still learning a lot of information about Java, such as inheritance, polymorphism, abstract classes, interfaces, and so on. I am really curious about these lectures and I'm willing to learn them well. Actually I've not missed any point in these lectures and I got those very well. But nobody teach me how to desing a project and we are supposed to design a decent Java project at the very end of school.
I and my 3 classmates have decided to make a new game. It is played with only one ball and the ball has changeable two colours. Also two players have the same colour with this ball's colours. When the ball is at one player's colour, this player will be able to move the ball and try to score to another player's goal. These are our idea's basic logic and we can add some new facilities and options for this game. We are so willing to achieve this project. But... although we listen and learn from our lectures, we are really confused about to design this project step-by-step. I've just tried to demonstrate our project's logic. Meanwhile, we are still learning about GUI but we are at the very beginning of GUI. So I want to understand about what kind of ways we have to follow in order to design and make this kind of project. I just want to know about tricks and shortcuts and make the most of our knowledge about class hierachies, abstract classes, superclasses, overriding, etc.(We know everything about this terms but just don't know how to use them to design a project). If you can indicate even a little info about these, I would be so so so happy and able to change my point of view. And it would facilitate our progress. Thank you!
You might want to have a look at this Java Pong Game - it's pretty simple and includes some source code that you can study.
More general advice:
You need some way to display what is happening in the game. Probably the easiest way to display the screen in a very simple game is to use a JPanel and override it's paintComponent() method to draw the game screen correctly (e.g. draw players at the right x,y locations)
You will also need a game loop that should do the following things:
Reads any input from players
Update the positions of the objects in the game
call repaint() on the JPanel so that the screen gets redrawn
Waits a short amount of time using e.g. Thread.sleep(30) to sleep for 30 milliseconds
Loops back to the start of the game loop
I would recommend separating the classes that define the user interface (frames, panels etc.) from classes that define the game logic (players, balls etc.). Ideally the game logic classes shouldn't contain any code that relates to how they are displayed or interacted with.
For a game this simple, you don't actually need many classes. I'd recommend something like:
App - contains the main(...) function which launches the game. At a minimum it should create a JFrame and add a single GamePanel inside it, but you can create other UI elements if you like. You may choose to implement your game loop also in this class - in which case the main method should call this once all the setup has been done.
GamePanel (which extends JPanel) - contains the screen drawing logic, also perhaps detects mouse movement
Game - class that represents the entire state of the game, including the locations of both players and the ball
Player - small class to represent the player, with x,y co-ordinates
Ball - small class to represent the ball, with x,y co-ordinates and dx,dy velocity
GUI isn't really suitable for making a game.
a GUI (Graphical User Intreface, Swing in java) is a set of buttons and other text/image content, as opposed to something you can make a game with: a 3D rendering engine, such as OpenGL (most commonly used on java, be it in a framework or through low level libraries).
You here have a choice:
you can either decide to do a simpler project, for example a console program, but that will run on a GUI, for example a GUI program to move files.
or you can get to learning OpenGL or similar (JOGL for java) and make that game!
(JavaFX also might work, but I don't know much about it)
Now about design.
Generally you want to have a main "looping" class that will output every frame etc.
The main "looping" class should inherit from an interface that allows all other components to get the rendering particle, the time counter etc.
Then you want several components, one for the ball, one for any other physics object (don't forget to make them implement a "physics" interface and add them as "physical object references" in your main class, so that the physics for them are calculated each frame!), one for the background, and one for user input.
You can also add multiple others that will each do a specific action.

How to show only part of map on screen

I'm developer of game Space STG II for Android phones... and I want to add to this game new option. To do this I need to know how to do movable screen. I want to do a battle like in Heroes Might & Magic, but in mobile phone screen is small... I don't know how developers show only a part on screen of all things on map. I want to make a small map in corner which show which part of map is shown on screen.
I can't find it :/ I spend 2 days and I found only 2d tile moving, but I need smooth moves. Please help. I will give activation codes for Space STG II for help.
This question is rather vague, and so in return I can't reply with more than a vague answer. Adding this new feature to your game is very specific to how you wrote your game to begin with. If you used bad coding habits, it's going to be very difficult. From what I gather, you are trying to add a mini-map in the corner like many games have. If your model of the game and view are intertwined, you're going to have issues doing this. If you used a design pattern like Model-View-Controller http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller it would be easier to add another "view" of your model and implement it as the minimap. Sorry for the vague answer, but I don't have much else to work with seeing as you have a specific question with not many details of how your game is written.
If you're writing OpenGL code, its extremely easy- just draw the scene and move the camera to look at whatever location you want. Scrolling means moving the camera and will be smooth. Note that a tile approach works fine with OpenGL
If you're using some other 2D API, it might not be that simple. You could try to look up algorithms yourself for how people implement scrolling in widgets (think- how do people make a listview?). You'll come up with something.
Edit: If you do accept this answer, I don't really want your activation codes. Thanks anyway.

Categories