Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: Best Way to Code Random Percentage of Something on: 2013-04-09 11:30:05
You would use a java.util.Random object. Define one somewhere, and use it like this (assuming your HashMap is of item IDs to percentages, if not you might need to change it a bit):

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
boolean dropped = false;
int highest = -1;
int highAmt = -1;
// Lets loop through all the items, because you said you didn't want it hardcoded
for (Entry<Integer, Integer> entry : drops.entrySet()) { // Where drops is the HashMap you spoke of. HashMaps are extremely fast, don't worry about that
   if (entry.getValue() > highAmt) {
        highest = entry.getKey();
    }
    // Note <, not <=, because nextInt(100) will generate a number from 0-99, not 1-100.
   if (random.nextInt(100) < entry.getValue()) { // Will happen every (entry.getValue() / 100) times
       world.dropItemById(x, y, z, entry.getKey()); // Or however you do this
       dropped = true; // Set this to true for usage a bit later
       break; // Remove this if you want the chance of multiple drops
   }
}
if (!dropped) {
    world.dropItemById(x, y, z, highest); // Slightly crude way of ensuring something is dropped. If we don't drop something, drop whatever has the highest percentage. If you want the possibility of no drop remove this
}
2  Game Development / Performance Tuning / Re: Speeding up Minecraft? on: 2013-03-30 19:06:54
Rewrite most of Minecraft to use rendering that isn't immediate mode and multithread some of it Tongue Realistically you could probably add a bit of multithreading, and if you want to spend a lot of time on it you could convert it to use DisplayLists.
3  Game Development / Game Mechanics / Re: Multiple threads on: 2013-03-29 23:19:51
It depends on how well you do it. It's can work to have a rendering thread, a logic thread, a resource loading thread, a world generation thread (if applicable), and even an input thread if you do it right, as well as threads for connections, etc. It all depends on how your game works and how well you know how to implement multithreading though.
4  Games Center / Cube World Projects / Re: Sparky's little Cube World Project on: 2013-03-29 21:55:39
Ok, I forgot about the jar if you like to try it. It should be ready for windows and linux:
here

Please report me any errors. Smiley

The download is a 404
5  Game Development / Shared Code / Re: [LWJGL] Easily render text. on: 2013-03-29 16:24:56
This looks exactly like Minecraft's renderString method looked in one of the early beta versions (before they optimised it quite a bit).
6  Game Development / Shared Code / Re: CyclicMap - A Map implementation perfect for games and faster than HashMap on: 2013-03-29 16:14:41
Well maybe you can talk to him about it. It's still twice the speed with his optimisation, and I'm fairly sure currentTimeMillis doesn't go 80ms off (at least most of the time).
7  Game Development / Shared Code / Re: CyclicMap - A Map implementation perfect for games and faster than HashMap on: 2013-03-29 15:53:46
If you are looking at optimising HashMaps, you could have a look at raphfrk's findings at http://forums.spout.org/threads/hashmap-micro-optimisations.6648/
8  Games Center / Cube World Projects / Re: LWJGL BlockWorld on: 2013-03-29 14:50:06
Is it possible that we could get the source for the new version of your game? I've made my own block engine but it's not great on efficiency / performance, and I'd love to learn from someone better's code to see where it can be optimised and what methods I should be using.
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

ctomni231 (34 views)
2014-07-18 06:55:21

Zero Volt (30 views)
2014-07-17 23:47:54

danieldean (25 views)
2014-07-17 23:41:23

MustardPeter (27 views)
2014-07-16 23:30:00

Cero (42 views)
2014-07-16 00:42:17

Riven (44 views)
2014-07-14 18:02:53

OpenGLShaders (32 views)
2014-07-14 16:23:47

Riven (34 views)
2014-07-14 11:51:35

quew8 (30 views)
2014-07-13 13:57:52

SHC (66 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!