P0jahn

Member
  • Content count

    138
  • Joined

  • Last visited

Community Reputation

308 Neutral

1 Follower

About P0jahn

  • Rank
    Member

Personal Information

  • Interests
    Programming
  1. The method above works fine, I just posted it for the sake of completeness. Am actually trying to learn the math and not to get spoon feed. Anyway I resolved this by giving this unit its own camera/matrix, which I rotate and apply to the sprite batch before render and clear afterwards.
  2. Back again. So I got it to work. Here is the method I use to rotate points: public static Vector2 rotatePoint(final float x, final float y, final float cx, final float cy, final float rotation) { if (rotation % 360 == 0) return new Vector2(x, y); final float angleInRadians = (float) (rotation * (Math.PI / 180)); final float cosTheta = MathUtils.cos(angleInRadians); final float sinTheta = MathUtils.sin(angleInRadians); return new Vector2( (cosTheta * (x - cx) - sinTheta * (y - cy) + cx), (sinTheta * (x - cx) + cosTheta * (y - cy) + cy)); } Now I want to draw a small ball between these rectangles. They are like connectors. The thing that keeps the parts together. I did in a similar way, but they are slightly of. How do I get the correct position for these connectors?
  3. Cleaver and simple solution. Thanks!
  4. Hi! I am developing a 2D game in Java where top-left corner is (0,0) and bottom-right is (max x, max y). I want to render rotated rectangles next to each other. Say I have the following image(rotation 0): If I wanted to draw an other one of this next to this one so that the green line connects(or "chains"), I would simply draw it at previous rectangle position + rectangle with. Easy. If it however was rotated, like this(30 degrees): Then I would somehow have to recalculate both the x and y coordinate. Not sure how to do this. Any help would be appropriated.
  5. 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.
  6. 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; }
  7. 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.
  8. 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.
  9. 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.
  10. 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 =)
  11. 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?
  12. Hi Krypt0n. I like your first suggestion. How do you handle the foreground image(s) when you use a tile based game?   My game:  
  13. 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? 
  14. 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 :)
  15. 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?