Show Posts
|
|
Pages: [1]
|
|
3
|
Game Development / Newbie & Debugging Questions / Moving along odd angles
|
on: 2005-01-07 21: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 16:15:25
|
Actually, "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.
|
|
|
|
|
6
|
Game Development / Newbie & Debugging Questions / Re: Peg Solitaire
|
on: 2005-01-06 20: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 10 2=Canada 23 69 3=United_States 23 30
[borders] border1 = 7 2 5 border2 = 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.
|
|
|
|
|
8
|
Game Development / Newbie & Debugging Questions / Re: copying a (BSP) tree into an array?
|
on: 2004-12-15 19:04:03
|
is 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 22: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.*;
public 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(); }
|
|
|
|
|
10
|
Game Development / Newbie & Debugging Questions / Re: Best practice when dealing with cards?
|
on: 2004-12-10 19:27:06
|
|
No problem. I usually suck at descriptions. - I had a class called ADConstants where I was defining card properties but I deleted that last night. And went to using a text file.
Ok, Card is an object. That has the following properties. - label - image - name - type - cost to play - event triggered
These properties are stored in a txt file that is read into a 2 dimensional array. With all the card properties.
I have a class called deck. Which will read the text file and load a deck, creating an array of card objects.
After this the system retrieves the array of card IDs stored somewhere (JDBC most likely, but currently just on the client side). Its is just an array of ints which refrence the IDs of the master array of card objects.
So deck object has an array of card objects (100 so far). And the player as an aray of integers, which when called to be displayed. They fetch the card data, the total cards a player can have showing on screen is 4.
So player 1 is dealt 4 cards.
Card size is 145x200 and is a PNG file. So to display the card I have to load the image.
So my question is which is a better design to follow. I create the PNG of the card with all the following displayed as part of the card. - name - type - flavor text - cost to play - what it does (event triggered) - main image * Downside If I change anything I need to recreate the card *Upside Quicker to create Easier to manage Less images to load, most likely quicker performance
What I have then is a PNG that is 145x200 and holds all the card info.
Or I do the following: - Card Template is a blank PNG of a card with no name or image or any text at all on it. I create a PNG of the cards main image. I then keep loaded all the time my card template. I know exactly where the card will be placed. So I add labels: - lblNameC1, where the name would be on the template - lblCostC1, where the cost appears And so on. So I paint down the template then load the JLabels And I just load the cards main image over top where I need it on the template. When I'm done with that card I clear the labels and load the next cards values into them. *Downside 1 more image loading into memmory more processing time setting all the labels. I can cash the image, but will have to reload labels if the same card comes up Have to come up with a way to store the flavor text of the card in some kind of easy to manage reader. *Upside Quicker to add more cards, since I just have to create small simple images. Any change in the text file and it will auto reflect to the player with no need for a whole new card PNG
I can also email you a picture of a card if that will help you understand a little better, I bet its hard to imagine.
After writing it out a little better, the last option is looking better, but I'm not sure how much performance it will cost me using the labels and loading and displaying 2 images. The set up of the labels will be a pain in the ass as well.
My last question is, should I keep the card images loaded in memmory until the end of the game. So if anyone else plays the same card it loads the image quicker. Or should I dispose of it after is been played and thrown out. - Players could have 20 of the same card (in theory)
|
|
|
|
|
11
|
Game Development / Newbie & Debugging Questions / Best practice when dealing with cards?
|
on: 2004-12-09 15: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 up And way 2 - The new way described above
To 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 21:38:49
|
Add this method. 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.
|
|
|
|
|
14
|
Game Development / Newbie & Debugging Questions / Problem with panning and scrolling
|
on: 2004-12-07 20: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.
|
|
|
|
|
16
|
Game Development / Newbie & Debugging Questions / Re: Creating a text image on the fly?
|
on: 2004-12-03 21: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
| 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;
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) { Rectangle2D rect = g.getFontMetrics().getStringBounds(message, g); int imageW = (int)(rect.getWidth() - rect.getX() + 2); int imageH = (int)(rect.getHeight() - rect.getY()); int descent = (int)(g.getFontMetrics().getDescent() + .5f); GraphicsConfiguration gc = g.getDeviceConfiguration(); intermediateImage = gc.createCompatibleImage(imageW, imageH, Transparency.BITMASK); 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; } 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<messages.size(); i++){ fm = (FloatingMessage)messages.get(i); fm.paintComponent(g); } }
public void updateFloatingMessages(){ FloatingMessage fm; for(int i=0; i<messages.size(); i++){ fm = (FloatingMessage)messages.get(i); if(fm.isMarkedForRemoval()){ messages.remove(i); } fm.move(); } } |
|
|
|
|
|
19
|
Game Development / Newbie & Debugging Questions / Re: Creating a text image on the fly?
|
on: 2004-12-02 21: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
| 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; } 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 20: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<messages.size(); i++){ fm = (FloatingMessage)messages.get(i); Graphics2D g = (Graphics2D)strategy.getDrawGraphics(); g.setColor(Color.RED); g.setFont(new Font("Arial",Font.BOLD,8)); g.drawString(fm.getMessage(),fm.getX(),fm.getX()); } }
public void updateFloatingMessages(){ FloatingMessage fm; for(int i=0; i<messages.size(); i++){ fm = (FloatingMessage)messages.get(i); if(fm.isMarkedForRemoval()){ messages.remove(i); } fm.move(); } } |
|
|
|
|
|
22
|
Game Development / Newbie & Debugging Questions / Creating a text image on the fly?
|
on: 2004-12-02 19: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 04: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.
|
|
|
|
|
25
|
Game Development / Newbie & Debugging Questions / LWJGL - Can't find imports
|
on: 2004-11-21 00:33:15
|
|
I'm using LWJGL 0.93 alpha and I cant find these 2 imports in the jar files. org.lwjgl.Display org.lwjgl.opengl.window
Both seem to be non existant, I've imported these external jars into Eclipse: "lwjgl.jar" "lwjgl_media.jar" "lwjgl_util.jar"
Any suggestions?
|
|
|
|
|
27
|
Java Game APIs & Engines / Java 3D / Re: Early first results from JNWN
|
on: 2004-11-18 16: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 15: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.
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|