Java-Gaming.org
 Featured games (78) games approved by the League of Dukes Games in Showcase (404) games submitted by our members Games in WIP (289) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
 Show Posts Pages: [1] 2 3 ... 9
1  Game Development / Articles & tutorials / Re: Gravity on: 2013-01-02 15:30:25
 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  35  36  37 `//fieldsprivate float x, y;private float vx, vy;private float elapsedTime = -1;private final float g = -10;private final float jumpingPower = 6;private final int FPS = 60;private final float DELTA = 1f/FPS;public void update() {    //crap here    if(/*spacebar is pressed*/) {        vy = jumpingPower; //you probably want a mechanism limiting the frequency of jumps        elapsedTime = 0;    }        //gravity affects vy constantly    if (elapsedTime != -1) {        vy = elapsedTime * DELTA * jumpingPower + g / 2 * elapsedTime * elapsedTime * DELTA * DELTA; // alternatively, set initial value of vy as the stuff before the + sign, and increment by the stuff after the + sign        y += vy;        elapsedTime++; // alternatively, increment by 'DELTA' and get rid of 'DELTA' in equation for solving vy    }        //collision detection    for(Blocks b : randomBlocks) {        if(this.intersects(b)) {            if (vy >= 0) { // We hit our head on something, start falling                elapsedTime = -2f * jumpingPower / g; // The time when vy changes from positive to negative, i.e. you start falling. Completely inelastic collision.            } else { // We landed on a platform, stop moving                vy = 0;                elapsedTime = -1;            }        }    }}`

That's my approach, from memory. Might have mistakes?
 2 Java Game APIs & Engines / OpenGL Development / Re: Newbie Polygon Texturing Question on: 2012-12-28 14:08:46 These tutorials are great; they're explained well..
 3 Java Game APIs & Engines / OpenGL Development / Re: Newbie Polygon Texturing Question on: 2012-12-28 05:31:45 Yes I'll eventually learn about these things, thanks for the link.One small step at a time!
 4 Java Game APIs & Engines / OpenGL Development / Re: Newbie Polygon Texturing Question on: 2012-12-28 05:22:52 Quote from: HeroesGraveDev on 2012-12-28 05:21:54Quote from: counterp on 2012-12-28 05:19:35So I have to reuse vertices, it can just be one fluid motion, going from vertex to vertex. i.e. in my original drawing, I have to texture the triangles:1, 2, 41, 3, 43, 4, 63, 5, 65, 6, 85, 7, 87, 8, 107, 9, 10(I'm calling glVertex2f 24 times. When there are only 10 vertices)You could use GL_TRIANGLE_STRIP which lets you reuse 2 vertices each time resulting in 10 glVertex2f() callsInteresting. Sounds like what I was looking for@davedes that's what the code I posted does, I just wasn't sure if I was taking the long way about doing it
 5 Java Game APIs & Engines / OpenGL Development / Re: Newbie Polygon Texturing Question on: 2012-12-28 05:19:35 So I have to reuse vertices, it can't just be one fluid motion, going from vertex to vertex. i.e. in my original drawing, I have to texture the triangles:1, 2, 41, 3, 43, 4, 63, 5, 65, 6, 85, 7, 87, 8, 107, 9, 10(I'm calling glVertex2f 24 times. When there are only 10 vertices)
6  Java Game APIs & Engines / OpenGL Development / Re: Newbie Polygon Texturing Question on: 2012-12-28 05:02:26
It's OpenGL and the texture should be zig zagging.

I have the effect working, it's just not very efficient:

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19 `            float difY = tile.top() - tile.bottom();            int offZ = off % 360;            float o_ = 0;            for (int z = offZ; z <= 360 + offZ; ) {               float x_ = (float) (Math.sin(z * DEG_2_RAD) * 2 * PIXEL_X);               gl.glTexCoord2f(tile.left(), tile.bottom() + difY * (z - offZ) / 360);               gl.glVertex2f(l + o_, b + h_interval * (z - offZ) / 360); // bottom-left               gl.glTexCoord2f(tile.right(), tile.bottom() + difY * (z - offZ) / 360);               gl.glVertex2f(r + o_, b + h_interval * (z - offZ) / 360); // bottom-right               z += 30;               o_ = x_;               gl.glTexCoord2f(tile.right(), tile.bottom() + difY * (z - offZ) / 360);               gl.glVertex2f(r + x_, b + h_interval * (z - offZ) / 360); // top-right               gl.glTexCoord2f(tile.left(), tile.bottom() + difY * (z - offZ) / 360);               gl.glVertex2f(l + x_, b + h_interval * (z - offZ) / 360); // top-left            }`

(h_interval is the height of a tile, l is the left x coordinate of a tile, r is the right x coordinate of a tile, b is the bottom y coordinate of a tile, offZ is just a number i'm incrementing after each render, to make the effect move)

I'm trying to get a 'mirage' effect (tiles waving back and forth using sine. also i'm sure there's a way better way of doing this, if you know of it point it out)

edit: how do I get the smallest number of triangles (not reuse vertices) is my question I guess, in response to your edit
 7 Java Game APIs & Engines / OpenGL Development / Newbie Polygon Texturing Question on: 2012-12-28 04:44:16 When texturing a polygon, what order do I have to follow exactly? Say I have this polygonAnd I have a rectangular texture (of the same height, so the only thing changing is the x component)How do I achieve this? I have vertices 1-10, what order do I use them to texture the polygon?At the moment I'm breaking it up into quads and texturing those quads (using only a part of the texture) using these groups of vertices in this order:1, 2, 4, 33, 4, 6, 55, 6, 8, 7etc
 8 Discussions / Miscellaneous Topics / Re: Free "Source" Steam Game For you?! on: 2012-12-24 02:03:58 Can I get " ? ? ?"Reason I want that one is it seems like an interesting game and has me curious.I would like at least one present this year, which is why I want it I guess.
 9 Discussions / General Discussions / Re: Revenge of the Patent Trolls! on: 2012-12-21 04:33:29 Quote from: Roquen on 2012-07-25 11:27:15If you cannot patent anything mathematical, then all patents in all fields are disputable. Computational or algebraic is a different story.[quibble]Shouldn't physics and chemistry be swapped?[/quibble]And this is gonna get thrown out (for now) because they called it "Mindcraft" lol
 10 Java Game APIs & Engines / Java 2D / Re: quickest most effecient way to darken/lighten image on the fly? on: 2012-12-14 16:37:09 You could always draw a slightly transparent white (lighten) or black (darken) rectangle over a tile if the light is uniform
 11 Discussions / Miscellaneous Topics / Re: What music do you listen to while you code? on: 2012-11-27 22:55:10 HIPSTER MUSIC~http://www.youtube.com/watch?v=qDVW81bXo0s
12  Game Development / Newbie & Debugging Questions / Re: checking for variable type on: 2012-11-23 02:41:29
You can pass an Object as an argument and use the 'instanceof' keyword like:

 1  2 ` if (obj instanceof Window) {...`
 13 Game Development / Performance Tuning / Re: Trapezoid! on: 2012-11-23 01:57:58 Ugh. Would it be possible to have a 3D background and a 2D foreground if I switch to OpenGL? Time to look up tutorials.Thanks!
 14 Game Development / Performance Tuning / Re: Trapezoid! on: 2012-11-22 22:51:51 It seems that JAI has to be installed, that's why I don't want to use it.. Is there a version that you can just bundle with a project (with native libs)?
15  Game Development / Performance Tuning / Trapezoid! on: 2012-11-20 00:48:11
I was wondering if there are any fast algorithms out there for taking an image and morphing it into the shape of a trapezoid (trapezium).

I found this method:

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19 `   private final float A = W * 0.08f;   private final float B = W * (1f - 0.08f);   private final void createTrapezium(BufferedImage src, BufferedImage out) {      int[] pix = ((DataBufferInt) src.getRaster().getDataBuffer()).getData();      int[] pix2 = ((DataBufferInt) out.getRaster().getDataBuffer()).getData();      Arrays.fill(pix2, 0);      for (int y = 0; y < HEIGHT; y++) {         int yw = y * W;         float y_to_h = y / (float) HEIGHT;         float C_A_offset = A * (1 - y_to_h);         float trapeziumLine = -C_A_offset + B + (W - B) * y_to_h;         float k = trapeziumLine / W;         for (int x = 0; x < W; x++) {            int destX = (int) (C_A_offset + x * k);            pix2[yw + destX] = pix[yw + x];         }      }   }`

But it's pretty CPU intensive (using this in real-time for a changing background image at 30 FPS)... Is there an alternative to using JAI?
 16 Discussions / General Discussions / Re: Transparent Windows on: 2012-09-15 18:13:20 I did this a while back http://www.java-gaming.org/topics/transparent-jframe-background/24635/msg/208284/view.htmlThough granted, in my window I don't use the built in java components, but my own custom ones (using listeners, graphics and such)(PS I also used an undecorated window so I added my own dragging, and it's not totally smooth but good enough)
 17 Discussions / Miscellaneous Topics / Re: Who would you consider a programmer? on: 2012-08-06 10:42:03 Quote from: gimbal on 2012-08-06 10:22:41Little? You're too nice A programmer does not need to know how to make a compiler - a compiler developer needs to know that. A programmer needs to know how to USE a compiler.A programmer doesn't need to know how to make a networked game either. A 'hacker' does not need to know how to program at all... Most people would tell you that 'coder' and 'programmer' are the same thing and use them interchangeably.. I think he just threw 'scripter' in there for fun, first time I've heard that. Since if you're writing in a scripting language, you are still programming...He's a lot of off
 18 Games Center / WIP games, tools & toy projects / Re: [WIP] Metallum Miner (2D Mining game) on: 2012-08-03 21:35:47 You should give credit http://www.youtube.com/watch?v=7ReQMDRDe0s&feature=plcp
 19 Game Development / Artificial Intelligence / Re: A* with different sized units on: 2012-07-08 13:41:48 Well here is a graphical demo - completely unoptimized (didn't even merge clearances with node class, and new nodes are generated each time a path is found instead of saving them), possibly not even working properly, I don't feel like thinking for a while.http://www.java-gaming.org/?action=pastebin&id=143By default the unit size is 2x3Thanks again, feel free to point out any flaws, and you may tell me any suggestions for optimization (I already have a couple of ideas)
 20 Game Development / Artificial Intelligence / Re: A* with different sized units on: 2012-07-08 12:31:53 Quote from: UprightPath on 2012-07-07 23:50:27Fy, rom what's been said, I think I understand the problem (Yay!), but I still haven't actually read the page yet (I'm just responding/talking through my little phone while I try to make a section of my house wheel chair accessible.) Anyway, it seems that for an arbitary sized/shaped map (let's call it that, instead of infinite) that you have a few options.1) Recompute the clearrance when more areas becoming visible.2) Compute the clearance as soon as you can. However, this let's the path finder sort of "see beyond" the sight area of the creature when picking a route (the pathfinder gets the clearance values, which indicates open spaces, meaning it'll know where the creature can fit before it gets close enough to see.)3) Attempt to disable the clearance path finding through unseen areas. Not sure how to accurately do this though.4) Make a maximum limit on the clearance value of each tile (the smallest you can, and still fit your largest creature). Then, instead of recomputing each time you discover an area, you just mark a 'seen' flag, if it's seen, then you get it's actual clearnce values, if it's unseen you get it's unseen values (preferably either the maximum-- so that your path finder will assume that any sized creature can move through an unseen path-- or some arbitrary other value.) Still has the issue that the path finder can see a bit beyond the edges of the creature's vision (tiles on the edge of vision in certain directions with give information about what's further in that direction).If you give us some idea about what you're trying to do: how you're genetrating your map, whwther vision matters (sort of assuming from what you said), etc. We might be able to give you an answer to better suit your needs.Yes I just thought of #4 yesterday and all is going well. I'm just gonna finish making it work with rectangular units and all should be well.Thanks for pointing me in the right direction guys
 21 Game Development / Artificial Intelligence / Re: A* with different sized units on: 2012-07-07 15:14:47 problem is I have an 'infinite' map, is the only way to keep recalculating each time a new area has been discovered?Quote from: ReBirth on 2012-07-07 12:46:49Quote from: counterp on 2012-07-07 09:05:33I didn't quite understand how to set a clearance value for each tile for starters, (1, 2, 3, 4, 5, etc) so I thought looking at a java implementation would help@ReBirth not sure what you meantTreat a big tile as some small 1x1 tiles. You mean a 2x2 tile as 4 seperate 1x1 tiles? but how would that even work
 22 Game Development / Artificial Intelligence / Re: A* with different sized units on: 2012-07-07 09:05:33 I didn't quite understand how to set a clearance value for each tile for starters, (1, 2, 3, 4, 5, etc) so I thought looking at a java implementation would help@ReBirth not sure what you meant
 23 Game Development / Artificial Intelligence / A* with different sized units on: 2012-07-06 09:12:33 http://aigamedev.com/open/tutorial/clearance-based-pathfinding/Is there a java implementation of this, or any pathfinding that allows for different sized units instead of 1 per tile? A unit that takes up 4 tiles (2x2)? And the unit is not necessarily a square unit, they maybe rectangular for example taking up 2 tiles (1x2).I've got A* down, but I need to figure this out (more explanations also help)
24  Game Development / Newbie & Debugging Questions / Re: Getting a direction based on coordinate differences on: 2012-03-19 06:18:27
not the only way (not that it makes a difference)

 1  2  3  4  5  6  7 `private static final Direction[] directions = {     EAST, SOUTH, WEST, NORTH};public static final Direction get(int dx, int dy) {     return directions[dx & 2 | dy & 3];}`
 25 Discussions / Business and Project Discussions / Re: runescape private servers - looking for developer on: 2012-03-15 05:53:46 Quote from: nethious on 2012-03-15 05:51:09Quote from: GabrielBailey74 on 2012-03-15 04:54:32Dude, PLEASE do not bring Runescape to these forums..go to moparscape.org.*Cough* Delta.this is a java forum, private servers are written in java, I see no reason why I cant post this here.I'm doing rsps for profit, theres servers that make alot of money, and i want to get a piece of the pie.by the way, this is not delta.and also, moparscape is getting shut down.That's illegal
26  Discussions / Business and Project Discussions / Re: Can I have an Experience poll? on: 2012-03-01 22:23:14
 Name Time with Java Games Made Developed Ideas Not so developed ideas Learning Education Age In collaboration Need collaboration Mo (counterp) 6 years 1 that I've actually stuck with Many More than many Nothing in particular at the moment High school (no programming classes though?) 17 No one No
 27 Game Development / Newbie & Debugging Questions / Re: KeyEvent.KEY_TYPED on: 2012-02-29 20:17:40 Is there any particular reason why you're not using KeyListener (it behaves as what you stated), MouseListener, and MouseMotionListener?
28  Game Development / Newbie & Debugging Questions / Re: Java game - time on: 2012-02-18 21:39:52
 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20 `public boolean paused;public long pauseElapsed, pauseStarted;public void pause(boolean on) {   paused = on;   if (on) {      pauseStarted = System.currentTimeMillis();   } else {      pauseElapsed += System.currentTimeMillis() - pauseStarted;   }}...if (!paused) {   millis = System.currentTimeMillis() - startTime - pauseElapsed;   hours = millis / (1000 * 60 * 60);   millis -= hours * (1000 * 60 * 60);   minutes = millis / (1000 * 60);   millis -= minutes * (1000 * 60);   seconds = millis / 1000;}g.drawString("Time: " + hours + ":" + minutes + ":" + seconds, 300, 10);`
 29 Game Development / Newbie & Debugging Questions / Re: [Java: (Socket/ServerSocket) Question] on: 2012-02-14 17:58:51 you can't get the computer name via just establishing a connection
30  Game Development / Game Mechanics / Re: Networked bit of a client on: 2012-01-03 22:01:37
sounds a lot like my system cool

 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  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92 `public class Packets {   private static final int[] sizes = new int[256];   private static final Packet[] packets = new Packet[256];   static {      packets[187] = new AttemptLogin();      sizes[187] = -1;      packets[23] = new RemotePlayer();      sizes[23] = -1;      packets[112] = new DrawingAction();      sizes[112] = -1;      packets[83] = new ChatMessage();      sizes[83] = -1; // size can change, send it as a byte      packets[241] = new RegionRequest();      sizes[241] = -2; // size can change, send it as an int   }   public static Buffer fragment;   public static ISAAC decryptor;   public static void handle(Buffer buffer) { // read a chunk of data as a byte[] and pass it along to my custom Buffer class for easy reading      boolean decrypt = true;      if (fragment != null) {         buffer.insertStart(fragment.array());         fragment = null;         decrypt = false;      }      while (buffer.remaining() > 0) {         int opcode = buffer.getSigned();         if (decrypt) {            if (decryptor != null)               opcode -= decryptor.next();         } else {            decrypt = true;         }         opcode &= 0xFF;         int size = sizes[opcode];         Packet packet = packets[opcode];         if (packet == null) {            System.out.println("Non-existant packet: " + opcode);            return;         }         if (size == -1) {            if (buffer.remaining() > 0)               size = buffer.get();            else {               fragment = new Buffer(2).put(opcode);               buffer.clear();               System.out.println("Storing fragmented packet " + opcode + ".");               return;            }         } else if (size == -2) {            if (buffer.remaining() > 3)               size = buffer.getInt();            else {               fragment = new Buffer(2).put(opcode);               buffer.clear();               System.out.println("Storing fragmented packet " + opcode + ".");               return;            }         }         int remaining = buffer.remaining() - size;         if (remaining < 0) {            fragment = new Buffer().put(opcode);            if (sizes[opcode] == -2)               fragment.putInt(size);            else               fragment.put(size);            fragment.put(buffer.getBackingBuffer(), buffer.readPosition(), buffer.remaining());            buffer.clear();            System.out.println("Storing fragmented packet " + opcode + ", size " + fragment.writePosition() + ".");            return;         }         try {            packet.execute(buffer, opcode, size);         } catch (Exception e) {            e.printStackTrace();         }         if (buffer.remaining() != remaining) {            System.out.println(" Expected: " + remaining +", Actual: " + buffer.remaining());            buffer.skip(buffer.remaining() - remaining);         }      }   }}`
 Pages: [1] 2 3 ... 9

 Add your game by posting it in the WIP section, or publish it in Showcase. The first screenshot will be displayed as a thumbnail.
 cubemaster21 (34 views) 2013-05-17 21:29:12 alaslipknot (42 views) 2013-05-16 21:24:48 gouessej (72 views) 2013-05-16 00:53:38 gouessej (71 views) 2013-05-16 00:17:58 theagentd (79 views) 2013-05-15 15:01:13 theagentd (74 views) 2013-05-15 15:00:54 StreetDoggy (116 views) 2013-05-14 15:56:26 kutucuk (139 views) 2013-05-12 17:10:36 kutucuk (140 views) 2013-05-12 15:36:09 UnluckyDevil (147 views) 2013-05-12 05:09:57
 Complex number cookbookby Roquen2013-04-24 12:47:312D Dynamic Lightingby Oskuro2013-04-17 16:46:122D Dynamic Lightingby Oskuro2013-04-17 16:45:572D Dynamic Lightingby Oskuro2013-04-17 16:23:20Noise (bandpassed white)by Roquen2013-04-05 17:36:01Noise (bandpassed white)by Roquen2013-04-03 16:17:38Java Data structuresby Roquen2013-03-29 13:21:12Topic Requestby kutucuk2013-03-22 21:42:01
Page created in 0.426 seconds with 20 queries.