Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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: Did you know? Hints and tips on: 2014-07-14 22:31:24
For circle shaped objects:

1  
2  
3  
public boolean isColliding(Actor a) { // CIRCLE shapes.
 return sq(a.x - x) + sq(a.y - y) < sq(a.rad + rad);
}


1  
2  
3  
public static final double sq(double val) {
  return val*val;
}
2  Game Development / Newbie & Debugging Questions / Re: Did you know? Hints and tips on: 2014-07-14 22:23:50
Another good 1... Test for even or odd: (value & 1) == 0.
It's faster than value % 2 == 0!   Wink
3  Game Development / Newbie & Debugging Questions / Re: Did you know? Hints and tips on: 2014-07-14 22:21:39
I believe these versions are more succinct:   Roll Eyes  
P.S.: rx is w/2 & ry is h/2!

1  
2  
3  
public boolean isColliding(Actor a) { // CENTER coords.
 return x >= a.x-rx & x < a.x+rx & y >= a.y-ry & y < a.ry;
}


1  
2  
3  
public boolean isColliding(Actor a) { // CORNER coords.
 return x >= a.x & x < a.x+w & y >= a.y & y < a.y+h
}


4  Game Development / Newbie & Debugging Questions / Re: How to get the size of a primitive/object? on: 2014-07-12 21:37:20
According to the link I've provided, an object instance w/o any instance variables consumes 12 bytes.  
But due to 8 byte alignment, it jumps to 16 bytes. Also, generally we're gonna need to store its reference.
It means more 4 extra bytes. In short 16 bytes for each object at minimum + 4 bytes for each of its reference!   persecutioncomplex

1  
2  
3  
int bytes = 30;  // 12 overhead + 18 instance variables.
int align = (bytes-1)/8*8 + 8;
System.out.println(align); // 32 bytes consumed.
5  Game Development / Newbie & Debugging Questions / Re: How to get the size of a primitive/object? on: 2014-07-12 21:06:12
http://docs.Oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
http://Java-Performance.info/overview-of-memory-saving-techniques-java/
6  Game Development / Newbie & Debugging Questions / Re: For advice on where beginners should go to start making games on: 2014-07-06 19:47:43
Perhaps you should take a look at http://www.GreenFoot.org/doc or even http://Processing.org .   Smiley 
7  Game Development / Newbie & Debugging Questions / Re: [Solved] ConcurrentModificationException - How to avoid it on: 2014-06-25 20:11:11
Don't get me wrong, I love using the "enhanced" for-"each" loop version!
Even though it can be 10% slower for non-array structures than a c-style for loop! Grin
However, we can't use remove() on such loops. Either c-style or Iterator/ListIterator style for such occasions!  Roll Eyes
8  Game Development / Newbie & Debugging Questions / Re: [Solved] ConcurrentModificationException - How to avoid it on: 2014-06-25 07:36:55
I daresay that a backwards loop would still be a bit faster than an Iterator version.
B/c the condition is against a literal 0 rather than a method call like hasNext()!   persecutioncomplex
And the 2nd example using a remove()/set() combo is unbeatable! Averting left-shifting collateral is hard to ignore IMO!   Roll Eyes
On the other hand, if I was dealing w/ a structure like a LinkedList or similar, going w/ an Iterator or a ListIterator is a no-brainer!   Tongue
9  Game Development / Newbie & Debugging Questions / Re: [Solved] ConcurrentModificationException - How to avoid it on: 2014-06-24 23:46:28
I prefer this slightly more compact format using the faster overloaded index-based version of the remove() method:   Roll Eyes

1  
2  
3  
4  
5  
6  
for (int i = popups.size(); i-- != 0;) {
  PopUp p = popups.get(i);

  if (p.isDisposed())  popups.remove(i);
  else                 p.render();
}


And in the case the index order isn't important, this approach averts any left-shifting after remove(): Grin

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
for (int len = popups.size(), i = len; i-- != 0;) {
  PopUp p = popups.get(i);

  if (!p.isDisposed())  p.render();

  else {
    p = popups.remove(--len);
    if (i != len)  popups.set(i, p);
  }
}
10  Game Development / Newbie & Debugging Questions / Re: Teaching Java Game Programming to Children on: 2014-06-15 19:37:41
http://www.GreenFoot.org
https://www.KhanAcademy.org/cs
http://Hello.Processing.org
11  Game Development / Newbie & Debugging Questions / Re: Animated image that only exist for a short period of time. Garbage collection? on: 2014-05-20 01:49:50
Guess it's more specific saying assign null to every variable field or array "slot" which might happen to have a reference for the object we want to be disposed of later on!   Roll Eyes
Alternatively, rather than assign null to a variable, assign another object reference to it. The effect is the same!  Grin 
12  Game Development / Newbie & Debugging Questions / Re: [LibGDX] Removing game objects on: 2014-05-12 02:18:49
Another option would be to have a Boolean in the entity isDead. When it collides with the player, you would set this to true. When you're updating and rendering then you would just ignore the enemies that are dead.

That's my favorite strategy! Although I prefer to save the "dead" object's index value
and then re-use it when requesting a new enemy rather than instantiate another 1!  Cool  

The other option is from this recent thread:
http://www.java-gaming.org/topics/concurrentmodificationexception-when-removing-an-item-from-an-arraylist/32939/msg/309008/view.html

If the order doesn't matter, remove the latest (tail) entry and insert it in the index of the "dead" object, replacing it!   Tongue
This way, we avoid left-shifting the List's entries completely! Shocked

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
static final int BULLETS = 100;
final List<Bullet> bullets = new ArrayList<>(BULLETS);

public void displaySpritesOptimized() {
  stroke(Bullet.COLOUR);
  for (int b = bullets.size(), len = b; b-- != 0;)
    if (bullets.get(b).script()) { // returns true if requesting remove due to outta canvas!
     final Bullet u = bullets.remove(--len);
      if (b != len)  bullets.set(b, u);
      System.out.println("A bullet has strayed too far from view!");
    }
}
13  Game Development / Performance Tuning / Re: Is there a logical reason to stuff 2D array data into one? on: 2014-05-06 16:04:55
Sure you save a couple of array lookups I guess, but I don't think the ry[] would assist much with caching (it's still a pointer).

That's the point, 1 pointer rather than 2! Moreover, values which don't change later in the inner loop are cached right in the outer loop!   Tongue  
14  Game Development / Performance Tuning / Re: Is there a logical reason to stuff 2D array data into one? on: 2014-05-06 15:17:35
Still you're not taking into consideration my tiny optimizations:   Lips Sealed  

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public static void fill_2d_random() {
  for (int y = 0; y != DIM;) {
    int yi = randX[y++], ry[] = rows[yi], x = 0;

    while (x != DIM) {
      int xi = randX[x++];
      ry[xi] = yi^xi;
    }
  }
}
15  Game Development / Performance Tuning / Re: Is there a logical reason to stuff 2D array data into one? on: 2014-05-06 11:18:23
And for the non-random 2D fill too:   Cool  

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public static void fill_2d_YX() {
  for (int y = 0; y != DIM;) {
    int yi = linearY[y++], ry[] = rows[yi], x = 0;

    while (x != DIM) {
      int xi = linearX[x++];
      ry[xi] = yi*DIM + xi;
    }
  }
}
16  Game Development / Performance Tuning / Re: Is there a logical reason to stuff 2D array data into one? on: 2014-05-06 11:06:28
Some cache optimization ideas for the random fill functions:   Roll Eyes  

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
private static final int POW = 10, DIM = 1 << POW;

private static final int[] grid = new int[DIM*DIM];
private static final int[][] rows = new int[DIM][DIM];

private static int[] randX = new int[DIM], randY = new int[DIM],
                     linearX = new int[DIM], linearY = new int[DIM];

public static void fill_1d_random() {
  for (int y = 0; y != DIM;) {
    int yi = randY[y++], x = 0;

    while (x != DIM) {
      int xi = randX[x++];
      grid[yi<<POW | xi] = yi^xi;
    }
  }
}

public static void fill_2d_random() {
  for (int y = 0; y != DIM;) {
    int yi = randX[y++], ry[] = rows[yi], x = 0;

    while (x != DIM) {
      int xi = randX[x++];
      ry[xi] = yi^xi;
    }
  }
}
17  Discussions / General Discussions / Re: [Web Games] What is the best second language? on: 2014-05-01 12:34:22
As said, go w/ Dart or CoffeeScript!   Tongue 
18  Game Development / Newbie & Debugging Questions / Re: ConcurrentModificationException when removing an item from an arraylist on: 2014-04-28 05:38:01
If the order is not important, you can write your own list class that avoids all the overloads. Every time an element is deleted, you can overwrite the deleted item with the last item in the list, then decrease the list size counter. That way you can remove items without speed penalty and you don't need two lists, and all the copies that can be worse than the deletes. I have use this in my Retroships game and it works like a charm.

Loved your tip, Endos. I wish I'd known about that technique before! Although I didn't need to write my own List class at all.
A regular ArrayList is capable to pull that out. Check it out:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
static final int BULLETS = 100;
final List<Bullet> bullets = new ArrayList<>(BULLETS);

public void displaySpritesRegular() {
  stroke(Bullet.COLOUR);
  for (int b = bullets.size(); b-- != 0;)
    if (bullets.get(b).script()) {
      bullets.remove(b);
      System.out.println("A bullet has strayed too far from view!");
    }
}

public void displaySpritesOptimized() {
  stroke(Bullet.COLOUR);
  for (int b = bullets.size(), len = b; b-- != 0;)
    if (bullets.get(b).script()) {
      final Bullet u = bullets.remove(--len);
      if (b != len)  bullets.set(b, u);
      System.out.println("A bullet has strayed too far from view!");
    }
}
19  Discussions / Miscellaneous Topics / Re: new computer purchase advice on: 2014-04-02 07:23:09
@princec

I've also got some Linux distro advise which I've posted @ http://www.java-gaming.org/topics/sorry-ubuntu-has-experienced-an-internal-error/32616/view.html
But it's half digested by the "Chit-chat Monster" now though!   Undecided 

Luck I've saved my post offline and gonna re-post it here!   Roll Eyes 


Go to http://DistroWatch.com to get the picture of all open source distros.   Roll Eyes 

In general, any Ubuntu derived distro is good for 1st lookers.
As mentioned, Mint is overall the better choice. Zorin is good too.

But if you're inclined to more aesthetically gifted distros, I'd go w/:

    Elementary -> http://DistroWatch.com/elementary
    or Deepin   -> http://DistroWatch.com/deepin


For lighter Ubuntu-based distros, go w/:

    Bodhi -> http://DistroWatch.com/bodhi
    LXLE  -> http://DistroWatch.com/lxle


For non-Ubuntu & non-DebIan options, perhaps these 3 below:

    PCLinuxOS -> http://DistroWatch.com/pclinuxos
    Fedora       -> http://DistroWatch.com/fedora
    OpenSUSE -> http://DistroWatch.com/suse


If you feel pretty adventurous, there's PC-BSD -> http://DistroWatch.com/pcbsd
Which it's not even a Gnu/Linux distro, but a FreeBSD 1!   Tongue
20  Game Development / Newbie & Debugging Questions / Re: New to java, where do i start? on: 2014-03-05 00:05:09
BlueJ is a very nice beginner IDE:  http://bluej.org
21  Discussions / Miscellaneous Topics / Re: C++ standard library is really lacking - good or bad? on: 2014-03-03 05:17:59
If some1 wanna stay in the middle of both C++ & Java, D language mixes up both styles: http://dlang.org 
Like C++, it provides pointers & machine code compiling. Like Java, it offers GC, similar class definitions and transparent object variables!
22  Discussions / Miscellaneous Topics / Re: C++ standard library is really lacking - good or bad? on: 2014-02-27 17:05:42
Main difference between what Java/C# calls a reference & C/C++/D calls a pointer is that the latter includes memory addresses for everything that got 1.  
That is, references for variables & functions; not just objects!   Roll Eyes  
23  Discussions / Miscellaneous Topics / Re: C++ standard library is really lacking - good or bad? on: 2014-02-27 04:11:27
There's also the C++, Rust & Go rival, the D language -> http://dlang.org
Like Dart, it also implements classes & GC very Java like!   Grin  
24  Game Development / Newbie & Debugging Questions / Re: Trying to set up a class hierarchy on: 2014-02-18 02:51:29
1  
2  
3  
4  
5  
6  
public class Player extends Entity{
   
   FixtureDef fixtureDef;
   BodyDef bodyDef;
   Texture texture;
   PolygonShape shape;


I wonder if you are re-declaring Entity's fields within Player again?
Also, you said that both WORLD_TO_BOX & BOX_TO_WORLD were supposed to be constants. But they're instance variables after all!  Shocked
25  Game Development / Newbie & Debugging Questions / Re: Trying to set up a class hierarchy on: 2014-02-16 23:18:01
Or rather than null arguments, new 1s!   Roll Eyes  

1  
2  
3  
4  
5  
public class Player extends Entity {
    public Player(SpriteBatch spriteBatch, World world) {
        super (new Texture(), spriteBatch, world, new FixtureDef(), new BodyDef(), new CircleShape());
    }
}
26  Game Development / Newbie & Debugging Questions / Re: Trying to set up a class hierarchy on: 2014-02-16 19:56:08
Made a model mock-up. Instead of a constructor for parent Entity, turned it an init() method, so we can call it later!   Roll Eyes

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
class Entity {
    byte[] sprite, texture, spriteBatch;
    int[]  body, fixtureDef, bodyDef, shape, world;

    Entity init(byte[] texture, byte[] spriteBatch, int[] world,
    int[] fixtureDef, int[] bodyDef, int[] shape) {
        this.texture = texture;
        this.spriteBatch = spriteBatch;
        this.fixtureDef = fixtureDef;
        this.bodyDef = bodyDef;
        this.shape = shape;
        this.world = world;

        body = new int[bodyDef.length];
        sprite = new byte[texture.length];

        return this;
    }
}


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public class Player extends Entity {
    static final int NUM = 10;

    public Player(byte[] spriteBatch, int[] world) {
        texture = new byte[NUM];
        fixtureDef = new int[NUM];
        bodyDef = new int[NUM];
        shape = new int[NUM];

        init(texture, spriteBatch, world, fixtureDef, bodyDef, shape);
    }
}
27  Game Development / Newbie & Debugging Questions / Re: Trying to set up a class hierarchy on: 2014-02-16 17:18:56
Actually, there's an inheritance bug in your Player class! You're re-declaring those 4 fields which are already auto-inherited from Entity!  
Also, all-caps names are for constant fields!   Roll Eyes

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
class Entity {
  public float BOX_TO_WORLD;
  public float WORLD_TO_BOX;

  // Drawing
 public Sprite sprite;
  public Texture texture;
  public SpriteBatch spriteBatch;

  // Box2D
 public Body body;
  public FixtureDef fixtureDef;
  public BodyDef bodyDef;
  public Shape shape;
  public World world;
}

class Player extends Entity {
  /*
  Texture texture;
   FixtureDef fixtureDef;
   BodyDef bodyDef;
   CircleShape shape;
   */


  public Player(SpriteBatch spriteBatch, World world, float WORLD_TO_BOX, float BOX_TO_WORLD) {
    //Planned to define texture, fixtureDef, bodyDef and shape and set their attributes here
   super (defTexture(), spriteBatch, world, defFixtureDef(), defBodyDef(), defShape(), WORLD_TO_BOX, BOX_TO_WORLD);
    // TODO Auto-generated constructor stub
 }

  public Texture defTexture() {
    return texture = new Texture();
  }

  public FixtureDef defFixtureDef() {
    return fixtureDef = new FixtureDef();
  }

  public BodyDef defBodyDef() {
    return bodyDef = new BodyDef();
  }

  public CircleShape defShape() {
    return shape = new CircleShape();
  }
}
28  Game Development / Newbie & Debugging Questions / Re: Trying to set up a class hierarchy on: 2014-02-16 16:30:50
Another option is when the instantiation isn't too long as something like new Class(), we can do it inside the field declaration itself:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public class Player extends Entity {
  Texture texture = new Texture();
  FixtureDef fixtureDef = new FixtureDef();
  BodyDef bodyDef = new BodyDef();
  CircleShape shape = new CircleShape();

  public Player(SpriteBatch spriteBatch, World world, float WORLD_TO_BOX, float BOX_TO_WORLD) {
    //Planned to define texture, fixtureDef, bodyDef and shape and set their attributes here
   super (texture, spriteBatch, world, fixtureDef, bodyDef, shape, WORLD_TO_BOX, BOX_TO_WORLD);
    // TODO Auto-generated constructor stub
 }
}
29  Game Development / Newbie & Debugging Questions / Re: Trying to set up a class hierarchy on: 2014-02-16 16:25:28
HeyUall! I'm a new member! I believe I've got a solution for it and couldn't resist not to register to answer it. HEHEHE!
How about defining methods to initialize those fields, and invoke them within super () itself?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
public class Player extends Entity {
  Texture texture;
  FixtureDef fixtureDef;
  BodyDef bodyDef;
  CircleShape shape;

  public Player(SpriteBatch spriteBatch, World world, float WORLD_TO_BOX, float BOX_TO_WORLD) {
    //Planned to define texture, fixtureDef, bodyDef and shape and set their attributes here
   super (defTexture(), spriteBatch, world, defFixtureDef(), defBodyDef(), defShape(), WORLD_TO_BOX, BOX_TO_WORLD);
    // TODO Auto-generated constructor stub
 }

  public Texture defTexture() {
    return texture = new Texture();
  }

  public FixtureDef defFixtureDef() {
    return fixtureDef = new FixtureDef();
  }

  public BodyDef defBodyDef() {
    return bodyDef = new BodyDef();
  }

  public CircleShape defShape() {
    return shape = new CircleShape();
  }
}
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.

Dwinin (28 views)
2014-09-12 09:08:26

Norakomi (57 views)
2014-09-10 13:57:51

TehJavaDev (74 views)
2014-09-10 06:39:09

Tekkerue (37 views)
2014-09-09 02:24:56

mitcheeb (57 views)
2014-09-08 06:06:29

BurntPizza (45 views)
2014-09-07 01:13:42

Longarmx (28 views)
2014-09-07 01:12:14

Longarmx (34 views)
2014-09-07 01:11:22

Longarmx (34 views)
2014-09-07 01:10:19

mitcheeb (40 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!