Show Posts

Pages: [1] 2 3 4

2

Game Development / Game Mechanics / Re: Rendering only visible isometric tiles

on: 20150205 22:45:11

Right, that seems to work well. 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 "outofbounds" 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.



4

Game Development / Game Mechanics / Rendering only visible isometric tiles

on: 20150204 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?



7

Game Development / Game Mechanics / 2D side scroller platformer  detecting collisions with big movement intervals

on: 20141111 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 topdown 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: 20140430 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) { var rel_x = x  xCam; var rel_y = y  yCam; var rel_z = z  zCam;
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: 20140414 18:54:15

All works great. 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?



12

Game Development / Game Mechanics / Re: A* path finding

on: 20140414 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.



17

Game Development / Game Mechanics / A* path finding

on: 20140409 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



20

Game Development / Newbie & Debugging Questions / Bresenham's line algorithm

on: 20130918 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. If anyone could explain this I'd be grateful. Thanks



21

Game Development / Newbie & Debugging Questions / Rotation around an arbitrary axis

on: 20130816 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.javagaming.org/?action=pastebin&id=684Thanks in advance for any help



22

Discussions / Miscellaneous Topics / Re: Quadratic equations

on: 20130613 01:32:22

Thanks for the reply. 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.



26

Discussions / Miscellaneous Topics / Quadratic equations

on: 20130612 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_equationIt 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





javagaming.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

