• Content count

  • Joined

  • Last visited

Community Reputation

307 Neutral

About P0jahn

  • Rank
  1. Added the optimisations suggested here and got it down to 1 ms(radius 20). As samoth mentioned, this is going to be calculated when ever a major bomb explodes, so it is far from every frame. I can live with it.
  2. Yeah, this wasn't so hard as I expected.   samoth: I found something very similar. The performance is ok I guess. Took 1.768828 milliseconds when the radius was 20, in Java. Complete code for future reference: public Set<Vector2> searchTiles(int x, int y, int r) { Set<Vector2> points = new HashSet<>(); for (int j=x-r; j<=x+r; j++) for (int k=y-r; k<=y+r; k++) if (distance(new Vector2(j,k), new Vector2(x,y)) <= r) points.add(new Vector2(j,k)); return points; }
  3. Thanks for the help. Tried some of the suggestions noted here, such as the link to Midpoint Circle Algorithm. While they work, they dont find the coordinates inside the circle. Ie they dont fill search.
  4. I am developing a game where the top left corner of the world is coordinate 0:0. Thus, x is increasing while moving right and y down.   I am trying to come up with an algorithm that finds the coordinates of the tiles within the given circle.   The method signature could look like this:   ArrayOfCoordinates findCoords(int centerX, int centerY, int radius)   Example, if radius is set to 1, it would search something like this: [attachment=28925:pic1.jpg]   If it is 2: [attachment=28926:pic2.jpg]   And 3: [attachment=28927:pic3.jpg]   4: [attachment=28928:pic4.jpg]   And so on.
  5. I am developing a game where a rectangles position is the top-left corner where x is increasing rightwards and y downwards.   What I am trying to achieve is to iterate through the boundaries of an rotated rectangle. Did some googling with no luck.
  6. Background is the sky, clouds etc. Static images. Serve no purpose other than decoration. Foreground is the ground, walls etc. Affects where you can walk etc.   So say I store the stage data as tile, like Krypt0n suggested, should I have a bunch of small images that maps to the tile pieces? And render them each frame etc.   It's kinda hard to explain because I am not sure what I want to do haha =)
  7. I am not storing every pixel. That would take ages for the sprite batch to render and the game would lag to hell. Currently, I am using one large image for the background(which is ok), and one of the foreground(bad). The problem with that is that I can not transform the tiles at playtime, because manipulating an managed image is a big no. So would be a good idea to split the image to a few tiles, and render them every frames? Or would that affect performance badly?
  8. Hi Krypt0n. I like your first suggestion. How do you handle the foreground image(s) when you use a tile based game?   My game:  
  9. In my current game, coded in Java, I store it in a 2D byte array(width, height). Each element is the size of a pixel.   When the stage gets large, the amount of ram used for it as high as 150 mb.   I dont know if this is the best approach. Any suggestions of an better way to store a stage efficiently? 
  10. Never mind the gaps. I dont want to calculate the number of links, it should be a fixed value like Randy Gaul suggested.   From the code posted above, I switched line from: Vector2 linkPos = endPoint1.lerp(endPoint2, (float)i/(float)links); to: Vector2 linkPos = endPoint1.lerp(endPoint2, (float)i/(float)(links-1));   And I got the results I wanted: One chain always on the start point and an other always at the end point.   The problem is that the distance between the chains are really odd. [attachment=24554:inconsistensy.png]   Why do the links at the left clot but not those at right?   Edit: Never mind. It was an typo. Works great :)
  11. unbird: Thanks, I will try to complete those tomorrow.    As for the original question, I did kinda what you suggested, but the distance between the chains are not consistent.   for(int i = 0; i < links; i++) { Vector2 linkPos = endPoint1.lerp(endPoint2, (float)i/(float)links); batch.draw(chainImage, linkPos.x, linkPos.y); } I also dont see why I need to subtract one link?
  12. Thanks.   How do I calculate the number of links(the position of the points can change at any time)? Also, if I want gap between the links?
  13. I want to code a chain for my game and am not sure how to do it so I am hoping to get some suggestions that get me started.   Details: You create a chain object and specify two points: start and end point.  The image of the chain object is one piece of the chain. Example: [attachment=24539:ring_228_00.png]   So it should look something like this ingame: [attachment=24540:example.png]   Ideas?
  14. I am developing a 2D game where x is increasing rightwards and y downwards. Thus, the top-left corner is 0,0.   I have an enemy that moves towards a set of waypoints. When one is reached, it will start moving towards the next waypoint in the list.   I use the following code to move towards a point: Vector2 norP = normalize(this.x, this.y, target.x, target.y); float accelx = thrust * -norP.x - drag * vx; float accely = thrust * -norP.y - drag * vy; vx = vx + delta * accelx; vy = vy + delta * accely; this.x += delta * vx; this.y += delta * vy; That piece works fine. The problem is detecting when a point has been reached.   Right now, I use the following: if(distance(this.x, this.y, target.x, target.y) < 25) { ... The value 25 is a fixed value and works sometimes. As you alter thrust and drag properties, the value 25 stops being effective. So I need a formula that calculates this value that works good no matter what thrust and drag is(taking them into consideration).
  15. Like most people already explained, use an two dimensional array with either an object type or byte. public static final byte SOLID = 0; public static final byte HOLLOW = 1; byte[][] worldTiles = new byte[stageHeight][stageWidth]; And when to check for collision, the fastest way is to treat all entities as rectangles(this is often enough). You then check if the border of the rectangle is colliding with solid tile. //Checks if the specified GameObject collides with the given tile public boolean collidesWithTile(byte tileType, GameObject go) { int x = (int) go.x, y = (int) go.y, x2 = (int) (go.x + go.width), y2 = (int) (go.y + go.height); for(int lx = x; lx < x2; lx++) { if(worldTiles[y][lx] == tileType || worldTiles[y2][lx] == tileType) return true; } for(int ly = y; ly < y2; ly++) { if(worldTiles[ly][x] == tileType || worldTiles[ly][l2] == tileType) return true; } return false; } go.x++; boolean canGoRight = collidesWithTile(HOLLOW, go); go.x--; The great thing about byte array is that they take so little space in the ram. An map with 25 million tiles wont take more than 100mb ram. You could also use a bunch of references instead of byte, which should take less space than byte.