Tag Info

Hot answers tagged

17

Demo GameDev Meta: Henshin Main!! :D The code uses a canvas clip region and requestAnimationFrame for maximum quality and efficiency. (It's better live.) I assumed you meant HTML canvas! Even if you didn't, other rendering engines (such as Android's 2D rendering pipeline, which you might have meant) also support hardware-accelerated clip regions. The ...


15

Think of the problem like this: How does a snake move in the original game? The snake moves towards its current direction. The behavior looks like the head appears out of nothing, and the last tail part disappears. You can have a list of snakeparts. What you want to do is remove the last item in the list which represents the last tail part. Then you want ...


12

The get methods do not take so much time, so you're right - this isn't the reason. What's probably happening is that the KeyEvents aren't executed every tick, but are showing the same behaviour as you expect in a browser or anywhere else - when writing something and you move the cursor with the arrow keys, it first moves one space, then stops, and only after ...


9

There are two ways to handle this problem, in my opinion. Use a better coordinate system. You can make the math much easier on yourself if you're clever about how you number the hexes. Amit Patel has the definitive reference on hexagonal grids. You'll want to look for axial coordinates on that page. Borrow code from someone who has already solved it. I ...


8

I would avoid using reflection for something like this, and use a language-agnostic tagged blob format, or something like this (just one possible method for entity serialization): Have an ISaveable interface with a method that produces an Entity given a hunk of save data, and produces a hunk of save data given an Entity. public interface ISaveable { ...


8

The third call to length() in your function uses the updated x value. You really don't want that. Calculate the length once, then divide x and y. double len = length(); if (len > 0) { x /= len; y /= len; }


8

What I would do is make the factions be simple symbols which represent their information regardless of members (name, description etc), and keep some sort of dictionary for each match, which keeps track of which players are in which faction. Dictionary<Faction, List<Player>> This also allows you to do more exotic stuff like players betraying ...


8

Conceptually, you can do that by animating the rotation of the cube (or as in Bloxorz, a cuboid) 90 degrees around one of its edges. You don't need move() at all! Side-on view of one rotation: Here's a seriously good JMonkeyEngine tutorial showing you how to rotate Boxes around pivot Nodes. It explains everything step-by-step. These are the important ...


8

Talking about the "best choice" is always difficult, as long as you did not specify the task that you intend to perform in all detail. But here are several aspects to consider. First of all: Java is not C. The memory management is completely different, so one has to be very careful when trying to apply insights from one programming environment to another. ...


7

It turns out my initial suspicions were right. The SpriteBatch draw method takes floats for the X and Y, so I decided to feed it my positions as is, kept as floats. WRONG. It seems that the SpriteBatch class can't round properly or something because when I cast all of the values to integers and then gave it that, everything turned back to normal and is ...


6

There are many hex coordinate systems. The “offset” approaches are nice for storing a rectangular map but the hex algorithms tend to be trickier. In my hex grid guide (which I believe you've already found), your coordinate system is called “even-r”, except you're labeling them r,q instead of q,r. You can convert pixel locations to hex coordinates with these ...


6

Here is the pseudo-code from wikipedia for A* with a consistent-heuristic: 1. while openset is not empty 2. current := the node in openset having the lowest f_score[] value 3. if current = goal 4. return reconstruct_path(came_from, goal) 5. 6. remove current from openset 7. add current to closedset 8. for each neighbor in ...


6

Several suggestions come to mind. I feel you may have gone a little inheritance happy. While inheritance is a great tool, sometimes all you need is a little more customization of a single object. First, a component system seems to jump out as a good candidate. Then you'd just have a Spell class (or perhaps something even more broad, but that's not ...


6

As mentioned in PeterT's comment, you don't need to load all of your levels at once; instead you just load the current level and when the player transitions from that to a new one, you unload the current and load the new. That gets you down to about 100mb (the raw per-level cost), but we can go lower still. Consider a cube; right now you're defining each ...


6

Get rid of the Sleep call. Sleep is fine for reducing CPU usage, but it is not fine for controlling framerate, and these two are not the same thing. Sleep can have poor precision, in the order of ~16 milliseconds. Sleep guarantees that the thread will resume at some arbitrary time after the Sleep interval has elapsed, not at the exact Sleep interval. ...


6

The first method relies directly on the key presses. It's a standard behavior ( probably coming from the operating system ) for there to be a delay before it starts repeating itself. That's why it moves, then stops and then keeps moving afterwards. The second method sets a value for the velocity which is then applied to the x position. It's not exactly ...


6

The formula returns a scalar (the height of the water surface at coordinates x,y), not a vector. It is hard to tell what the authors had in mind, because the paper is very confused, but my guess is that it should have looked like this: Y(x,y,t) = A * cos(w * f(x,y) + wt * t + FI) Where f is a function that controls the shape of the wave. This function ...


6

Well, technically speaking you can generate textures using any language. Even if you don't have any output on screen, as far as your language can represent integer/float (could get away with integers) and arrays, you are good to go. The problem though is that not every texture could be generated procedurally. You usually need a formula as a stating point to ...


6

It's definitely possible, you would just need to create a thin layer wrapping the Steam SDK (or part of it) to java via the Java Native Interface I'm not aware of any efforts to have an opensource library for this.


6

Sphere-Sphere Intersection Let's start with the more obvious one - sphere-sphere. It's almost identical to the circle-circle case in 2D. We can project down on any plane containing the line between the sphere's centers to get an identical 2D picture: Here the first sphere has center c_1 and radius r_1, the second c_2 and r_2, and their intersection has ...


6

The simple solution would be to just discard and recalculate the power distribution in the whole grid whenever you make a change. Considering that your grid is only 18x18, it shouldn't be too computationally intensive to do so. Inverters might be problematic, though. What do you want to happen when the player connects the output of an inverter to its input? ...


5

I was able to find a solution, in order to convert the mouse coords to the coords relative to the tile map, i used: @Override public boolean mouseMoved(int screenX, int screenY) { //screenX, screenY - Mouse Coords Vector2 centerPosition = new Vector2(player.getX(), player.getY()); Vector3 worldCoordinates = new Vector3(screenX, y, ...


5

Yes it is. Many games have a slow logic loop (~10/s) and a fast render loop (~60/s). Turns out most games don't need to update that often. Also by decoupling logic and rendering, you won't see a frame rate drop when the game hits a particularly difficult logic tick. I could go over it, but just read this article: ...


5

I do know. // add speed x = dx * timeSinceLastFrame * 300; y = dy * timeSinceLastFrame * 300; // Move the player playerRec.x = (int) x; playerRec.y = (int) y Is effectively the same as saying // Move the player playerRec.x = (int) (dx * timeSinceLastFrame * 300); playerRec.y = (int) (dy * timeSinceLastFrame * 300); ...


5

This simple algorithm assumes you're working with a convex polygon (in the case of physics engines you definitely should be): Loop over the polygon with two indices, one called next and one called last. This is also known as a format called "Triangle Fan". Here's a demo image: You set up these two indices and loop something like this: TriVertexList ...


5

Do I create a country class that contains a bunch of towns? Sure. Do the towns contain a lot building class, most contain classes of people? Sure. Do I make a path finding class that the player can access to get around? Sure. Everything you have suggested above seems reasonable. It may not be the best way for you in the long run, but that's ...


5

LWJGL was my starting point for OpenGL (I since moved on to writing native C++ code), so I get where you're coming from. But what you should be looking for is good OpenGL tutorials, not LWJGL tutorials in specific. The LWJGL wiki should have everything you need as far as the library is concerned. The tutorials I'm going to recommend? Learning Modern 3D ...


5

Checking the surrounding tiles is pretty simple. You can do it pretty easily in a nested for loop: for(int i = x-1; i < x+1; i++) { for(int j = y-1; j < y+1; j++) { if(i != x && j != y) { //ignore the center tile //process tile (i,j) } } } This will loop through each tile surrounding tile (x, y). You'll ...


5

The way I do it, not in java but in some sort of c#/c++ hybrid, is I have an engine class (similar to your main class), which holds a Screen object. The screen object is an abstract class with two main functions, update and draw. The engine has one screen which it just calls the Update and the Draw functions. While I have no experience with it, I imagine ...


5

You have incorrectly implemented the formula as a function. The function is missing + 1 after the call to Math.sin(), which moves the wave to the range [0, 2]. Regarding your second problem, I don't see anything wrong. In fact the screenshot looks exactly like it should and seems to match the plotted curve. Try with k=10 and you should see the difference ...



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