Show Posts

Pages: [1] 2 3 4

3

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.



4

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]; } 



5

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?



8

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.



13

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



16

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



17

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



18

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.



22

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



27

Game Development / Newbie & Debugging Questions / Re: Bayer ordered dithering

on: 20130506 16:36:38

Yeah the threshold values range from 164, so presumably it breaches its respective channel fairly often which explains the artifacts, but I'm not entirely sure how to normalise the threshold value. I've tried dividing the value by 64, which is the highest value that is held in the matrix, although I'm working in whole numbers and only one instance would yield 1 and the rest would be 0.



28

Game Development / Newbie & Debugging Questions / Re: Bayer ordered dithering

on: 20130506 14:17:30

The closest colour rounding seems to actually be working before adding the threshold. As the colour's stored as an integer it performs the division first and rounds that result and then multiplies. So the end value is actually floored to the nearest 64 in this case. For example:
140 / 64 * 64 2 * 64 = 128
So 140 becomes 128 when floored to the nearest 64. Sorry if I'm teaching you how to suck eggs, I'm just making sure.



30

Game Development / Newbie & Debugging Questions / Bayer ordered dithering

on: 20130504 16:39:08

Hi all, I'm attempting to add a stylised order dithering effect on an image although I've been met with unexpected results. I have an 8 by 8 threshold matrix as follows: 1 2 3 4 5 6 7 8
 int[] dither = new int[] { 1, 49, 13, 61, 4, 52, 16, 64, 33, 17, 45, 29, 36, 20, 48, 32, 9, 57, 5, 53, 12, 60, 8, 56, 41, 25, 37, 21, 44, 28, 40, 24, 3, 51, 15, 63, 2, 50, 14, 62, 35, 19, 47, 31, 34, 18, 46, 30, 11, 59, 7, 55, 10, 58, 6, 54, 43, 27, 39, 23, 42, 26, 38, 22 }; 
I just found this on the wikipedia page for ordered dithering and have been following the explanation in order to produce this effect myself. The algorithm producing the effect from this matrix is as closely resemblant of that explained in the wikipedia page and is as follows: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
 int w = image.getWidth(); int h = image.getHeight(); int bd = 64; for(int y = 0; y < h; y++) { for(int x = 0; x < w; x++) { int c = pixels[y * w + x]; int d = dither[(y & 7) * 8 + (x & 7)]; int r = ((c >> 16) & 0xff) + d; int g = ((c >> 8) & 0xff) + d; int b = (c & 0xff) + d; newpix[y * w + x] = 0x000000  closestCol(r, bd) << 16  closestCol(g, bd) << 8  closestCol(b, bd); } } 
This is just the method that reduces the amount of colours available in each channel: 1 2 3
 private int closestCol(int c, int b) { return c / b * b; } 
The above code simply adds the corresponding value from the threshold matrix to the image data and then attempts to find the nearest colour to it after rounding. The issue is that the dither values are quite high and saturate the channel of the pixel. I've tried averaging the channel colour with the corresponding dither value but that makes the screen far darker than it should be. Is there a detail that I'm missing whereby it adds the effect without harshly altering the tone of the image? Just for reference, I've been consulting with this page: http://en.wikipedia.org/wiki/Ordered_ditheringHere's a before and after dither comparison so you can see the results: http://i.imgur.com/9SWukYS.pngThanks, Paul





Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.

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

