Tag Info

Hot answers tagged

65

You can use int, and consider everything in cents. $1.20 is just 120 cents. At display, you put the decimal in where it belongs. Interest calculations would just be either truncated or rounded up. So newAmt = round( 120 cents * 1.04 ) = round( 124.8 ) = 125 cents This way you don't have messy decimals always sticking around. You could get rich by ...


52

Okay, I'll jump in. My advice: it's a game. Take it easy and use double. Here is my rationale: float does have a precision issue that appears when adding units to millions, so though it might be benign, I would avoid that type. double only starts getting problems around the quintillons (a billion billions). Since you are going to have interest rates, you ...


39

C# and Java are not "basically the same". A lot of basics are just similar, and it's not a coincidence: C# was influenced by Java and they were both influenced by C++. Whilst this means you'd already recognise a lot of stuff, it doesn't mean you suddenly know C#. Do you know much about its standard library? A lot of the collection classes are named ...


19

Java runs in a virtual machine, while C++ is run directly on the hardware. What this means is that you have more control over where your memory goes and what is done with it in C++. Java is a garbage collected language. You do not have direct control over your memory. You can allocate new chunks of memory, but you do not have (fine) control over when it ...


19

Floating point types in Java (float, double) are not good representation for currencies because of one main reason - there is a machine error in rounding. Even if a simple calculation returns a whole number - like 12.0/2 (6.0), the floating point might wrongly round it (due tho the specific representation of these types in memory) as 6.0000000000001 or ...


18

Put it wherever you can to make it work. Anything else is design paralysis and just going to slow down your progress. When you start seeing patterns emerge, refactor your code. Lots of people will give you advice about the One True Way to do something, but without a breadth of experience to draw from, you'll just be parroting ideas without a true ...


16

For small scale game and where process speed, memory is important issue (due to precision or work with math co-processor can make painfully slow), there double is enough. But for large scale games (for example, social games) and where process speed, memory is not limited, there BigDecimal is better. Because here, int or long for monetary calculations. ...


15

I'm actually one of the Don't Starve devs (Kevin on our forums). I don't usually handle the rendering stuff, but I can tell you that the game is in 3D. The ground is just a regular 2D tile map with special transition pieces to make corners look better. There's no special Deathspank-style rounding going on, although we have talked about doing that in the ...


14

Start with a full list of rooms. Pick a starting room. Navigate from that room to all connected rooms. For each room you visit, remove it from the list of rooms and add it to a list A. Once you've visited all your connections, any rooms remaining on the list are not connected to the starting room or any of the rooms on list A. You can then continue by ...


12

Delete the Thread.sleep() call (assuming you're on a desktop machine and have power to spare!). In general you never sleep in your game loop (except on Android, where there appears to be no other choice). The bad thing about Thread.sleep is it is unpredictable and may cause your game to give up exec time for longer than 16ms, which is the maximum time a ...


12

Pools are used when the number of objects will fluctuate dramatically and are used to reduce the amount of memory allocation and garbage collecting. Using a pool the standard new Object() which allocates new memory is replaced with pulling an already allocated object from the pool. This is much faster even if you go though and reset every variable in the ...


11

I noticed that English isn't your first language. That's okay, it's my second language too. ;) What I would advise is to keep everything about your game in English. It's easier to port English to Danish than in reverse. Somebody else can extend your code if she knows English. You can outsource translations and resource creation to somebody else (who may ...


11

You want to store your currency in long and calculate your currency in double, at least as a backup. You want all transactions to take place as long. The reason you want to store your currency in long is that you don't want to lose any currency. Let's suppose you use a double, and you have no money. Someone gives you three dimes, and then takes them back. ...


11

What would the W3C do? The internet has had this problem. The World Wide Web Consortium noticed. It has a recommended standard solution since 1999: Scalable Vector Graphics (SVG). It's an XML-based file format specifically designed for storing 2D shapes. "Scalable-what?" Scalable Vector Graphics! Scalable: It's meant to scale smoothly to any size. ...


10

Databases have a quite different use case than file formats like XML. File-Formats like XML: Are saved once and loaded once per application start-up. Since they are loaded once the access time after the loading is extremely fast. Used for serialization and deserialization as well as configuration files. Databases: Are for the most part constantly in ...


10

It's basic physics: heavier objects don't fall faster! A feather has a bigger area than a pebble; hence it gets slowed down by air resistance a lot more. Introduce a drag force that slows down objects the faster they fall, in the opposite direction of the velocity. The drag force will cancel out gravity once terminal velocity has been reached. drag_force = ...


10

Noise along any of the axes will be consistent noise. Just imagine you're flying through a cloud of noise sampling a single line of data. So yes, return noise(x, 0, 0); is exactly like traveling along a single line of noise inside a cloud of noise. You'll be traveling along the line that represents the x axis. You could even do return noise(x, x, x); and ...


10

Yes, if you examine Minecraft under the hood you can see that it's just a separate file that will launch the JAR file afterwards. However, you're probably more interested in implementing an update solution for your game yourself. If that's the case, check out Sparkle.


9

Form a triangle using the two sides you already have (one side is from 'c' to 'o', the other from 'o' to 'a'), and the third side goes from 'a' to 'c'. You don't know where 'a' is just yet, just imagine there is a point there for now. You'll need trigonometry to calculate the angle of the angle that is opposite to the side 'd'. You have the length of the ...


9

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(); } ...


9

The game in game theory and game development are not talking about the same kind of games. Game theory is mainly used in economics and political science. Sounds like the book you were reading was about business strategy? I would say it's more accurate to say that game theory can be applied to computer science and the development of logical theories related ...


9

Your collection of rooms is essentially a graph, and your problem boils down to finding connected components ("islands") in that graph. A simple way to find connected components is to do BFS (breadth-first search) from each vertex. Doing BFS from a vertex A will get you all the vertices in the connected component which vertex A belongs to. So, basically, ...


9

The java List interface provides two methods for removing objects, one taking an instance of the object and one taking an index. You can see all the methods on the list interface here Regardless of what list implementation you use all lists will have those methods. The difference is in the speed of certain operations. The JavaDocs for list implementations ...


9

Fascinating question. I think one of the first issues you have to address is whether you want the patrolling behavior to be "optimum" patrolling or "lifelike" patrolling. I'm just making up these words, but what I mean is: Optimum: The agents move about in a manner that perfectly distributes their coverage area for the system as a whole. Lifelike: The ...


8

You don't need a physics engine for this because the calculations required are extremely simple! All you have to do is to apply some gravity to your player's vertical velocity, and he will automatically follow an arc when jumping. For a detailed explanation of how it works, including a demo that runs in the browser, read the following answer: ...


8

(CAVEAT: I'm using two approximations here: the first takes d as an arc length, and the second takes it as an orthogonal length. Both of these approximations should be good for relatively small values of d, but they don't fulfill the precise question as clarified in comments.) The math on this, fortunately, is relatively straightforward. First of all, we ...


8

I think you're after Application querying switch(Gdx.app.getApplicationType()) { case ApplicationType.Android: // android specific code case ApplicationType.Desktop: // desktop specific code case ApplicationType.WebGl: /// HTML5 specific code }


8

I have seen your game samples. In this specific case I would use a grid. Divide the game screen into squares. Create a 2D-Array representing the game screen squares and containing reference to the game objects inside each square (2d array of object lists). Check for collisions between all the objects that are inside the same squares (that can collide with ...


8

The main point is that the end user should not be required to install any Java JRE, nor should the installer contain a JRE and install it for the user You can use Java source/bytecode to machine code compilers. There are Excelsior JET for Windows and Linux (requires license) and GNU Compiler for Java which is old. If it's ok to contain Java with ...


7

Since you give absolutely no details as to why you want to do this or how it would be used. I'll just give you the most straightforward simple answer I can come up with. Start Java as a process: String pathToJava = @"c:\program files\java\bin\java.exe";//replace with automated method to find java on machine String jarFile = "myjarfile.jar"; String ...



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