How to use particle effects like mentioned? - java

I am developing a multi-platform game on android studio using libGDX library and java language.
The game requires the player to maneuver a main ship across 2D space using mouse input.
I am using the given ParticleEffect class in libGDX library to show its exhaust but there is a slight problem that looks like this...
This is the standing ship
and
This is when its moving upward
I need every particle to move only downwards respective to the ship regardless the ship is standing or moving.
This means that I need to add the change in (x,y) coordinates of ship into each particle of exhaust but the problem is that the (x,y) coordinates of that class are private and there is no function that lets me make any direct changes to the coordinates of individual particles.
How do I make that happen?

Not sure, if I understood the question right. But probably, you can solve your issue via marking the emitter as attached. In this case if you change draw coordinates of ParticleEffect from (x0,y0) to (x1,y1), then every particle, which is already emitted, will be moved by (x1-x0, y1-y0) as well.
See the screenshot:

Related

Fog in openGL dependent on camera position

I am trying to make a simple game using OpenGL. I have already modeled 3D scene. Now I want to add some fog to make it look like in horror. I have used this code below
gl.glEnable(GL2.GL_FOG);
gl.glFogi(GL2.GL_FOG_MODE,GL2.GL_LINEAR);
gl.glFogi(GL2.GL_FOG_START,(int)1);
gl.glFogi(GL2.GL_FOG_END,(int)5);
However that just creates a static fog with some random coordinates. How to make It dependent on the camera movement? So the player will only see clearly on the set distance?
You can find the definition of glFog (and all the other OpenGL commands, even the classic ones) at www.opengl.org. Fog is always calculated according to the distance from the eye / camera / viewpoint coordinates, so you don't need to do anything special.
Be warned that glFog is part of the old classic OpenGL API and may not work reliably on modern 3D systems.

Sidescroller game with libgdx / Box2D with moving floor instead of moving player

I'd like to write a sidescroller game with libgdx and Box2D.
But instead of the moving the player and the camera to the right, the player should stay at his position and the floor should move to the left. Crates should be placed randomly and move from the right to the left of the screen as well. In addition the player should also be able to move to the left and the right of the screen without the game stopping to scroll the level.
I have no problems with using libgdx or Box2d but I'm not sure what is the best way to achieve my goal. I'd like to use physics because I will also have some bouncing balls etc. in the game which should show a physically correct behaviour and should interact with the player.
I have some ideas how to solve my problem:
Apply constant force or velocity to the floor and the crates which pushes them to the left and apply a counter force to the player so it stays at his position. When pushing the left or right button to move the player the counter force is slighty enhanced or decreased.
(As physic simulation is not 100% percent accurate I'd like to avoid this)
Move the position of the floor, player and crates but this would subvert the whole physics thing.
Use physics for anything but the player and move him directly. Therefor I'd have to do any collission detection by myself
Unforunately I'm not happy with any of these solutions. Has anybody faced a similar problem or has any advice how to solve this problem in an elegant way?
Many thanks in advance.
I recommend you to create two separate cameras: for player and for ground(floor).
Such way you will be able to move your "ground camera" as you want, the player will stay on his position. Then just don't move your player camera, move only the player body ,such way you will get effect of racetrack.
I use 4 cameras on my game (for ground, for player, for HUD and for background) it provides you lots of fixability and you can create cool scrolling effects.

2D Moving Camera (LWJGL)

I'm currently developing a 2D RPG with LWJGL, and am still in the engine stage of development. I've got a lot of the tech I want created, but one of my big problems is fixing the camera on the player. All the solutions I've seen involve moving the world and keeping the player still, which can work, but it seems apparent that this can cause some calculation issues if not closely monitored. Normally, I'd write a system where I wouldn't have to worry about it, but I refuse, because I eventually intend on adding multiplayer capability, where a moving world would be unplayable.
Is there a way to affix the camera to an object or point that can move WITHOUT using translate to move the world around? Also, I'd like to avoid Slick if possible. That would require me to rework much of my game engine as it currently stands.
Whenever you are going to project the 3d viewport onto a 2d screen you need to move everything according to the point of view of the observer (the so called camera or view).
I guess you can't escape from this. What you usually do is having a Camera object which holds position and rotation that is used to build the view matrix which is passed to the vertices of your scene through a uniform to the shaders. Passing transformation matrices to shaders is the normality so you shouldn't feel burdened by it. You can always premultiply it with the perspective matrix.
You must move the whole world to match the position of your camera just because you need to transform everything in your scene as it is seen from that point of view, otherwise how could you then project it on your screen? There is no "move the camera, keep the world still" concept.
Move the world visually, it's how every other RPG does it. Don't move the actual world's location though.
Draw everything but the ui normally, than translate it all according to the players position (i.e. glTranslate2f(-player.x,-player.y)). This is all done in the render method. On networked multiplayer, the viewport is done to that specific player (i.e. Bob's screen is translated based off Bob's position, Jane's is translated based off Jane's position). Should you instead want single-screen multiplayer, you will probably have to use mutliple framebuffers (one per player), and use them as viewports.

Third Person Perspective Camera with Opengl

I want to implement a TPP Camera for my project, but something is not working + i don't know if i use the right concept.
Should I rotate the whole scene model-view matrices except my main model, which will be centered on the screen or rotate the lookAt camera?
Other thing is how to make the model move in given direction after rotating? (I think moving the whole scene makes it easier?) + how to add collision detection to it?
Collision detection is nothing to do with openGL you use you game state variables to work that out you can manage it in the same loop as the game where you do user input and display.
You should use a LookAtMatrix for the third person camera you will have the eye component behind the player and the at somewhere infront. Persective can be implemented by using a perspective matrix.
So the matrix multiplication will look like.
PerspectiveMatrix * LookAtMatrix * worldSpacePosition
Here is a good answer from gamedev explaining a lookatmatrix, most OpenGL / Computer Graphics books will also cover this.
Are you working with the new or old pipeline model?

collision & touch + shoot methods for Android

I really need help. I am making a game app for my final year project. It is a simple game where you have to shoot a ball into a target by rebounding of walls or angled blocks. However i need help in 2 areas:
the shooting mechanism is similar to that of stupid zombies. There is a crosshairs where you touch on the screen to indicate which direction you want the ball to be shot at. On release the ball should move into that direction and hopefully gets into the target and if not gravity and friction causes it to come to a stop.
The problem is how do I code something like this?
I need the ball to rebound of the walls and I will have some blocks angled so that the ball has to hit a certain part to get to the target. The ball will eventually come to a stop if the target is not reached.
How can I make a method to create the collisions of the wall and blocks?
I have spent the last weeks trying to find tutorials to help me make the game but have not found much specific to the type of game I am making. It would be great if sample code or template could be provided as this is my first android app and it is for my final year project and i do not have much time left.
Thank you in advance
akkki
Your question is too generic for stack overflow no one is going to do your project for you. Assuming you have basic programming experience if not get books and learn that first.
Assuming you already chose Android because of your tag, and assuming 2d game as it is easier.
Pre requests:
Install java+eclipse+android sdk if you havent already.
Create a new project and use the lunar landar example, make sure it runs on your phone or emulator.
Starting sample:
The lunar landar has a game loop a seperate thread which constantly redraws the whole screen, it does this by constantly calling the doDraw function. You are then supposed to use the canvas to draw lines, circles, boxes, colours and bitmaps to resemble your game. (canvas.draw....) Lunar landar does not use openGL so its slower but much easier to use.
Stripping the sample:
You probably don't want keyevents or the lunar spaceship!
Delete everything in the onDraw function
Delete the onKeyUp, onKeyDown
Delete any errors what happen
Create a new
#Override
public boolean onTouchEvent(MotionEvent event){
return false;
}
Run it you should get a blank screen, this is your canvas to start making your game... You mentioned balls, break it down to what a ball is: A position and direction, create variables for the balls x,y direction_x and direction_y the touch event will want to change the balls direction, the draw event will want to move the ball (adding the direction x,y to the ball x,y) and draw the ball (canvas.drawCircle(x,y,radius,new Paint())) want more balls search and read about arrays. Most importantly start simple and experiment.
2 collisions
Collisions can be done in the dodraw function and broken down to: moving an object, checking if that object has passed where it is supposed to go and if so move it back before anyone notices.... There are many differently techniques of collision detection:
If your walls are all horizontal and vertical (easiest) then box collisions checks the balls new x,y+-radius against a walls x,y,width and height its one big if statement and google has billions of examples.
If your walls are angled then your need line collision detection, you basically have a line (vector) of where your ball is heading a vector of your wall create a function to check where two lines collide and check if that point is both on the wall and within the radius of your ball (google line intersection functions)
or you can use colour picking, you draw the scene knowing all your walls are red for example, then check if the dot where the new ball x,y is, is red and know you hit
Good luck, hope this helped a little, keep it simple and trial and error hopefully this gets you started and your next questions can be more specific.

Categories

Resources