# Tag Info

15

You'll want to get a vector based on your current velocity and heading. Then use that vector to increment your position. //first get the direction the entity is pointed direction.x = (float) Math.cos(Math.toRadians(rotation)); direction.y = (float) Math.sin(Math.toRadians(rotation)); if (direction.length() > 0) { direction = direction.normalise(); } /...

8

My opinion is that an entity should have its own Update method, but not its own Render method. The entity contains most of the information necessary to update itself. It may require a bit of information about the context, such as the world, other entities nearby, etc., but most of the information is contained within the entity. Therefore it is the natural ...

8

Firstly, you need to use a switch case statement and decide which direction overrides the others, for example, if they press all four buttons, which button should be listened to for input? This gets put in order within the switch statements. Edit: For clarity about the above statement. You do need to use a switch case statement (or similar structural logic) ...

8

You can accomplish this with bitmasking. Each tile determines if it is an edge tile, based on its neighboring tiles. From the image above, we would assign a value to each neighbor. 1, 2, 4, or 8 based on its location. If the neighbor is a different tile Type than the one in the middle, you add the corresponding value. These values map out as shown in ...

7

Targeting/Attacking - That's fine. There are optimizations here, but don't worry about those yet. 2D Camera - No, that's not the way you do a camera. I'm sure your engine must have a camera class built in. If not, Slick2D has the option to translate. So before drawing your scene, you translate the scene by the 2D camera offset. Then draw your entities at ...

6

setShowFPS(false) from GameContainer. Use google (great tool trust me) and RTFM. Do you make a bit of research before asking here, you could save a lot time by simply typing slick2d hide fps in google. Please accept the answers you got.

6

What that code is doing is limiting motion to only if you're inside the screen. What you should instead do is something like this: //control code here if(player.getx() > 1024){ player.setx(1024); }else if(player.getx() < 0){ player.setx(0); } that way if the player exceeds the bounds of the screen the position will be set back to the bounds.

6

So my solution for this is that i created a SAVE class that stores all variabiles that i need public class Save implements java.io.Serializable{ Person person = null; int gold = 0; Job currentJob = null; Job currentWifeJob = null; Wife currentWife = null; Food currentFood = null; String currentCity = null; ArrayList<Child&...

5

First of all, don't listen to people who say that Java is a bad language for making games in. Everybody should start their game development career by using the tools you're already familiar with. It seems your animations are entangled with your images, which makes it difficult to share animations between objects. I propose that your animations should not ...

5

I'm not sure this kind of functionality is engine-specific. If you have a way of setting a global alpha, then you could do it just fine. Interpolate the scene alpha and the menu alpha through time, for example, for one second... timeStarted = currentTime() //Time in milliseconds since the program started, probably 0 if this is the actual start of the ...

5

You have to cast the GameContainer object, that is passed in the update method into AppGameContainer, then you can access setDisplayMode... I tested it right now, and it works. AppGameContainer gc = (AppGameContainer) container; gc.setDisplayMode(800, 600, false); But I think you need to use the dev branch of slick, as the "official" version from their ...

5

Error stacks go from the most recent call to the least recent, so the most recent line is what happened, and all the rest are what it happened within, what method that was called from, what method that was called from, and so on. Wed Jun 13 21:03:58 ADT 2012 ERROR:For input string: ",B6,W5,B2,W7,B,B,W,W" java.lang.NumberFormatException: For input string: ",...

5

Not really, no. There's one scenario: you're calling the draw method so often you don't leave yourself the resources to do anything else. That's not your FPS negatively affecting how the game runs, though. The cause would be a badly written game, engine or framework; the FPS would just be a side-effect. You have a glitch that surfaces on your desktop. Your ...

5

rate * time = distance Establish a rate of movement in whatever units of measure you want (such as pixels per millisecond). Get the time since the last update that has passed (elapsed time). Establish the direction of movement (you're already doing that).

5

There is a mismatch with the objects you write (currentPerson thru year, 14 objects) and those you read back (currentPerson thru generationList, 9 objects). And once you've completed a player, you need to reset i to zero. You can break the loop, when the object is null.

5

A probable cause is that you may not have identity in your modelview matrix when you come to draw the fullscreen quad. This could happen if you're drawing anything else before the quad. I note from your setup code that you correctly switch the matrix mode to GL_MODELVIEW, but then you don't make a glLoadIdentity call after doing so (this is OK as it should ...

5

Your issues does not seems to be "How do I accept only one directional input per update?" but rather "How do I prevent my snake to go backward?" From the many comments and discussion, you seem to be having a frame-rate that is not appropriate for the game you're developing. Traditionally, Snake is a game with a very low frame-rate, the snake moved only 2-3 ...

4

I have elaborated on my comment suggestion, but the answer to your questions are: Yes, there are alternatives to a singleton. I present one shortly. Whether you want to serialize your information to xml, a database, yaml, or whatever is up to you. I do not recommend serializing to your chosen method each time your character drinks a potion or whatever, ...

4

At one place in your code, you create your game container. If you followed the tutorials, that part will look something like this: AppGameContainer container = new AppGameContainer(game); Now you can call setDisplayMode on the container object: container.setDisplayMode(640, 480, true); The first two parameter define the window resolution, the third if ...

4

How to identify the issue: To find out what is slowing down your game (also known as bottleneck), you could use Profiling. http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 It is not classes that slow down frame rate, it is the amount of processing time it takes to complete the instructions in the code (for instance instructions that ...

4

If you're using Slick2D to create the rectangle. Slick2D has a Shape class that can be used to describe such things (rectangles, circles, etc.). I imagine you're using a shape like this for collision because it has methods like intersect()(link) that allow you to detect such things. Shape also has a nice method called transform()(link). It can be used to ...

4

pseudo-code: ClearAllCells(); foreach(entity) int minXCoord = floor(entity->GetPosition().x-entity->GetRadius()) / CollisionGrid.CELL_SIZE; int minYCoord = floor(entity->GetPosition().y-entity->GetRadius()) / CollisionGrid.CELL_SIZE; int maxXCoord = ceil(entity->GetPosition().x+entity->GetRadius()) / CollisionGrid.CELL_SIZE; int ...

4

Delta time is the amount of time since the last update. You're getting 16 or 17 because it has been 16 or 17 milliseconds since the last update. If you want to know how long your game has been running, do something like: long runningTime = 0; //declared outside the update loop //in update loop put: runningTime += deltaTime; if(runningTime > 60) //...

4

I'm not sure how you're not seeing this problem in the debug version. for (Particle o: particleList) { if(o.emitter.completed() == true){ particleList.remove(o); } Attempting to remove an item from a list while iterating through that list will give you a concurrency exception. Instead of particleList.remove(o); add the item to remove list....

4

The reason why it works in Eclipse is because you are in the project root when you do this: particleImage = new Image("res/particles/particle.png", false); For consistency, put your XML file there as well or if you don't want to run it from Eclipse, but from a JAR, integrate an absolute data path in your code (do not hardcode it in your source files).

4

You understood everything wrong. OpenGL was the first to come out. It is a low-level API that controls the GPU and such. You can work with it directly from C/C++. The name comes from Open Graphics Library. LWJGL is a binding of OpenGL to Java, so you can use OpenGL without having to mess with unmanaged C code. The name comes from Light Weight Java Game ...

4

An effect like the one you show is actually pretty simple to code. Create a class Ember that sits at one (x,y) position and randomly spawns 1-pixel particles that move upward (either accelerate upward or move at constant speed as your image). Push each particle into ember.particleList to be used for updates / ticks. Give a 50% chance to spawn new particle ...

3

glBindTexture is the only option for changing textures in OpenGL, but there are a few things you can do to make things easier on yourself. First of all you can wrap it with your own version. That just takes a texture number, compares it to the current texture (which you'll declare as a variable), and if it's changed calls glBindTexture and stores the ...

3

You get the mouse position mouseX = ... mouseY = ... You get the sprite position spriteX = ... spriteY = ... You find the angle angle = Math.atan2(mouseY - spriteY, mouseX - spriteX); Your movement will be: moveX = Math.cos(angle) * speed * time; moveY = Math.sin(angle) * speed * time;

3

Well the question really is how do you compile your game: If you just use javac in the console, make a batch file (in whatever batching language your OS supports, i.e. .bat file for windows, .sh file for Linux, etc) that before executing the compiling command (or after) will read the current build number from a text file, increment it and re-write it; If ...

Only top voted, non community-wiki answers of a minimum length are eligible