Skip to content

Instantly share code, notes, and snippets.

@jake7864
jake7864 / Cords.java
Created August 22, 2012 11:44
a class similar to the Rectangle class but with a few modifications so that it can be the base class for an entity in a game
public class Cords
{
public static enum Dir {UP, DOWN, LEFT, RIGHT, STOP}
public static Dir dir;
protected double x, y, size;
public double getX(){return x;}
public double getY(){return y;}
public double getCenterX(){return x+size/2;}
public double getCenterY(){return y+size/2;}
public void increaseX(double num){x+=num;}
@jake7864
jake7864 / VideoGameStatClass.java
Created August 22, 2012 11:10
a stat bar object with 2 variables cur + max & it also as methods for handling those variables
public class Stat
{
private double cur = 0;
private double max = 0;
public Stat(int max)
{
this.max = max;
cur = max;
}
public void add(double num)
@jake7864
jake7864 / followAI.java
Created August 6, 2012 22:24
a game with two boxes and one follows the other.
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferStrategy;
import javax.swing.JFrame;
@jake7864
jake7864 / wanderGame.java
Created August 3, 2012 17:14
3rd version of my collision detection game now the other box randomly wanders also bounces off walls & the player
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferStrategy;
import java.util.Random;
import javax.swing.JFrame;
@jake7864
jake7864 / CollisionUpgrade.java
Created July 31, 2012 18:09
Upgrade to my collion detection game, you can not go outside the window + diagonal collisions works better
public class Game extends Canvas implements Runnable
{
static Thread t;
public int width = 500, height = 300, playerSize = 10;
public InputHandler input;
public Player player = new Player();
public Box box = new Box();
public static void main(String args[])
{
JFrame frame = new JFrame();
@jake7864
jake7864 / BasicGame.java
Created July 31, 2012 01:31
this is a barebones, stripped down video game snippet/demo with collision detection.
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferStrategy;
@jake7864
jake7864 / StopWatchV2.java
Created July 19, 2012 07:08
a little upgrade to my stop watch program, this stop watch is now an alarm
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
@jake7864
jake7864 / StopWatch.java
Created July 14, 2012 13:53
a small simple stop watch program, you specify a time and when started it will decrease the time by 1 a second
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
@jake7864
jake7864 / JOptionPaneExample.java
Created July 10, 2012 09:27 — forked from anonymous/JOptionPane Example
na Example of how to use the JOptionPane to make GUIs.
import javax.swing.JOptionPane;
/*
///-_-_- JOPTIONPANE TUTORIAL -_-_-\\\
Hello this is my very first programming tutorial, what is up, this is a tutorial on how to use JOptionPane!
up to now you have been using System.out.print() to output messages & you've been using java.util.Scanner
to receive input but now I'll tell you how to use JOptionPane's showMessageDialog() & showInputDialog() methods.
JOptionPane programs are little pop up windows that either have a dialog box that has a message and asks for input that is
the showInputDialog() the other is showMessageDialog, it is just a little message with a Icon if you want, both pop up window
types can have a title & both need to have null for the container usually like probably too early for you for me to talk about that.
JOptionPane Programs are a lot more easy to use and to work with than the console type programs you have made so far,