Java-Gaming.org Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (616)
Games in Android Showcase (173)
games submitted by our members
Games in WIP (659)
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] 2 3 4
1  Game Development / Game Mechanics / Re: Rendering only visible isometric tiles on: 2015-02-08 01:43:28
Right, I eventually realised where I was going wrong. Smiley It wasn't that interesting problem in the end - just swapped the order of a few operations. Got it working now - works great!

If anyone's interested, here's what I have at the moment. I suppose javascript's better than nothing: http://www.java-gaming.org/?action=pastebin&id=1204

Thanks for the help. Cheesy
2  Game Development / Game Mechanics / Re: Rendering only visible isometric tiles on: 2015-02-05 22:45:11
Right, that seems to work well. Smiley There's just one small glitch when I introduce a "camera" to offset the scene with. It seems that the Y component is incorrect on every odd X component, as you can see in screenshot 2 (that's when I move 32 pixels right). Can you spot what I'm doing wrong?

The blue tile signifies the (0, 0) tile coordinate that I've just set as a landmark.

Green tiles are the tiles within the map and brown tiles are default "out-of-bounds" tiles that are rendered when scanning over a position outside the map boundaries.

Image 1 is your default starting position and Image 2 is when I move 32 pixels to the right.



Main render method:

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  
Render: function() {
   this.Display.Clear("#000000");

   var intTileWidth = 64;
   var intTileHeight = 32;

   var intMapWidth = 15;
   var intMapHeight = 15;

   var intHorizontalTiles = Math.ceil(this.Display.Viewport.intWidth / intTileWidth) << 1;
   var intVerticalTiles = Math.ceil(this.Display.Viewport.intHeight / intTileHeight);

   var intTileStartX = Math.round(this.Display.Viewport.Camera.intPositionX / intTileWidth);
   var intTileStartY = Math.round(this.Display.Viewport.Camera.intPositionY / intTileHeight);

   for(var y = -1; y < intVerticalTiles; y++) {
      for(var x = -1; x < intHorizontalTiles; x++) {
         var bIsEven = !(x % 2 == 0);
         var intTranslatedX = x - intTileStartX;
         var intTranslatedY = y - intTileStartY;
         var intIsoX = Math.round(intTranslatedX / 2 + intTranslatedY);
         var intIsoY = Math.round(intTranslatedY - intTranslatedX / 2);

         var intSpriteX = 0;
         var intSpriteY = 0;

         if(intIsoX < 0 || intIsoX >= intMapWidth || intIsoY < 0 || intIsoY >= intMapHeight) {
            intSpriteX = 64;
         }
         if(x==y&&x==0) intSpriteX = 128;
         this.Display.DrawImageToViewport(intSpriteX, intSpriteY, 64, 32, x * (intTileWidth >> 1), y * intTileHeight + (bIsEven ? (intTileHeight >> 1) : 0), 64, 32)
      }
   }
}


Sorry for the javascript. :x I'd appreciate any help as the logic should be the same.
3  Game Development / Game Mechanics / Re: Rendering only visible isometric tiles on: 2015-02-04 23:11:26
Cheers for the quick reply! Mapping the isometric coordinates from the screen coordinates makes far more sense than what I was doing. Shocked I'll have to play around with that idea and see if I can work out how it'd work.
4  Game Development / Game Mechanics / Rendering only visible isometric tiles on: 2015-02-04 22:42:41
Hi all, my question is about how I would best go about rendering a scene of isometric tiles, while not attempting to render tiles outside of the viewport.

What I currently have is a 15x15 array of tiles, that I'm using nested for loops to cycle through. I'm transforming the position of each tile using the formula below and rendering them to the screen:

1  
2  
3  
4  
int isoX = (x - y) / 2;
int isoY = x + y;

display.drawImage(isoX * TILEWIDTH, isoY * (TILEHEIGHT >> 1), TILEWIDTH, TILEHEIGHT);


This renders as expected as a diamond shape, with +X leading to the bottom right and +Y leading to the bottom left. This is illustrated by the image below:




This issue is that I'm completely stumped about how I would go about rendering a square of tiles, with the ability to clip tiles that aren't within the viewport. Notice the large black areas in the image above.

I like the idea of rendering a diamond shaped map, although ideally, rather than not rendering a tile at all, I'd like to loop over (somehow) the area that this tile would occupy and set it to render a default or "edge of map" tile, such as a boundary defining tile like impassable trees.

If this is possible, then I'm hoping that it wouldn't be that greater stretch to use this information to then decide which tiles lie outside of the viewport.

I've looked through a few tutorials, although my understanding of this area is very sketchy. Would anyone mind walking me through how I could achieve these goals logically? Smiley
5  Game Development / Game Mechanics / Re: 2D side scroller platformer - detecting collisions with big movement intervals on: 2014-11-12 18:16:38
Yeah, that's a good point. I probably should have set one. Tongue It's not crucial that entities move that fast. Ah well, maybe I'll set one for the hell of it.

Anyway, got this all working now. Cheers for your help guys!
6  Game Development / Game Mechanics / Re: 2D side scroller platformer - detecting collisions with big movement intervals on: 2014-11-12 00:00:13
Hiya, thanks for the reply. Smiley Sounds good. I'll have a play around with it. Cheers!
7  Game Development / Game Mechanics / 2D side scroller platformer - detecting collisions with big movement intervals on: 2014-11-11 21:20:23
Hi all,
I'm making a 2D side scrolling platformer, where the platforms are effectively a 2D array of tiles rendered in much the same way as a standard 2D top-down game (0, 0) top left hand corner to (mapWidth * tileWidth, mapHeight * tileHeight) which is the bottom right hand corner. The player can land on tiles, depending on whether they're set in the array, or walk into them, or bang their head on them, etc.

Gravity is acting on the player, so if they aren't standing on a tile, they'll keep falling faster, until they reach the end of the tile map, then they'll fall forever. Everything's going fine, but I'm determining collisions much in the same way as I've been doing in the top down games, whereby I divide the player's position + delta movement, divide each of the player's surrounding corners by the tileWidth and tileHeight, then loop through them, checking if they're passable and if one isn't, I stop the player from moving in that axis.

That's all fine for those games because the player doesn't move by a significant amount at a time, but obviously when gravity's introduced the player begins to clip through tiles, because the tile features between the player's position and the player's position + delta movement.

Are there any standard methods of solving this problem as at the moment, when the player's falling more than, say, 50 blocks, they can clip straight through entire platforms.

If anyone could give me any tips on this I'd appreciate it.
8  Game Development / Game Mechanics / World to screen coordinates on: 2014-04-30 04:52:16
Hi all, I've just got a quick question relating to converting world coordinates to screen coordinates. I've got a code snippet below that's written in javascript rather than java, but it should be fairly understandable. My issue is that I'm performing a 3D perspective projection, but this function allows for points that are behind the camera (off the screen) to still be rendered. I'm wondering whether there's a check that I can perform to check whether the point in question is outside of the view. I know it's not a very good way of doing this. :p I'm just playing around trying to get something made. If anyone knows how I perform this check I'd appreciate your help. Thanks

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  
var xOffset = canvas.width >> 1;
var yOffset = canvas.height >> 1;

function world_to_screen(x, y, z) {
   // Vert relative to camera position
   var rel_x = x - xCam;
   var rel_y = y - yCam;
   var rel_z = z - zCam;

   // Vert relative to camera orientation
   var c = Math.cos(yRot * (Math.PI / 180.0));
   var s = Math.sin(yRot * (Math.PI / 180.0));
   var orient_x = c * rel_x + 0 * rel_y - s * rel_z;
   var orient_y = 0 * rel_x + 1 * rel_y + 0 * rel_z;
   var orient_z = s * rel_x + 0 * rel_y + c * rel_z;

   var proj_point = persp_point(orient_x, orient_y, orient_z);
   var screen_x = ((proj_point[0] * canvas.height) | 0) + xOffset;
   var screen_y = ((proj_point[1] * canvas.height) | 0) + yOffset;

   return [screen_x, screen_y];
}

function persp_point(x, y, z) {
   return [x / z, y / z];
}
9  Game Development / Game Mechanics / Re: A* path finding on: 2014-04-14 18:54:15
All works great. Cheesy Thanks for everyone's help. Hey UprightPath, when you say the next shortest path, wouldn't that always be greater than the shortest path? Also, do you know how I would solve that problem?
10  Game Development / Game Mechanics / Re: A* path finding on: 2014-04-14 18:33:13
Thanks for all your help. Smiley I'll try this out and reply back.
11  Game Development / Game Mechanics / Re: A* path finding on: 2014-04-14 14:24:02
Yeah, I've tried adding in a few print statements to help shed some light but it's a bit overwhelming and I'm not sure what I'm supposed to be looking for. Sad
12  Game Development / Game Mechanics / Re: A* path finding on: 2014-04-14 14:09:53
All the tutorials I've looked at have told me to add the start node to the open list. :x
The start node is removed almost immediately because it is the node with the lowest f value in the open list and that node is removed at the beginning of the loop.
13  Game Development / Game Mechanics / Re: A* path finding on: 2014-04-14 13:50:22
Hi all, I'm just trying to implement this algorithm that I've mentioned above, but it seems to be stuck loading endlessly.

Here's my source: http://www.java-gaming.org/?action=pastebin&id=896

At the moment I'm declaring it with the start and goal nodes set to (0, 0) and (10, 5) respectively. Can anyone spot the reason why it's loading out?

Thanks!
14  Game Development / Game Mechanics / Re: A* path finding on: 2014-04-09 21:36:50
Thanks guise. Smiley
15  Game Development / Game Mechanics / Re: A* path finding on: 2014-04-09 21:36:31
Oh yeah, of course. Tongue That makes sense. Sorry for not getting that's what you meant, Riven. :x I'm knackered today.
16  Game Development / Game Mechanics / Re: A* path finding on: 2014-04-09 21:12:07
Oh, I think I originally misread the pseudo code. Am I right in thinking the path is in the closed list once this has ended?
17  Game Development / Game Mechanics / A* path finding on: 2014-04-09 20:55:02
Hi all,

I don't mean to create a topic regarding the exact same subject as another topic on the front page, but I didn't want to hijack their's. :p
Anyway, I've been implementing A* path finding from a tutorial found here: http://web.mit.edu/eranki/www/tutorials/search/
I've been going off the algorithm detailed at the bottom of that page and was just wondering where the final path is.
In other implementations of this algorithm, there was an open, closed and final path list. I understand most of the algorithm, but once it's been designed, how do I access the final list of nodes?

Thanks Smiley
18  Game Development / Newbie & Debugging Questions / Re: Bresenham's line algorithm on: 2013-10-15 21:13:08
Ah, I see why it's 1. :x Sorry, didn't read the preceding paragraph clearly enough.
19  Game Development / Newbie & Debugging Questions / Re: Bresenham's line algorithm on: 2013-10-15 19:41:19
Hey guys, thanks for the replies and sorry to resurrect an old topic, but I just have one quick question about the floating point method. Smiley Here's the article I'm referring to again:
http://en.wikipedia.org/wiki/Bresenham's_line_algorithm

My question is, after the error exceeds 0.5 and the Y component is increased, why is the error decreased by 1? I understand why it's decreased, but what is the significance of decreasing it by 1 exactly?
20  Game Development / Newbie & Debugging Questions / Bresenham's line algorithm on: 2013-09-18 21:28:15
Hi all, I've just found a Javascript implementation of the Bresenham's line algorithm and I'm just trying to understand what it's actually doing and was wondering whether anybody would mind giving me a brief explanation about a few lines of it.

Here's the algorithm 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  
29  
30  
function renderLine(x0, y0, x1, y1) {
    var xx0 = x0;
   var yy0 = y0;
   var xx1 = x1;
   var yy1 = y1;
   
   var dx = Math.abs(xx1 - xx0);
   var dy = Math.abs(yy1 - yy0);
   
   var stepx, stepy;
   if(xx0 < xx1) stepx = 1;
   else stepx = -1;
   if(yy0 < yy1) stepy = 1;
   else stepy = -1;
   
   var err = dx - dy;
   while(true) {
      renderPoint(xx0, yy0);
      if(xx0 == xx1 && yy0 == yy1) break;
      [b]var e2 = err << 1;
      if(e2 > -dy) {
         err -= dy;
         xx0 += stepx;
      }
      if(e2 < dx) {
         err += dx;
         yy0 += stepy;
      }[/b]
   }
}


The section I'm having difficulty getting my head around is emboldened. I understand from reading the wikipedia page on the different methods of implementing it that you create an error variable and loop through every value between the two points X components, then you add the slope of the line to the error until it reaches over 0.5 and then you increase the Y component and subtract 1 from the error. I also understand that this is more or less what's happening above using integer arithmetic rather than floating point arithmetic although I'm not entirely sure why error needs to be multiplied by 2 or what the significance of this being over -dy or under dx is. Forgive my noobiness - I'm just stuck with this. Tongue If anyone could explain this I'd be grateful.

Thanks
21  Game Development / Newbie & Debugging Questions / Rotation around an arbitrary axis on: 2013-08-16 02:54:22
Hi all,
Just got an issue with a 3D first person view I'm trying to create for use with LWJGL. I've got 3 vectors representing the side, up and forward axes set at (1, 0, 0), (0, 1, 0) and (0, 0, 1) respectively. When rotating the view I perform a "rotation around an arbitrary axis" about the vector representing the axis I want.
It's all working as expected, but I want the camera to rotate around a fixed Y axis (0, 1, 0) as it does in most FPS games, but at the moment it's just rotating around the up vector, whichever way it's pointing. The issue here is that X axis rotations changed the direction of the Y axis, so it won't stay at (0, 1, 0). Is there any way around this? Here's my current camera class for reference: http://www.java-gaming.org/?action=pastebin&id=684
Thanks in advance for any help Smiley
22  Discussions / Miscellaneous Topics / Re: Quadratic equations on: 2013-06-13 01:32:22
Thanks for the reply. Smiley Yeah, all I remember from secondary school with regards to quadratic equations was that formula. I'm just trying to look at the other methods of solving it to help me get a better understanding. Completing the square is the method that I recall the teacher saying takes too long to work out in an exam. Hurray for the British education system. D: So now I'm trying to learn it on my own and struggling a bit.
23  Discussions / Miscellaneous Topics / Re: Quadratic equations on: 2013-06-13 01:18:43
Old enough for it to be embarrassing. ): I'm alright with other areas of algebra. This has just stumped me.
24  Discussions / Miscellaneous Topics / Re: Quadratic equations on: 2013-06-13 00:18:55
Yeah, I keep re-reading this instructions thinking I'm missing a subtle wording, but that step completely throws me. The other steps are fairly trivial.
25  Discussions / Miscellaneous Topics / Re: Quadratic equations on: 2013-06-12 23:55:04
Thanks for the replies guys! So Geemili, is what I described just FOIL in reverse?
26  Discussions / Miscellaneous Topics / Quadratic equations on: 2013-06-12 23:39:40
Hi all, I'm trying to learn how to solve quadratic equations but I've ran into a problem.
On the wikipedia page: http://en.wikipedia.org/wiki/Quadratic_equation
It explains the step by step process of solving a quadratic equation using the "Complete the square" method. The fourth step states: "Write the left side as a square, and simplify the right side, if necessary."
And this appears to change the expression "x² + 2x + 1" into "(x + 1)²" and I'm not exactly sure how that's come about. Could somebody explain it to me?

Thanks!

Paul
27  Game Development / Newbie & Debugging Questions / Re: Bayer ordered dithering on: 2013-05-06 22:43:25
Thanks. Smiley I'll substitute it.
28  Game Development / Newbie & Debugging Questions / Re: Bayer ordered dithering on: 2013-05-06 22:32:23
Thanks for your help. Smiley I'll have a sit down and try and understand it.
29  Game Development / Newbie & Debugging Questions / Re: Bayer ordered dithering on: 2013-05-06 22:20:10
Thanks for the reply. That seems to work far better. Smiley It's just that it looks very bright. The image becomes saturated by light.
30  Game Development / Newbie & Debugging Questions / Re: Bayer ordered dithering on: 2013-05-06 17:23:01
Ah I see. Do you know how I would apply this to my algorithm?
Pages: [1] 2 3 4
 
Coldstream24 (19 views)
2015-09-03 00:41:28

Andrew_3ds (31 views)
2015-09-01 19:08:10

afikri (20 views)
2015-08-31 09:30:22

afikri (27 views)
2015-08-31 09:30:07

afikri (15 views)
2015-08-31 09:27:24

afikri (17 views)
2015-08-31 09:26:40

Roquen (32 views)
2015-08-29 11:30:54

GamerC4 (41 views)
2015-08-22 20:38:50

GamerC4 (37 views)
2015-08-22 20:37:18

GamerC4 (43 views)
2015-08-22 20:37:01
HotSpot Options
by Roquen
2015-08-29 11:33:11

Rendering resources
by Roquen
2015-08-17 12:42:29

Rendering resources
by Roquen
2015-08-17 09:36:56

Rendering resources
by Roquen
2015-08-13 07:40:51

Networking Resources
by Roquen
2015-08-13 07:40:43

List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30
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!