Gallivan

Members
  • Content count

    186
  • Joined

  • Last visited

Community Reputation

158 Neutral

About Gallivan

  • Rank
    Member
  1. EA Quality of Life Paper

    Does anyone have a link to the EA Quality of Life paper written by an (ex?)-programmer?
  2. ASCII Containers

    Point taken - I've probably been idolizing too many game mod readmes and too few game readmes.
  3. Good Dog Names?

    "Come, Quat."
  4. ASCII Containers

    Not code (or comments) persay, but read-me files. I don't mind trading off a little size for user experience.
  5. ASCII Containers

    I'm not a very creative guy, but when I write documentation I like to put the main headers in nice looking boxes. eg. ==================== = Useful Variables = ==================== Does anyone know of a place that has some pre-made ones? I've seen some really nice, faux-3D containers.
  6. I have the following two classes, one of which extends the other. Entity -> Food (I realize that food does not have anything specific at this point.) I keep receiving the message: Cannot Find Symbol - Constructor Entity()... import java.awt.*; import java.awt.image.*; import java.io.*; import javax.imageio.*; public class Entity { int x, y; // coordinates int width, height; int id; BufferedImage image1,image2; boolean isSelected = false; BufferedImage currentImage; public Entity( int setX, int setY, int setWidth, int setHeight, int entityCount ) { x = setX; y = setY; width = setWidth; height = setHeight; id = entityCount; } } import java.awt.*; import java.awt.image.*; import java.io.*; import javax.imageio.*; public class Food extends Entity { public Food() { super(); } }
  7. There's definitely a great theme going - hats off to all of you. I was a little confused about the gameplay though - do the roots collect water, how do I get the other flowers, what do ants do, etc?
  8. Quantum - Single/Multiplayer RTS

    It's a very fun game to play. My only problem was that once I started to get behind, there's very little you can do to catch up. Other then that, and once I figured out that each planet had limited resources, it was a blast.
  9. [java] Label on Frame?

    It turns out Glass_Knife has already solved this in the discussion of his article, "Active Rendering". I had been through it a few times but I must have passed it over as a tweak.
  10. [java] Label on Frame?

    Thanks for your help, but it still doesn't show...
  11. I'm trying to add a label to my frame, but it does not show up. I've indicated the problematic lines because my code is quite messy. GAME LOOP *lines 35-67 import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.Random; import java.awt.image.*; import java.io.*; import javax.imageio.*; public class GameLoop implements MouseListener { final int TICKSPERSECOND = 500; final int SKIPTICKS = 1000 / TICKSPERSECOND; final int MAXFRAMESKIP = 5; final long STARTTIME = System.currentTimeMillis(); boolean gameIsRunning = true; float interpolation; int gameState = 0; // 0 - Menu // 1 - Game // 2 - Editor int loops; int fps = 0; int frames = 0; long nextGameTick = GetTickCount(STARTTIME); long sleepTime = 0; Display gameDisplay; Scene gameScene; int currentTime = (int) System.currentTimeMillis(), lastTime = currentTime, totalTime = 0; public void main() { gameDisplay = new Display(gameScene, 1024, 768); gameDisplay.createMenu(); gameDisplay.createLabel(); while (gameIsRunning) { loops = 0; while (GetTickCount(STARTTIME) > nextGameTick && loops < MAXFRAMESKIP) { // *---------------------------------------------------------------* // || CODE TO BE PLACED IN THE WHILE LOOP || // || || // || 1. Input/Output || // || 2. UPDATE WORLD || BufferedImage img = null; try { img = ImageIO.read(new File("entity.jpg")); } catch (IOException e) { } lastTime = currentTime; currentTime = (int) System.currentTimeMillis(); totalTime += currentTime - lastTime; if ( totalTime > 0 ) { totalTime -= 1000; fps = frames; frames = 0; } ++frames; gameDisplay.clearBackBuffer(); // Random generator = new Random(); // for (int i = 0; i < 100; i++) // { // gameDisplay.setColor( generator.nextInt( 255 ), generator.nextInt( 255 ), generator.nextInt( 255 ) ); // gameDisplay.drawImage( img, generator.nextInt( 800 ) + 50, generator.nextInt( 800 ) + 50 ); // } gameDisplay.drawFPS( fps ); gameDisplay.blitFlip(); // || || // || || // || || // || || // *---------------------------------------------------------------* nextGameTick += SKIPTICKS; loops++; } interpolation = (float)(GetTickCount(STARTTIME) + SKIPTICKS - nextGameTick) / (float)(SKIPTICKS); // 2. DISPLAY WORLD // add interpolation to this later // --------------- } } // PRIVATE FUNCTIONS private long GetTickCount(long STARTTIME) { return System.currentTimeMillis() - STARTTIME; } // USER INPUT public void mousePressed(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) { int mouseX = e.getX(); int mouseY = e.getY(); // Testing the unit list bounds with the mouse click location. for (int i = 0; i < gameScene.entityCount; i++) { if ((mouseX < gameScene.entities[i].x + gameScene.entities[i].width) && (mouseX > gameScene.entities[i].x) && (mouseY < gameScene.entities[i].y + gameScene.entities[i].height+30) && (mouseY > gameScene.entities[i].y+30)) { // Switching unit's selected status. if (gameScene.entities[i].isSelected) { gameScene.entities[i].setImage(2); gameScene.entities[i].isSelected = false; } else if (!gameScene.entities[i].isSelected) { gameScene.entities[i].setImage(1); gameScene.entities[i].isSelected = true; } } } } else if (SwingUtilities.isRightMouseButton(e)) { gameScene.createEntity(e.getX(),e.getY()-30,100,100,"entity.jpg","entityselected.jpg"); } } public void mouseReleased(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mouseClicked(MouseEvent e) { } } DISPLAY *lines 24-53, 56-70, 92-96 import java.awt.*; import java.io.*; import javax.imageio.*; import javax.swing.*; import java.awt.image.*; import java.lang.*; public class Display { VolatileImage bi; BufferStrategy buffer; Canvas canvas; Color background; Graphics g; Graphics2D g2d; GraphicsConfiguration gc; GraphicsDevice gd; GraphicsEnvironment ge; int width, height; JFrame gameWindow; Scene gameScene; public Display( Scene scene, int w, int h ) { JPopupMenu.setDefaultLightWeightPopupEnabled( false ); width = w; height = h; gameScene = scene; gameWindow = new JFrame(); // Create the game window... gameWindow.setIgnoreRepaint( true ); gameWindow.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); // Create the painting canvas canvas = new Canvas(); canvas.setIgnoreRepaint( true ); canvas.setSize( width, height ); // Add the canvas to the game window... gameWindow.add(canvas); createMenu(); gameWindow.pack(); gameWindow.setVisible( true ); // Create the back buffer... canvas.createBufferStrategy( 2 ); buffer = canvas.getBufferStrategy(); // Get the graphic's configuration... GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); // Create off-screen drawing surface... bi = gc.createCompatibleVolatileImage( width, height ); // Create graphics objects... g = null; g2d = null; background = Color.WHITE; } // RENDERING -> public void blitFlip() { g = buffer.getDrawGraphics(); g.drawImage( bi, 0, 0, null ); if ( !buffer.contentsLost() ) buffer.show(); } public void clearBackBuffer() { if (bi.validate(gameWindow.getGraphicsConfiguration()) == VolatileImage.IMAGE_INCOMPATIBLE) { System.out.println("Recreating image"); bi = gc.createCompatibleVolatileImage(640, 480); } g2d = bi.createGraphics(); g2d.setColor( background ); g2d.fillRect( 0, 0, width, height ); } // <- RENDERING // DRAW -> public void drawFPS( int fps ) { g2d.setFont( new Font( "Courier New", Font.PLAIN, 15 ) ); g2d.setColor( Color.BLACK ); g2d.drawString( String.format( "FPS: %s", fps ), 20, 20 ); } public void drawImage( Image img, int x, int y) { g2d.drawImage( img, x, y, null ); } public void drawRect( int x, int y, int width, int height ) { g2d.fillRect( x, y, width, height ); } public void setColor( int r, int g, int b ) { g2d.setColor( new Color( r, g, b ) ); } // <- DRAW // GUI -> public void createLabel() { Label label = new Label("HI"); gameWindow.add(label); gameWindow.pack(); gameWindow.setVisible(true); } public void createMenu( ) { MenuBar menuBar = new MenuBar(); Menu menu = new Menu("File"); MenuItem menuItem = new MenuItem("New"); menu.add(menuItem); menuBar.add(menu); gameWindow.setMenuBar(menuBar); } public Panel createPanel() { Panel panel = new Panel(); gameWindow.add(panel); return panel; } // <- GUI /** private void drawEntities(Graphics g) { for (int i = 0; i <= gameScene.entityCount; i++) { if (gameScene.entities[i] != null) { if (gameScene.entities[i].isSelected) { g.drawImage(gameScene.entities[i].currentImage, gameScene.entities[i].x, gameScene.entities[i].y, null); } else if (!gameScene.entities[i].isSelected) { g.drawImage(gameScene.entities[i].currentImage, gameScene.entities[i].x, gameScene.entities[i].y, null); } } } } private void drawMap(Graphics g) { g.drawImage(gameScene.map.image,0,0,null); } **/ }
  12. I've never actually done this but I believe you can pop-up certain components on triggers. So on the click of your menu item you'd just use: popup.show(); I got this from: http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html //...where instance variables are declared: JPopupMenu popup; //...where the GUI is constructed: //Create the popup menu. popup = new JPopupMenu(); menuItem = new JMenuItem("A popup menu item"); menuItem.addActionListener(this); popup.add(menuItem); menuItem = new JMenuItem("Another popup menu item"); menuItem.addActionListener(this); popup.add(menuItem); //Add listener to components that can bring up popup menus. MouseListener popupListener = new PopupListener(); output.addMouseListener(popupListener); menuBar.addMouseListener(popupListener); ... class PopupListener extends MouseAdapter { public void mousePressed(MouseEvent e) { maybeShowPopup(e); } public void mouseReleased(MouseEvent e) { maybeShowPopup(e); } private void maybeShowPopup(MouseEvent e) { if (e.isPopupTrigger()) { popup.show(e.getComponent(), e.getX(), e.getY()); } } } It's probably off - let me know if it works out.
  13. [java] Mixing Swing and AWT

    It was an error with my menu declaration (although at first it was Swing incompatability). :) Thanks!
  14. [java] Mixing Swing and AWT

    http://img3.imageshack.us/img3/8536/menubarlc4.jpg That's what it looks like now. It places the grey menu bar up there, but it has no options (which I've created). I'm going to post my code up tomorrow when I can make it readable. I though I would throw a picture up in case someone had this occur before.