0 Members and 2 Guests are viewing this topic.
We're not banging rocks together here, we know how to put a body back together
public class CraftMine{ public static void main(String [] args) { Game g = new Game(); //make the game object g.run(); //run the game System.exit(0); //exit and close all threads when the game is ready to close (isRunning is set to false) }}
//this class does nothing but provide you with a blank window to fill in with your game objectsimport javax.swing.*;import java.awt.*;public class Game extends JFrame{ private boolean isPlaying = true; //fps settings private final int DEFAULT_FPS = 60; private int fps = DEFAULT_FPS; //window dimensions settings private int windowWidth = 640; private int windowHeight = 480; ///place any other global objects you may need below public static void main(String [] args) //ignore this { } public run() { boolean isPlaying = true; initialize(); //call the initialization logic while(isPlaying) { long startTime = System.currentTimeMillis(); update(); draw(); long endTime = System.currentTimeMillis(); //keep the framerate from going above the specified fps (default fps is 60) if((endTime - startTime) > (1000/fps)) { try {Thread.sleep((endTime - startTime) - (1000/fps));} catch (Exception e) {} } } } public void initialize() { setSize(windowWidth, windowHeight); //sets the screen dimensions //TODO: place initialization logic here! Set other JFrame settings as well } public void update() { //TODO: place update logic here! Include user input. To make the program //stop, simply set isRunning to false to make the while loop exit and consequently, the whole program } public void draw() { BufferedImage bb = new BufferedImage(windowWidth, windowHeight, BufferedImage.TYPE_INT_RGB); Graphics buffer = getGraphics(); //get the graphics object (from the JFrame) Graphics backbuffer = bb.getGraphics(); //get the graphics object (from the backbuffer buffered image "bb") //TODO: place drawing logic here! (draw all of your shapes to the backbuffer object. NOT the buffer object) //END DRAWING LOGIC buffer.drawImage(backbuffer, 0, 0, this); //draw the backbuffer to the screen //this is known as double buffering, and this prevents the screen from flickering while performing the draw method }}
I saved 100% on car insurance by switching to no car insurance
My dad likes weird songs. Title of 1: death to my hometown.Chorus of the other: god is great, beer is good, nd ppl r crazy!
Quote from: That Goalie Guy. on December 29, 2012, 07:34:22 pmMy dad likes weird songs. Title of 1: death to my hometown.Chorus of the other: god is great, beer is good, nd ppl r crazy!That song is not weird. I grew up listening to country and the songs have good meanings. Sure, most of them are about love, but that one is not. I know most of you are think that I am crazy for listening to country music, but "God is great, beer is good and people are crazy" :p
Is it the 31st yet.