Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (595) Games in Android Showcase (168) games submitted by our members Games in WIP (646) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
 Show Posts Pages: [1]
 1 Game Development / Newbie & Debugging Questions / Re: Moving along odd angles on: 2005-01-07 21:47:59 Looks good, I'll plug it in when I get home and try it out.
 2 Game Development / Newbie & Debugging Questions / Re: Moving along odd angles on: 2005-01-07 20:57:03 Actually thats pretty ugly.  It moves at an angle depending on the x and y.  Then it may move in a straight line to get to the bigger point.\ \  \   \ _ _ _So it works but is crap.  So whats the proper way to do this?
3  Game Development / Newbie & Debugging Questions / Moving along odd angles on: 2005-01-07 20:53:10
Ok currently I have a game piece object at position 1,1 and I move it to position 5,4.  Its just a simple repaint from there to here.

But in my move() call I want to animate the piece sliding on the board.  I already do simple move calls to float text or move a card in straight lines.  But its always only on one axis, either x or y.

And the moving of a game piece can be at any odd angle. So what type of equation should I be looking to use to figure out my where to redraw the gamepiece as it slides along the board.

I current brain storm was something like this.
 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 `void setDestination(int destX, int destY) {      this.destX = destX;      this.destY = destY;            if(currentX < destX){            moveX = 1;      }else{            moveX = -1;      }            if(currentY < destY){            moveY = 1;      }else{            moveY = -1;      }            moving = true;}void move() {            if(moving == false) return;            if(currentX != destX)            currentX += moveX;            if(currentY != destY)            currentY += moveY;            if(currentX == destX && currentY == destY)            moving = false;}`

Is there a better way to do this?
 4 Game Development / Newbie & Debugging Questions / Re: Peg Solitaire on: 2005-01-07 15:15:25 QuoteActually, "RISK" like games is exactly what I want to develop, once I get basic knowledge.Do you have some "real" examples to show? I really like your idea with the .ini file. I have some custom classes and such.  Allot to post, but I'll be putting the project on Source Forge soon.  So you'll be able to look at the source there.  I'll add a link in my signature when I create the project on source forge. So just keep an eye open.
 5 Game Development / Newbie & Debugging Questions / Re: Simple Mouse Question on: 2005-01-06 19:23:04 Hi Jeff, I created a Risk style game as well.   I used the following method to define maps.  I currently have 4 different maps.  It takes some time to set up.  But there is not large amount of RAM used or long access times.  I currently get 54 fps.http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=cluebies;action=display;num=1105044939But since I assume its turn based, as another dev mentioned to me in another post.  You may want to look at re-active renderring rather then active renderring for a risk game.  So far I'm using active, but I may change that soon, but so far so good my renderring seems ok.Actually I would really like to port the project over to LWJGL.  And try the same thing with maybe a 3D map.
6  Game Development / Newbie & Debugging Questions / Re: Peg Solitaire on: 2005-01-06 19:04:06
And if you ever get into using wierd shapes, like a Risk board style.  I found it fast enough to create a ini file that listed all the areas.

 1  2  3  4  5  6  7  8 `[areas]1=Brazil 12 102=Canada 23 693=United_States 23 30[borders]border1 = 7 2 5border2 = 9 10 3 12`

I use built in java ini reader and a string tokenizer.

The first part holds the area names ( under scores _ = spaces), then follows the x and y for the pieces.

The second part holds all your borders.  I found setting up this ini file I could create a board game with some really wierd shaped areas.  Works well for games that require a risk look and feel.

I would like to develop a map maker to create the ini file, but havent got around to it yet.

The coolest thing I found, another developer showed me.  Was to take the origenal PNG and create a grayscale GIF of the image.  The player always sees the hi res color PNG.  The GIF is just for processing background things.

Then take area 1 Brazil and make the RBG 1,1,1

Canada would be RBG 2,2,2 and so on.

Thus you can take the GIF image and any x y coordiante and figure out where you are from the RBG value.  This also allows you to highlight areas by changing the RBG value to a real color like RED on the file then displaying a sub image, thus it looks like your highlighting the area.  Works good for mouse clicks.

I'm still working on the highlighting part though.
 7 Game Development / Newbie & Debugging Questions / Re: simple boardgames on: 2005-01-05 20:11:31 QuoteI found a thread somewhere with a nice example.  Mind posting the link.  I would like to give it a read. Thanks
 8 Game Development / Newbie & Debugging Questions / Re: copying a (BSP) tree into an array? on: 2004-12-15 18:04:03 Quoteis there a efficient way to copy a Node & it's children into a 'orderly' arranged array right now i have a left and right child and eventually i want an int that's point into a global 'nodes' array for it's left and right sibbling.You can use a 2 dimensional array maybe.int[a]All the parents in array (a) and the children in (b).
9  Game Development / Newbie & Debugging Questions / Re: Best practice when dealing with cards? on: 2004-12-10 21:48:05
Yea 2 was sounding better and better. Thanks.

Now when you drawstring.  Would you bother creating that as a bufferedimage.  We dicussed this in another topic.  But these could be changing very often or the player may hold the same card for 40 minutes no one knows.

So to speed up rendering I would want to make them a compatible image.  But is it worth the CPU time to create these images, or should I just keep calling drawstring.

And another question if I may, the flavor text area is 100x75.  How can I ensure the text wraps when it reaches the end of the limit using drawstring?  I can ensure the text doesnt exceed x amount of characters.  That would make it to big to fit in a 100x75 box.  But can you force the text to wrap?

So far all my uses of draw string its been to say short little things that I always knew would fit.

I did find this on the net which looks like it will work, but if there is an easier way.  I always like to hear about those.
 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 `import java.util.Enumeration;import java.util.NoSuchElementException;import javax.microedition.lcdui.*;//www.astrientlabs.compublic class LineEnumeration implements Enumeration{private Font font;private String text;private int width;private int position;private int length;private int start = 0;public LineEnumeration(Font font, String text, int width){this.font = font;this.text = text;this.width = width;this.length = text.length();}public boolean hasMoreElements(){return (position < (length-1));}public Object nextElement() throws NoSuchElementException{try{return text.substring(start,(start = next()));}catch ( IndexOutOfBoundsException e ){throw new NoSuchElementException(e.getMessage());}catch ( Exception e ){throw new NoSuchElementException(e.getMessage());}}private int next(){ int i = position; int lastBreak = -1;for ( ;i < length && font.stringWidth(text.substring(position,i)) <= width; i++ ){if ( text.charAt(i) == ' ' ){lastBreak = i;}else if ( text.charAt(i) == '\n' ){lastBreak = i;break;} }if ( i == length ){position = i;}else if ( lastBreak <= position ){position = i;}else{position = lastBreak;}return position;}}`

Usage Example:

LineEnumeration e = new LineEnumeration(myFont,myText,lineWidth);
while ( e.hasMoreElements() )
{
g.drawString(e.nextElement().toString(), startX,startY, Graphics.TOP | Graphics.LEFT);
startY += myFont.getHeight();
}
 11 Game Development / Newbie & Debugging Questions / Best practice when dealing with cards? on: 2004-12-09 14:53:00 Ok I have a set of cards for my current game.  The best example would be a card from Magic the Gathering as an example.The cards all have the same layout.  The size is the size of a playing card, top area is a picture, bottom area text.There are currently 100 cards in a deck.  The player plays with 5 at a time.So on the HUD I display the 5 cards and a deck.Currently the HUD and the static deck are 2 images.  Which I think I should combine into one to lessen load on the system.So that leaves me with 5 cards to display.  Currently I have a template card.  And I load the small image into it, to create a new card image that I store.  Then when I display the card, it always goes to 1 of 5 spots.  These spots have labels drawn on them.  And when the card appears it loads the proper text into the label.I have a class that holds all the card consts, - ID- the pic it needs and - the text it displays- ID of event triggered (used in switch statement)Seemed like a good idea at the time.After thinking about this for the last 2 days.  I'm think I did this the wrong way.  I should have instead created 100 unique cards.  And changed my const class.- ID- Card PNG- ID of event triggered (used in switch statement)So assuming we have way 1- The way I have it currently set upAnd way 2- The new way described aboveTo lessen load on the system.  I guess I should refactorit to work off way 2.  What are other peoples thoughts on the matter?
12  Game Development / Newbie & Debugging Questions / Re: Problem with FPS Counter on: 2004-12-07 20:38:49
 1  2  3  4  5  6  7  8  9 `    public void paintFps(Graphics2D g) {          g.setFont( new Font("Arial",Font.BOLD,12));          g.setColor(Color.white);          if (usedTime > 0){              g.drawString(String.valueOf(1000000000/usedTime)+" fps",screenWidth-50,screenHeight-10);          }else{              g.drawString("--- fps",screenWidth-50,screenHeight-10);          }    }`

Then do what oNyx suggested.
long startTime = System.nanoTime();

usedTime = System.nanoTime()-startTime;

usedTime is a private global.

Call paintFps in your render loop.

Then follow Grazer's instructions, the componets should have all the setIgnoreRepaint(true);

And you should use a custom render loop.
 13 Game Development / Newbie & Debugging Questions / Re: Problem with panning and scrolling on: 2004-12-07 19:52:24 Nevermind, I had to reverse my X and Y.  They were counting up when they should count down and vice versa.
14  Game Development / Newbie & Debugging Questions / Problem with panning and scrolling on: 2004-12-07 19:40:48
Ok game one I created a top down view scoller.  And just incremented my Y and used
drawImage(Image img,
int dx1,
int dy1,
int dx2,
int dy2,
int sx1,
int sy1,
int sx2,
int sy2,
ImageObserver observer)

Works fine.

So for game 2 I create a top down view game.  That the user can scroll.  Seemed simple enough.

What I have:
Screen 640x480
Image 1024x780 (variable background)
Viewable area 640x300
edgeX - tracks panning.
edgeY - tracks panning.

I create my fullscreen frame, I draw the image of my level.  It only show the top left corner. Cool

So I add a JPanel of that size of the Viewable area to the frame, then add a mouse listener.

Now I create a function to track if the mouse is on the edge of the panel borders.  If true I increase/decrease the X or Y.  As long as its within the limits of the source.
This all works lovely.

Problem I encounter is when I scroll it just scrolls around within the limits but the new viewbla area is black (background color).  The image is not staying anchored.

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22 `public void render(){    if(!strategy.contentsLost())    {        Graphics2D g = (Graphics2D) strategy.getDrawGraphics();               g.setColor(Color.BLACK);        g.fillRect(0,0,screenWidth, screenHeight);                g.drawImage(background,      0,0,screenWidth,screenHeight,      edgeX,edgeY,      edgeX+screenWidth,edgeY+screenHeight,                window);                          g.setColor(Color.BLUE);        g.fillRect(hudX,hudY,hudWidth, hudHeight);                          paintStatus(g);                      strategy.show();        g.dispose();    }}`

Am I using the wrong call to draw the image.  Should I be creating a subimage of background and drawing that?

Assuming you had the X and Y what would you do.  I want to show a 640x300 area of the image called background (var name).  Starting at edgeX and edgeY.
 15 Game Development / Newbie & Debugging Questions / Re: Creating new panels in Exclusive Mode? on: 2004-12-07 18:55:16 Thanks, yep thats working.  Got the HUD working.  Now I just need to design a better looking gif to overlay. Thanks.
16  Game Development / Newbie & Debugging Questions / Re: Creating a text image on the fly? on: 2004-12-03 20:20:51
This works real nice, and the framerate is better as well.

 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  93  94  95  96  97  98  99  100  101  102  103  104  105  106  107  108  109  110  111  112 `/* * Created on Dec 2, 2004 * */package game;import java.awt.AlphaComposite;import java.awt.Color;import java.awt.Font;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.GraphicsConfiguration;import java.awt.Image;import java.awt.Transparency;import java.awt.geom.Rectangle2D;/** * @author Jeremy * */public class FloatingMessage {    protected String message;    protected int x;    protected int y;    protected int vY = -3;    protected boolean markedForRemoval = false;    protected Image intermediateImage;    protected static Font font = new Font("Arial",Font.BOLD,11);        public FloatingMessage(String m, int x, int y){        message = m;        this.x = x;        this.y = y;    }    public void paintComponent(Graphics2D g) {        if (intermediateImage == null) {            // First, measure the size of the text            Rectangle2D rect = g.getFontMetrics().getStringBounds(message, g);            int imageW = (int)(rect.getWidth() - rect.getX() + 2);            int imageH = (int)(rect.getHeight() - rect.getY());            // We must also account for text "descent" in determining where to draw string in image            int descent = (int)(g.getFontMetrics().getDescent() + .5f);            // Now, create the intermediate image            GraphicsConfiguration gc = g.getDeviceConfiguration();            intermediateImage = gc.createCompatibleImage(imageW, imageH, Transparency.BITMASK);            // And render the transparent background and the text into the image            Graphics2D gImg = (Graphics2D)intermediateImage.getGraphics();            gImg.setComposite(AlphaComposite.Src);            gImg.setColor(new Color(0,0,0,0));            gImg.fillRect(0, 0, imageW, imageH);            renderText(gImg, 0, imageH - descent);            gImg.dispose();        }        g.drawImage(intermediateImage, x, y,null);    }        public void renderText(Graphics g, int x, int y) {        g.setColor(Color.WHITE);        g.setFont(font);        g.drawString(message, x, y);    }        public static void createFloatingMessage(Stage stage, String m, int x, int y){        FloatingMessage fm = new FloatingMessage(m,x,y);        stage.addFloatingMessage(fm);    }        public void setMessage(String m){        message = m;    }        public String getMessage(){        return message;    }        public void setX(int i){        x = i;    }        public int getX(){        return x;    }        public void setY(int i){        y = i;    }        public int getY(){        return y;    }        /**     * Am I going to be deleted?     * @return true or false     */    public boolean isMarkedForRemoval(){       return markedForRemoval;        }        public void move(){        y+=vY;                if(y < 0){            remove();        }    }        public void remove(){        markedForRemoval = true;    }}`

In my main class I just call these subroutines when I need them.

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20 `public void paintFloatingMessages(Graphics2D g){    FloatingMessage fm;        for(int i=0; i
 17 Game Development / Newbie & Debugging Questions / Re: Creating a text image on the fly? on: 2004-12-03 18:03:33 Thanks for the info all.Good read grlea, thanks.Another article for those interested.http://java.sun.com/developer/technicalArticles/Media/intimages/
 18 Game Development / Newbie & Debugging Questions / Re: Creating a text image on the fly? on: 2004-12-02 20:55:23 DOH!Found the error, I pasted above there.g.drawString( fm.getMessage(), fm.getX(), fm.getX() )Passed in getX where it should have been my getY.
19  Game Development / Newbie & Debugging Questions / Re: Creating a text image on the fly? on: 2004-12-02 20:12:40
Yea thats all in the FloatingMessage class

 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 `/* * Created on Dec 2, 2004 * */package game;public class FloatingMessage {    protected String message;    protected int x;    protected int y;    protected int vY = -3;    protected boolean markedForRemoval;        public FloatingMessage(String m, int x, int y){        message = m;        this.x = x;        this.y = y;    }    public FloatingMessage(){        message = null;        this.x = 0;        this.y = 0;    }        public static void createFloatingMessage(Stage stage, String m, int x, int y){        FloatingMessage fm = new FloatingMessage(m,x,y);        stage.addFloatingMessage(fm);    }        public void setMessage(String m){        message = m;    }        public String getMessage(){        return message;    }        public void setX(int i){        x = i;    }        public int getX(){        return x;    }        public void setY(int i){        y = i;    }        public int getY(){        return y;    }        /**     * Am I going to be deleted?     * @return true or false     */    public boolean isMarkedForRemoval(){       return markedForRemoval;        }        public void move(){        y+=vY;                if(y < 0){            remove();        }    }        public void remove(){        markedForRemoval = true;    }}`

The only problem is the Y position is sometimes where I think it should be, but sometimes its way way off like right on my head, when it should be at like y 100, on a 800x600 screen.

I can't seem to figure out why that is.  I can't step through in eclipse because the window is blank, so its hard to tell.
20  Game Development / Newbie & Debugging Questions / Re: Creating a text image on the fly? on: 2004-12-02 19:08:29
For anyone else wonderring, create a class called FloatingMessage with a string, x and a y value.  Then used these methods.

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23 `    public void paintFloatingMessages(){        FloatingMessage fm;                for(int i=0; i
 21 Game Development / Newbie & Debugging Questions / Re: Creating a text image on the fly? on: 2004-12-02 18:18:45 Yea thanks, hit me to after I went and grabbed a sandwich.Add the text grapics to a HashMap and just manage them in there.  Thanks.yea just creating a method called updateFloatingMessages()That will cycle and handle it all.  Thanks.
22  Game Development / Newbie & Debugging Questions / Creating a text image on the fly? on: 2004-12-02 18:02:05
I can currently paint strings no problem using.
 1  2  3  4 `Graphics2D g = (Graphics2D)strategy.getDrawGraphics();g.setColor(Color.RED);g.setFont(new Font("Arial",Font.BOLD,8));g.drawString("BooM",x,y);`

That easy, but now I want to create an Image, that is text.  Like a score, kill monster a score value appears and floats upwards.

The acting and all that I got no problem, but I can't seem to figure out how to create a dynamic text image.  Since I don't want to create a gif for each score value.  I'd rather just create it on the fly.

So the question is:
Is this possible to do?
Which class should I use?

I assume I should be able to create it as a Graphics2D and some how change that graphic into a new image.
 23 Game Development / Newbie & Debugging Questions / Creating new panels in Exclusive Mode? on: 2004-12-02 03:46:35 I have an app running in full screen mode.  Now I want an area along the bottom for player info.  How do you go about creating some kind of panel that will float above the screen.The main playing area is a 1024x1024 board.  Think risk, like an area at the base of the screen, that will show your current cards.  Any pointers to howto's would be great thanks.If you check out Wurm you'll see that have little tabs at the bottom of there window.
 24 Game Development / Newbie & Debugging Questions / Re: LWJGL - Can't find imports on: 2004-11-21 17:31:24 Yea that was it, one of my options was to choose org.lwjgl.opengl.display just wanted to make sure.  That fixed it mostly, every where in the code that said window I just changed it to display as well.  And it all seems to be working. Thanks.
 25 Game Development / Newbie & Debugging Questions / LWJGL - Can't find imports on: 2004-11-20 23:33:15 I'm using LWJGL 0.93 alpha and I cant find these 2 imports in the jar files.org.lwjgl.Displayorg.lwjgl.opengl.windowBoth seem to be non existant, I've imported these external jars into Eclipse:"lwjgl.jar" "lwjgl_media.jar" "lwjgl_util.jar"Any suggestions?
 26 Game Development / Newbie & Debugging Questions / Re: Greetings on: 2004-11-18 16:16:11 Well found my answer on where to start:http://www.gamedev.net/reference/design/features/makegames/Looks like Tetris
 27 Java Game APIs & Engines / Java 3D / Re: Early first results from JNWN on: 2004-11-18 15:02:00 Hey Jeff I just came from the NWN Development arena.  Let me know if you need some info about things.  My expertise was in creating HAKs.   Mostly new creatures and textures, but I have allot of 2da knowledge.   The render looks good so far. Not looking to join a project but hopefully I can save you some time and answer some questions.
 28 Game Development / Newbie & Debugging Questions / Greetings on: 2004-11-18 14:54:38 Well hello all.  I'm not new to JAVA Dev.   But I'm new to game programming.  I've done allot of toolset work with the current commerical games.  Hopefully I'll catch on quick. I've read Practical Java Game programming and I'm waiting for Advanced Java Game Programming in the mail.  I've been lucky enough to chat with a few of you off line as well.  So hello and I hope to contribute some usefull info in the future.I'll be starting with a turn based board game.  So it looks like chess will be my starting project.  I want to shoot for a 2D board game with 3D pieces.  Am I starting off to quick? (Running before I can walk)Assuming no AI and using a UDP connection to play online.  Would this project be a bad place to start learning?  I've read the Asteroids 101 and key listeners and all that I use all the time in App programming.Just want to make sure I dont shoot myself in the foot jumping into 3D right away.  Since I have no 3D experience. Anyways hope to chat more as I learn a little more.
 Pages: [1]
 Riven (22 views) 2015-07-03 11:22:16 deepthought (47 views) 2015-06-30 15:39:44 deepthought (49 views) 2015-06-30 15:39:09 deepthought (62 views) 2015-06-30 15:36:52 Za\'Anzabar (34 views) 2015-06-29 05:44:54 TritonDreyja (45 views) 2015-06-24 17:10:40 CopyableCougar4 (44 views) 2015-06-23 00:34:45 BurntPizza (50 views) 2015-06-21 20:36:46 cookiecompiler (91 views) 2015-06-11 15:42:53 cookiecompiler (54 views) 2015-06-11 15:41:14
 princec 30x wessles 22x BurntPizza 19x CopyableCougar4 19x opiop65 17x Riven 15x nsigma 15x EgonOlsen 14x ags1 13x theagentd 12x KaiHH 12x SauronWatchesYou 11x KevinWorkman 11x Archive 11x sunburn 11x NegativeZero 10x
 How Do I Expand My Game?by bashfrog2015-06-14 11:34:43List of Learning Resources2015-05-31 05:37:30Intersection Methodsby Roquen2015-05-29 08:19:33List of Learning Resources2015-05-05 10:20:32How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14
 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