Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (686) Games in Android Showcase (198) games submitted by our members Games in WIP (758) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
 Show Posts Pages: [1] 2 3 ... 5
1  Game Development / Newbie & Debugging Questions / Re: Getting the chunk of a Hex on: 2016-08-06 10:03:12
I also did some testing with chunks farther away, like if hex_ix = -12 and hex_iy =10 it will return -3,3 after

Thank you for testing and helping me out, I ran a quick test to see all the places that aren't correct, and to check if chunk_iy is correct indeed, it turns out that after testing the chunk_iy isn't correct (the yellow lines)

Cleaned up the image a bit, colour coded it, and added a circle. I feel like the solution probably involves trigonometry, but I haven't figured it out yet. Will keep trying.

This image is really handy, seeing both axes of the hexs and chunks. It also is showing why the code is failing. Since the code is the same as finding a hex by mouseclick (only slightly changed to match flat-hexagons instead of pointy-hexagons) so for finding chunks we are using the blue grid instead of the red grid so that's wrong.

This also gives why the chunk_x isn't accounting for hex_iy since the x-as of the blue grid is ''straight''.
And you are very right on this one, it has to do with trigonometry! That's also why there is a Math.sqrt(3)/3 in the code.

chunk
hex

Are chunks the colored groupings of hexes?
The single pointy-hexagonals are a single hex and correct, the chunk is the group of colored hexes.
I've logged the input data and output data.
Everything after Adding Hexes to Chunk[chunk_ix , chunk_iy] belongs in that chunk so the hexes that are logged after that line need to have a minimal @-value of [chunk_ix - 0.5f, chunk_iy-0.5f] and a maximal @-value of [chunk_ix + 0.5f, chunk_iy + 0.5f] The yellow lines show output data that isn't right

I will be adjusting the code to match the other grid.

Update:
I have been trying to create the grid, but before giving the codes it is needed you know what all the vars actually are.

The values of these vars are based of their pixels/texel value.
And the values of the chunk variables are iteration values based on the number of hexagons

Because the vars are final the value of the var is given after the name (= ...)

So I've been trying to translate the hex_ix and hex_iy from the hexagonal grid to a chunk_ix and chunk_iy value from the chunk grid. The following is what I've come up with, currently it's more wrong than the previous code, but I believe this code is more correcter: Log-files
 1  2  3  4  5  6  7  8  9  10  11  12  13 `      float size_x = HEX_X_DX * (CHUNK_LENGTH-1);      float size_y = HEX_Y_DY * CHUNK_LENGTH;      float x_dx = HEX_X_DX;      float x_dy = HEX_Y_DX/CHUNK_LENGTH;      float y_dx = HEX_Y_DY * CHUNK_SIZE /(CHUNK_LENGTH-1);      float y_dy = HEX_Y_DY;      float chunk_ix = ((float)hex_ix * x_dx + (float)hex_iy * x_dy) / size_x;      float chunk_iy = ((float)hex_ix * y_dx + (float)hex_iy * y_dy) / size_y;      System.out.println("Hex [" + hex_ix + ", " + hex_iy + "] @ [" + Math.round(chunk_ix) + ", " + Math.round(chunk_iy) + "] : " + chunk_ix + ", " + chunk_iy + " : " + size_x + ", " + size_y + " : " + x_dx + ", " + x_dy + " : " + y_dx + ", " + y_dy);`

Thanks for helping,
-Rose
 2 Discussions / Miscellaneous Topics / Re: What I did today on: 2016-08-05 23:10:33 More what I did yesterday..I love the last one, looks like actual art
 3 Game Development / Newbie & Debugging Questions / Re: Getting the chunk of a Hex on: 2016-08-05 22:36:23 Quote from: Hydroque on 2016-08-05 21:34:47Could you post with more information on what you are actually trying to do with the chunks. I feel like there isn't enough description to know what you want. Make sure to describe your inputs and your expected output and what those types are.First of all, thanks for the help, I will be try a little bit clearer this timeThe idea basically is that I want to create an graph but instead of having horizontal and vertical axis, I want them to be slightly rotated to create a graph like the following graph:Image2:If you place that graph over the current hexagonal chunks (image1), you will be able to see what I am trying to do:Image3:And if you take a look at image2, you can see that Hex A is inside the boundary(DEFG) of Chunk (0, 0) So basically what I am trying to do is creating a grid without "straight" axes. So I can locate the place of an hex inside the grid and simply use the Math.round() function to get the chunk of the hex. But the problem I am facing is that I don't know how to create this type of grid. I've been searching, but because I don't know the proper name of it, the results are limited.(I hope it is clearer now)Thanks for reading, -Rose
4  Game Development / Newbie & Debugging Questions / Re: Getting the chunk of a Hex on: 2016-08-05 20:18:14
Update:
Tried to implement the same tactic as pixel_to_hex. Instead the size of the hex I am using the (Vars.Chunk_size + 1)

 1  2  3 `                float size = (Vars.CHUNK_SIZE + 1);                int chunk_x = (int)Math.round((float)hex_ix * 2/3 / size);                int chunk_y = (int)Math.round((-(float)hex_ix / 3 + Math.sqrt(3)/3 * (float)hex_iy) / size);`

Only if x = 0 it gets the right coördinate (I believe, haven't fully tested)
5  Game Development / Newbie & Debugging Questions / Getting the chunk of a Hex on: 2016-08-05 16:38:22
Well, hello there!

This project is my first time implementing hexagons and actually using them.
I've been reading some information on this subject.

Image1: Hexagonal Chunks

coördinates of the chunk(chunk_ix, chunk_iy)
coördinates of the hex(hex_ix, hex_iy)

The problem I am having, is that I don't know how to get the coördinates of the chunk of hex A/B/C

The size of the chunks is variable, the images is using the following vars:
 1  2  3 `   /* CHUNK INFORMATION */   public static final int CHUNK_SIZE = 2;   public static final int CHUNK_LENGTH = CHUNK_SIZE*2 + 1;`

Every time a new chunk is created the hexagonal in the center gets the following coördinates:

 1  2  3  4  5  6  7 `int center_hex_x   = /*chunk_x alternation*/ chunk_ix * (Vars.CHUNK_SIZE + 1)   - /*chunk_y alternation*/ chunk_iy * Vars.CHUNK_SIZE;int center_hex_y   = /*chunk_x alternation*/  chunk_ix * Vars.CHUNK_SIZE   + /*chunk_y alternation*/chunk_iy * Vars.CHUNK_LENGTH;`

I can get the coördinates of the hexes quite easily, so the question is how to get the chunk that corresponds with that hex?

It's probably possible with transforming the coördinates of the hex and checking which chunk is the closest to it, but I've actually no clue on how to do that.

Minor update:
If you know any articles et cetera, post them if possible. I prefer getting information, instead of codes!

-Rose
6  Game Development / Newbie & Debugging Questions / LibGDX Box2D Basic Shader failing (Box2DDebugRenderer) on: 2016-05-26 15:40:24
Previously my box2ddebugrenderer always worked, but at this moment, it seems to be failing on all my programs. I don't know why this is, I've searched, without success. There are little to no topics about this problem and those that stated this problem, got no reactions. So maybe one of you ever experienced this problem, and know the proper solution.

Things I've tried:
• Searched the solution online
• Testing the debugrenderer on multiple applications

Because I am not using any shaders, but the basic shaderprogram there is little information to provide you with.
But here we go:

[ErrorLog]
[/list]
 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15 `Exception in thread "LWJGL Application" java.lang.IllegalArgumentException: no uniform with name 'u_projModelView' in shader   at com.badlogic.gdx.graphics.glutils.ShaderProgram.fetchUniformLocation(ShaderProgram.java:287)   at com.badlogic.gdx.graphics.glutils.ShaderProgram.fetchUniformLocation(ShaderProgram.java:277)   at com.badlogic.gdx.graphics.glutils.ShaderProgram.setUniformMatrix(ShaderProgram.java:507)   at com.badlogic.gdx.graphics.glutils.ShaderProgram.setUniformMatrix(ShaderProgram.java:498)   at com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer20.flush(ImmediateModeRenderer20.java:147)   at com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer20.end(ImmediateModeRenderer20.java:160)   at com.badlogic.gdx.graphics.glutils.ShapeRenderer.end(ShapeRenderer.java:1104)   at com.badlogic.gdx.physics.box2d.Box2DDebugRenderer.renderBodies(Box2DDebugRenderer.java:109)   at com.badlogic.gdx.physics.box2d.Box2DDebugRenderer.render(Box2DDebugRenderer.java:79)   at net.loco_coco.terraingeneration.states.GS_Game.render(GS_Game.java:75)   at net.loco_coco.terraingeneration.handlers.GameStateManager.render(GameStateManager.java:33)   at net.loco_coco.terraingeneration.main.Main.render(Main.java:50)   at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:215)   at com.badlogic.gdx.backends.lwjgl.LwjglApplication\$1.run(LwjglApplication.java:120)`

Creating the debugrenderer
 1  2  3  4  5  6  7  8  9 `public GS_Game(GameStateManager gsm) {      super(gsm);      b2dCam = new OrthographicCamera();      b2dCam.setToOrtho(false, Main.V_WIDTH / Vars.PPM, Main.V_HEIGHT / Vars.PPM);      debugRenderer = new Box2DDebugRenderer();      gravity = new Vector2(0, -9.81f);      world = new World(gravity, true);      createGround();   }`

Rendering the debugrenderer
 1  2  3  4  5  6  7 `public void render(){      //clear screen      Gdx.gl.glClearColor(0, 0, 0, 1);      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);            debugRenderer.render(world, b2dCam.combined);}`

Creating the Body
 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17 `   private void createGround(){      BodyDef bDef = new BodyDef();      bDef.type = BodyType.StaticBody;      bDef.position.set(0, 0);            CircleShape shape = new CircleShape();      shape.setRadius(3f);      shape.setPosition(new Vector2(0, 0));      FixtureDef fDef = new FixtureDef();      fDef.friction = 0.5f;      fDef.restitution = 0.05f;      fDef.shape = shape;            world.createBody(bDef).createFixture(fDef);      shape.dispose();   }`

I've tried using another shaderprogram, but because I am not using any spritebatch so far, I cannot use the shaderprogram. I still think the problem is inside the libGDX Box2D.
If someone can post a working version of the Box2DDebugRender/ShaderProgram the problem will probably be fixed.

Thank you very much for reading.
-Rose
 7 Game Development / Newbie & Debugging Questions / Re: Bit operating + Handling Weapons and/or Spells on: 2015-10-01 19:45:33 Quote from: BurntPizza on 2015-10-01 19:37:02Also, are you sure you'll only ever need 16 traits? (bits) It'll be painful if you eventually find out you need more.EDIT: the sort of cleaner way of doing this is with EnumSets, btwWell, currently I am using 14 types and I can switch to integers to use 32bit...Quote from: KevinWorkman on 2015-10-01 19:33:24I would argue that what you're doing here is basically like having an array of booleans. Instead of that, why not use an ArrayList that holds an enum type?Like I said, which approach you take really depends on you. If you're really sticking with this bit approach, then check out bit shifting and the Integer class for some useful functions.As you both suggest that I should use Enum types, I will gather some information about this subject. Thanks for helping me out. Honestly I also like to argue a bit with these kinds of things, it provides some usefull information. Well thanks again for the effort-RoseSlayer
 8 Game Development / Newbie & Debugging Questions / Re: Handling a large variety of spells and/or weapons (shorts|bit) on: 2015-10-01 19:30:13 Quote from: KevinWorkman on 2015-10-01 19:22:56Why in Gosling's name wouldn't you just use interfaces instead?Or better yet, a "composition over inheritance" approach like we've been talking about?I am using composition over inheritance, but the type is declared in the very base of all things. The (short)type is only used for holdingcells that only can hold that type (of a combination like that (i.e. CellB)). I think this is the most clean and best way to approach this situation. I am not using instanceof etcetera, also the possibilities of doing it this way is endless. Why do I need to create new lines of codes if I only need to test if a bit of the short is 0 or 1?Thanks for responding as fast as you just did.-RoseSlayer
9  Game Development / Newbie & Debugging Questions / Re: solved Handling a large variety of spells and/or weapons on: 2015-10-01 19:20:31
Thank you all for your support.

The way of creating a large variety of spells and weapons is working now.
All the items do have the following in them:
 1 `short type`

the types that are currently possible are the following:
 1  2  3  4  5  6  7  8  9  10  11  12  13  14 `   public static final short allType = -1;   public static final short equip = 2;   public static final short consumable = 4;   public static final short material = 8;   public static final short spell = 16;   public static final short weapon = 32;   public static final short shield = 64;   public static final short backpack = 128;   public static final short ammo = 256;   public static final short face = 512;   public static final short helmet = 1024;   public static final short body = 2048;   public static final short boots = 4096;   public static final short gloves = 8192;`

The reason why I've done this is to make it quite easy to create an item that is made out of multiple types.
for example I have a sword:
 1 `Sword sword(short(equip & sword))`

If you write it in shorts:
 1  2  3  4 `equip = 0000000000000010weapon = 0000000000100000/* so sword has those types together */sword = 0000000000100010`

so sword will have the type:

But with only this knowledge I am stuck:

I have a cell, cellA that only accepts equip, and cellB that accepts equip, weapon and shield but how to test if the bit on that place is 1 or 0?
I don't know if it is possible to use these kind of bit operators anyways, so if you know anything about this subject, provide me with some of your delicious information.

-RoseSlayer
 10 Game Development / Newbie & Debugging Questions / Re: Three Dimensional Array 'dupe' glitch on: 2015-09-20 17:32:40 Quote from: BurntPizza on 2015-09-20 17:27:05Hint: What do you think Array.fill() does with it's arguments?Quote from: Riven on 2015-09-20 17:27:21You are creating ONE instance of InventoryCell(null), and put that in every slot of the array.As the array only holds references, you'll see that changing the data in the InventoryCell instance, will be visible from every slot in the array.I feel dumb...Thanks anyways  -RoseSlayer
11  Game Development / Newbie & Debugging Questions / Three Dimensional Array 'dupe' glitch on: 2015-09-20 17:22:36
Greetings again,

I've spent some hours trying to solve it, rechecking all the classes etc, but I can't seem to find where the problem is. So I believe after some Trail-And-Error that it was the Three DImension Array itself. The problem is that an item that is added to the Array i.e.
 1 `inventorySpells[0][0][0]`

gets duped to
 1 `inventorySpells[0][0][n]`

Initialize:
 1  2  3  4  5  6 `      inventorySpells = new InventoryCell[INV_WIDTH][INV_HEIGHT][2];      for (InventoryCell[][] square: inventorySpells) {         for (InventoryCell[] line : square) {            Arrays.fill(line, new InventoryCell(null));         }      }`

 1 `               inventorySpells[x][y][0].setItem(spell);`

(note): This is the only function that adds something to the InventoryCell[][][]

With some good old System.out.print, I've found that
 1 `inventorySpells[0][0][0] = inventorySpells[0][0][n∞]//Well it isn't infinity because it can get a max value of 1, but you get the clue`

So the problem is that the Third Dimension doesn't matter at all, because changing a z-value, will result in the same x-value and y-value.
I really the three dimension array, it's much cleaner and uses less lines than using multiple Two Dimensional Arrays...

Anyone know what this problem is all about? If there is something not clear, just ask me.
-RoseSlayer
12  Game Development / Newbie & Debugging Questions / Re: Handling a large variety of spells and/or weapons on: 2015-09-17 18:07:15
Similarly, you'd create a new instance of the Spell class whenever a player earned that spell. You wouldn't need to share instances between players, and you wouldn't need one master class responsible for creating spells.

I know this sounds terrible, but the problem is I don't know how to create a new instance of a spell without hardcoding the atributes into the enemy/player class...

 1 `Spell fireball = new Spell(1, false);`

Because of this I have always used a static class that contains the weapons/spells. If I faced an constructor that doesn't require any attributes I am still confused with making a new instance of a spell because I will hardcode it like:

 1 `Spell fireball = new SpellFireBall(); `

/*Edit*/
Nvm, just need to implement cloneable and clone it with the list you've already provided, am I right?
 1  2  3  4 `public static Spell getSpell(String name) {    if (!spells.containsKey(name)) throw new IllegalArgumentException(...);    return spells.get(name).copy();}`

-RoseSlayer
 13 Game Development / Newbie & Debugging Questions / Re: Handling a large variety of spells and/or weapons on: 2015-09-17 17:21:29 Quote from: KevinWorkman on 2015-09-16 20:39:38I think it really depends on how your characters obtain these weapons and spells in the first place. Are they located in the game world (on the map or in a chest or something)? Are they obtained automatically? Are they there from the beginning?The weapons are obtained by the following: Crafting, trading/buying, dropsThe spells are obtained by the following: Monsters have a very small chance to give the player a spell that fits the monster unique ability (atleast if the player has the requirments) if killed.Quote from: princec on 2015-09-16 21:17:05With Java 8 the landscape of inheritance vs composition ideological conflicts has subtly changed with the advent of default methods in interfaces.Well this doesn't help me much, unfortunately...Quote from: Roquen on 2015-09-16 23:21:43Yeap. And functional interfaces.  Take a bioware or elder scrolls like game, using an archtype system all items, monsters, effects, etc. could be defined using only inheritance in around a dozen classes.  (give or take given some design decisions).  Player's designing their own doesn't add any problems here either.  Who is creating the data does matter for the base system...it's all just data.  This excludes all "game mechanic" code.  But in java8 that can be however many static utility (or enum classes) one needs.  Each of these is more or less independent of everyone else.  Java 8 drastically reduces the number of classes required due to functional interfaces. This is exactly what I am trying to achieve, do you know how this work and give some small information about it? As always, thanks for the posts and time spended.-RoseSlayer
14  Game Development / Newbie & Debugging Questions / Re: Handling a large variety of spells and/or weapons on: 2015-09-16 19:06:34
Just chiming in here:
There is no such thing as 'the best', since different games/applications need different functionality.
You can't make a 'fit all' solution, its simply not possible.
There is no the best, I know but I am trying to gain alot of information about this subject, I've had trouble with this in the past. Just need some tactics how other handle it.

I'm not sure why you need that second class. You might also save a bunch of Spells to a text file or something. How you store them is up to you.
I've done this kind of large classes in the past and always had some trouble with it. If I create as example a weapon like fireAxe = new Weapon(1, "fireAxe"); and I give this weapon to multiple entities i.e. the player and a creature. If the durability is 1 and I hit a tree with this axe, both my weapon and his weapon will be broken, as the object that is in their hands is reffering to the same object. I don't know how to handle this type of multipleUsage classes. I know the player can do a Weapon myWeapon = new Weapon(1, "fireAxe") and the same in the creature. So they have not the same objects held in their hands, this is the way to tackle this problem, but it is not the smartest to write the constructor of your weapon in the main class (if you get what I mean with this). I want a global class that has easy access to all of the different weapons. So it only takes one line (withouting adding variables yourself), to take the weapon and use it (without duping it). How are you handling that?
/*Edit*/
Well I know you can do the following to get a weapon without duping it,
 1 `public Weapon createFireAxe(){return new Weapon(1, "fireAxe");}`

but this isn't a great way of getting a specific weapon.

-RoseSlayer
15  Game Development / Newbie & Debugging Questions / Re: Handling a large variety of spells and/or weapons on: 2015-09-16 18:41:47

In other words, you shouldn't have a bunch of classes for different kinds of spells. You should have a single Spell class, and that class should contain (in other words, be composed of) all of the variables necessary to describe the different kinds of spells. Then to create a new spell, you just create a new instance of Spell, not a new subclass.

So basically I need to create like two classes:
• Spell - A class that contains all the code which has a constructor, so you can edit everything
• Spells - In here you create a spell like: Spell fireball = new Spell(1, true, 12.1f (...))

Well this will safe alot of time, but spells are in this way not unique. So if you have multiple players with a fireball, playerA has fireball(lv.1) and playerB has fireball(lv.14), they will both be calling the same fireball. I know you can do fireball.cast(levelFireball) etcetera, but with weapons this will not work (atleast I don't believe it will), also using this methode I cannot use different ways of leveling up a spell, for example a spell like enrage(this will buff the player), has other variables then a spell like fireball. If for example upgrading fireball from lv.1 -> lv.2 will give it an unique feature like spawn triple fireballs, how will I handle this in the Spell class. Doesn't this class get way too large if I create like 20 different levelMethodes?

/*Edit*/

/*Edit2*/
I can also create a class that contains vars as:
 1  2  3 `   public static final byte focusEnemy = 0;   public static final byte focusPlayer = 1;   public static final byte focuseAll = 2;`

and just call them in the  Spells class as:
 1  2 `   Spell fireBall = new Spell(true, focusEnemy);   Spell enrage = new Spell(true, focusPlayer);`

This type of spellHandling is already alot better than I am currently doing, but still is it the best?

What is your way to tackle this problem?
-RoseSlayer (Also thanks for responding as quick as you did!)
16  Game Development / Newbie & Debugging Questions / Bit operating + Handling Weapons and/or Spells on: 2015-09-16 18:19:17
Good afternoon,

as the title already has stated, I am trying to handle a large variety of spells (and/or weapons). Because weapons are basically the same idea as spells we will not talk about them. Basically I am new in handling large amount of objects which are almost the same. The only problem is that I do not know, where I need to start. I've searched online and found some decent tutorials about oop and Multiple Inheritance. But I've not become much smarter after reading that. The only thing I've learned is that you need to use Interfaces. But I believe that Interfaces are not that usefull, because you still need to write and copy all the code to do the same thing.

Interfaces
Java Multiple Inheritance

My Current setup is as following:
• EntitySpell extends Sprite
• SpellCaster (*)
• Spell (**)
• SpellFireBall extends Spell (***)

*SpellCaster:
This class is basically just a timer of the spell it is 'holding'. It is also holding the level of the spell (but I've not implemented the leveling system yet).

 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 `[quote]public class SpellCaster {   private float timer;      Spell spell;      public SpellCaster(Spell spell, int level){      this.spell = spell;      this.timer = spell.getCooldown();   }      public void update(float dt){      if(timer < spell.getCooldown())         timer+=dt;   }      public float getMana(){      return spell.getMana();   }      public boolean castSpell(float x, float y){      if(timer >= spell.getCooldown()){         spell.castSpell(x, y);         timer = 0;         return true;      } else {         return false;      }   }}`

The castSpell is a boolean, if it get casted, then the mana of the player will be reduced by the manaCost which is located in the SpellCaster

**Spell:
Just a simple abstract class that contains some information about the spell i.e. mana/cooldown (and it passes the castSpell event).

***SpellFireBall:
This is the real problem, I am trying to solve the issues it is providing me with, I don't want to write the code twice on multiple Spells like i.e. SpellLightningBolt. It is just a waste of space and time, at this moment it is still a small class without many lines of code in it, but when this class is completed it will be filled with information which is on many spells the same (but remember, not all the spells will be the same, i.e. buffs will be targeted to player instead of target to the cursor. These buffs will only work on the player and not on the enemy unlike the spell FireBall).
Because of this I cannot create a superclass Spell that is extended by SpellFireBall. So what is the best way of creating classes like Spells and or Weapons.

Please, if you have dealt with this issue on your project(s), can you tell me what you've done? I am not seeking for your codes or whatever, just a summary of what you've done or what you think that is the correct way.

As always, thanks for reading the post
-RoseSlayer
 17 Game Development / Game Mechanics / Re: LibGDX Celestial/Planetary bodies TileMap on: 2015-05-10 16:20:03 I get it, was thinking about changing the texture aswell to get a hill etc. Thank you very much for your help. The game in the last image is probably, as you said, another approach, but your approach is better for the thing I want to accomplish, so thank you very much.Now I need to tackle another problem, the hitboxes etc. I don't need a fixed scale regardless of the distance you are from the center of the planet, well not for the tilemap, only for the entities (but that's not any problem).Thank you very much, for your fast responding and your help!-RoseSlayer
 18 Game Development / Game Mechanics / Re: LibGDX Celestial/Planetary bodies TileMap on: 2015-05-10 15:52:05 Yes that is exactly what I meant. Is it also possible to have variation in Height, or even better using a dynamic Tilemap like in Terraria?
20  Game Development / Newbie & Debugging Questions / Re: Check if it's a combo/streak on: 2015-03-08 16:10:42
First of all, thanks for all the help and time investigated.
BurntPizza, and richierich, you both understood the problem.
But there is another problem by doing the following:

 1  2 `if (grid[y][x+1] == cellValue && grid[y][x+2] == cellValue)            //Horizontal streak!`
and
 1 `if (grid[x][y - 1].equals(center) && grid[x][y + 1].equals(center)) {}`

The problem of these codes is that the script works by comboLength >= 3, but if you want the comboLength >= 4, you can't use these scripts.
So the only solution I could think of is a forLoop. By doing that the script gets kinda choatic, and sometimes require more CPU then other times, which result in laggspikes.
Is there no way of finding the streaks within the grid[x.][y]? like:
 1 `grid[x][y = 0]{1, 1, 0, 1, 1, 1, 0 , 0}.contains({1, 1, 1}) -> [x=5][y=0]`

The above is the psuedocode, but again there is a problem with the variable comboLength, any other ideas how to solve this problem?

-RoseSlayer
21  Game Development / Newbie & Debugging Questions / Re: Check if it's a combo/streak on: 2015-03-05 19:56:11
It is possible to use this function:

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20 `   public Byte grid[][] = new Byte[8][8];   public Byte gridComboLength[][] = new Byte[8][8];   public void checkCombo(){      for(int y = 0; y < gridHeight; y++){         for(int x = 0; x < gridWidth; x++){            int ix = x + 1;            int comboLength = 0;            boolean checkHorizontalCombo = true;            while(checkHorizontalCombo && ix < gridWidth){               if(grid[x][y] == grid[ix][y]){                  comboLength++;                  ix++;               } else                   break;            }            gridComboLength[x][y] = (byte) comboLength;            x = ix;         }      }   }`

But this is only for the horizontals, so I need 2 times this code.

 1  2  3  4  5  6  7 `Grid[][]={1, 0, 2, 0, 0, 0, 2, 0}{1, 1, 0, 1, 1, 2, 2, 0}GridComboLength[][]={1, 1, 1, 3, 0, 0, 1, 1}{2, 0, 1, 2, 0, 2, 0, 1}`

So you see that at [3][0] there is a combo of 3 (according to this Grid)
 22 Game Development / Newbie & Debugging Questions / Re: Check if it's a combo/streak on: 2015-03-05 19:01:08 Quote from: KevinWorkman on 2015-03-05 18:44:17You would use a nested for loop.What have you tried?Sorry for the limited information given.I've tried quite alot, but it was done with objects and not tiles. First Forloop:Previously I was checking on every Tile, if it's connected to the left, right, top, bottem. and if it was connected to the right and not the left it was assigned as the start of a (horizontal)combo. the same goes for top and bottem, if it was connected to the bottem and not top, it was assigned as a start of a (vertical)comboSecond Forloop:In the second forloop the code is searching for the Tiles that were assigned to a forloop and then create a forloop within to get the length of the combo (which is extremely inefficient).Third Forloop:Execute the combo in the Tile.executeCombo(comboLength);Forth Forloop: Remove every Tile that was in a combo and create a new Tile in the grid.But if you can read this, there were so much forloops and extremely inefficient..The problem I am also experiencing is that I don't know the exact name of that what I am doing, so I cannot google it for any hints/tips..But long story short I've removed all the Tile classes and I am doing it now with the identities(byte) to create a faster and cleaner function.Also an offtopic question, are double-dimensional arrays not faster as you can write it in [x.][y] instead of [x+y*gridWidth]?-RoseSlayer
23  Game Development / Newbie & Debugging Questions / Check if it's a combo/streak on: 2015-03-05 18:41:48
Greetings JGO,

In this application I've created a grid[][] with Bytes in it.

 1  2  3  4  5  6  7  8 `{1, 0, 2, 0, 0, 0, 2, 0}{1, 1, 0, 1, 1, 2, 2, 0}{1, 0, 0, 2, 1, 0, 0, 0}{0, 1, 0, 2, 2, 0, 1, 0}{2, 0, 1, 2, 1, 0, 2, 2}{1, 2, 0, 2, 1, 0, 1, 0}{0, 1, 1, 0, 0, 0, 1, 2}{0, 0, 0, 0, 1, 0, 2, 0}`

A combo/streak is 3 of the same bytes next to each other, for example {1, 1, 1}. This can occur horizontal and vertical.
But the question is, how do I achieve finding all combos/streaks?

If possible, give an example, explained in words, of how it's done, as I am here to learn and not copy codes.

If you have any questions, just say it.
-RoseSlayer
24  Game Development / Newbie & Debugging Questions / Re: Android Rendering platform Chunk tiles. on: 2015-01-28 19:04:56
tiles[x + y*16] The tiles are already stored consecutively

Tile.render():
 1  2  3 `   public void render(Canvas c, Level level, float x, float y) {      level.gameView.gfx.renderBitmap(c, bmp, x, y, level.scale, false, false);   }`

Graphics.renderBitmap():
 1  2  3  4  5  6  7 `   public void renderBitmap(Canvas c, Bitmap bmp, float x, float y, float scale, boolean centeredX, boolean centeredY){      Matrix m = new Matrix();      m.postTranslate((centeredX ? (-bmp.getWidth() / 2) : 0), (centeredY ? (-bmp.getHeight() / 2) : 0));      m.postScale(scale, scale);      m.postTranslate((float)x, (float)y);      c.drawBitmap(bmp, m, null);   }`

chunk.render_tile() isn't used, it was just a simple  Tile.getTile(tiles[x + y*16]).render(canvas, level, x, y);

But it's true I am performing 32(probably more) multiplications per tile, which is insanly inefficient.
I think the problem is also the way I am getting the Bitmap that correspond with the TileId..

:
 1  2  3 `   public static Tile getTile(byte id) {      return tiles[id];   }`

This are already some iterations less..

[edit 2:]
Found some websites, after a long time searching:
Voxel 3D Chunk management

Greetings,
Roseslayer.
25  Game Development / Newbie & Debugging Questions / Re: Android Rendering platform Chunk tiles. on: 2015-01-28 16:22:55

The getTile is pretty straight-forward:
 1  2  3  4  5  6  7  8 `public static Tile getTile(byte id) {      for(Tile t: tiles){         if(t.getId() == id){            return t;         }      }      return null;   }`

And using DDMS, how can you find the location where the CPU is being eaten up?

Greetings,
Roseslayer
26  Game Development / Newbie & Debugging Questions / Android Rendering platform Chunk tiles. on: 2015-01-27 20:12:07
Dear JGO-community,

I've came across a big issue in the devolpment in my game, the rendering of the tiles within the chunks are causing some FPS drops. So really my question is how to render the tiles of the chunk cpu-efficient? I've already tried some solutions but they didn't really fit the job..

What've tried so far:
Code in Chunk.java
 1  2  3  4  5  6  7  8  9  10  11 `public void render(Canvas canvas, Level level){       for(int x = 0; x < 16; x++){          for(int y = 0; y < 16; y++){             if((cx*16+x)*16*level.scale >= level.xOffset - 16*level.scale && (cx*16+x)*16*level.scale <= level.xOffset + level.gameView.width){                 if((cy*16+y)*16*level.scale >= level.yOffset - 16*level.scale && (cy*16+y)*16*level.scale <= level.yOffset + level.gameView.height){                    Tile.getTile(tiles[x + y*16]).render(canvas, level, (cx*16 + x)*16*level.scale - level.xOffset, (cy*16 + y)*16*level.scale - level.yOffset);                    }             }           }       }    }`

This gave a FPS from 30 to around 20 and was pretty instable, so I rewrote the whole code to something that didn't used that much forloops:

Code in Level.java
 1  2  3  4  5  6  7  8  9  10  11 `public void render(Canvas c) {      for(int tileX = (int)((xOffset)/scale)/1; tileX < (int)((xOffset + gameView.width)/scale)/16; tileX++){         for(int tileY = (int)((xOffset)/scale)/1; tileY < (int)((yOffset + gameView.height)/scale)/16; tileY++){            for(Chunk chunk : chunkListOpen){               if(chunk.cx == (int)(tileX/16) && chunk.cy == (int)(tileY/16)){                  chunk.renderTile(c, this, Math.abs(tileX%16), Math.abs(tileY%16));               }            }         }      }}`

While running this script the FPS was around 3..

chunkListOpen are 3x3 chunks (in which the center chunk is the chunck which the player is located at)

So really the question is how do you render the visible tiles (most times around 20x8tiles) in 9 chunks efficient?
If you have any questions, feel free to ask them.

Edit:
These are all the tiles visible on the screen

 1  2 `for(int tileX = (int)((xOffset)/scale)/1; tileX < (int)((xOffset + gameView.width)/scale)/16; tileX++){         for(int tileY = (int)((xOffset)/scale)/1; tileY < (int)((yOffset + gameView.height)/scale)/16; tileY++){`

Greetings,
Roseslayer
27  Game Development / Newbie & Debugging Questions / Re: ANDROID Perlin Noise clouds & CPU-Usage & Bitmaps on: 2014-11-14 16:46:04
Did you profile it? What's in isTransparent(...)?

 1  2  3  4  5  6 `   public boolean isTransparant(int image, int x, int y){      if(getColor(image, x, y) == Colors.transparent){         return true;      }      return false;   }`

I don't know if it is better to retrieve the pixels[] of the mask and only change the integers in that, that doesn't have the value 0 (which is transparent)... Changing that right now, and checking if it is a better way.

Then don't create a new Bitmap every time and recycle Bitmaps. Make two Bitmaps (mask and target) parameters to "generate clouds".  Handle the error case when mask and target are not the same size. Certainly the "clouds" bitmap can be recycled.  I don't know how many mask images you load or how often this method is called.

Recycling it is indeed a better way, but I don't know if that is really efficient, because if you want to overwrite a bitmap you need to make a copy (or I am wrong, kinda new to Android) But I am giving it a try

:
O wow, it takes like some milliseconds to generate the entire map instead of 20 seconds... Reusing the Bitmaps with
 1 `options.inMutable = true;`
is like the heaven of speed ^w^!

And for the isTransparent fuction, i changed it to just retrieve the pixels[] from the mask and don't do anything if the value is 0 which is transparent. Because the getPixel function is probably not the most efficient function out there..
Thanks for all the help but I am still stuck with the Perlin Noise question, how can you really have cloudy effects (I am just shifting the x and y value). Like the effects that make the perlin noise clouds look like they are 'blooming'..

-RoseSlayer
 28 Game Development / Newbie & Debugging Questions / Re: ANDROID Perlin Noise clouds & CPU-Usage & Bitmaps on: 2014-11-12 16:39:28 Quote from: BurntPizza on 2014-11-12 16:17:46Ah, well if this is on Android, then all bets are off.Well, it's a big twist, but whilst this topic was mainly about the generation of clouds using Perlin Noise, the rendering of the clouds are causing a problem..
29  Game Development / Newbie & Debugging Questions / Re: Perlin Noise clouds & CPU-Usage on: 2014-11-12 16:04:42
After some testing, i've proved that the Perlin Noise doesn't use alot of CPU, it's the creating of the bitmaps...
I think I've a really inefficient way of generating the Bitmap

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24 `public Bitmap generateClouds(int image, int depth, int height, int ex, int ey){      Bitmap mask = BitmapFactory.decodeResource(getResources(), image, options);      Bitmap clouds = createBitmap(mask.getWidth(), mask.getHeight());            SimplexNoise sn = new SimplexNoise();      int pixels[] = new int[mask.getWidth()*mask.getHeight()];      for(int y = 0; y < mask.getHeight(); y++){         for(int x = 0; x < mask.getWidth(); x++){            if(!isTransparant(image, x, y)){               int z = (int)(depth+(sn.octavedNoise(x + ex, y + ey, 3, 0.4f, 0.05f)+0.5)*(height-depth));               if(z > 120){ //

Result:
Whilst it provides a good result, it has a FPS of 3-6..

At the start of the game, it starts to generates like 16-22 Bitmaps and the time it takes is 20s...
 30 Game Development / Newbie & Debugging Questions / ANDROID Perlin Noise clouds & CPU-Usage & Bitmaps on: 2014-11-11 16:26:21 Hi there,I know there are probably millions of topics out there about this, but I can't seem to find a good tutorial on how to do it. The problem is that the FPS drops.. Are there any CPU-friendly ways to do it? Or shall I just have a noise tileset. I've already implemented a Perlin Noise gen. If there is any article about it, let me know.As you probably know it needs an alpha level, yet I don't know how to accomplish it, because the bitmap is like only changing the alpha-level of all the pixels... The clouds only have 1 color and 3 alpha levels(AL). the first AL is like 0% transperant, the second AL is like 33% Transperant etc..So basically, how to make clouds and changing alpha levels of them. Only use words if you can, I need to write my own program and learn from it ^w^!-RoseSlayerPost scriptum: if you have any questions just ask them!
 Pages: [1] 2 3 ... 5
 roseslayer (468 views) 2016-08-06 11:43:29 roseslayer (426 views) 2016-08-06 09:43:11 xTheGamerCodes (502 views) 2016-08-04 15:40:59 xTheGamerCodes (493 views) 2016-08-04 15:40:24 orrenravid (843 views) 2016-07-16 03:57:23 theagentd (920 views) 2016-07-11 14:28:54 Hydroque (1016 views) 2016-07-06 05:56:57 Hydroque (1015 views) 2016-07-03 08:52:54 GrandCastle (828 views) 2016-07-01 09:13:47 GrandCastle (640 views) 2016-07-01 09:09:45
 Archive 43x Ecumene 26x Spasi 24x theagentd 22x DarkCart 15x h.pernpeintner 14x gouessej 14x EgonOlsen 13x orange451 13x ags1 11x admin 10x Riven 9x TheMeatMan 8x Brynn 8x philjord 8x Slyth2727 7x
 Rendering resourcesby Roquen2016-08-08 05:55:21Rendering resourcesby Roquen2016-08-08 05:52:42Rendering resourcesby Roquen2016-08-08 05:50:38Rendering resourcesby Roquen2016-08-08 05:49:53Rendering resourcesby Roquen2016-08-08 05:32:39Making a Dynamic Plugin Systemby Hydroque2016-06-25 00:13:25Java Data structures2016-06-13 21:22:09Java Data structures2016-06-13 21:20:42
 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