here it is.
Freeport Public Schools (FPS) does not control or endorse the content, messages or information found in this communications service and, therefore, disclaims any liability with regard to this service and any actions resulting from your participation in this service.
//package game1;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import java.math.*;
public class JFrame extends javax.swing.JFrame {
public Image Buffer;
public Graphics gBuffer;
boolean pressedLeft, pressedRight, pressedUp, pressedDown;
int mousex = 320,mousey = 432;
int projx,projy,num;
public String State= "!";
javax.swing.Timer t;
public JFrame() {
Image Buffer;
Graphics gBuffer;
javax.swing.Timer t;
initComponents();
Buffer=createImage(size().width,size().height);
gBuffer=Buffer.getGraphics();
t = new javax.swing.Timer(1,
new ActionListener() {
public void actionPerformed(ActionEvent e) {
update();
}
});
t.start();
this.pack();
// IceCicle[] IceCicles = new IceCicle[15];
int c = 0;
for(c = 1;c<15;c++){
//IceCicles[c].IceCicleX = 1;
// IceCicles[c].IceCicleY = 1;
//
}
}
public int[] _X = new int[15]; // x coord of rock
public int[] _Y = new int[15]; // y coord of rock
public int[] speed = new int[15]; // speed of rock
public int score = 0;
public int clr = 0;
public boolean Dead = false;
public void drawStuff()
{
if(Dead == true){
long N = System.currentTimeMillis();
while((System.currentTimeMillis()-N)<2000){
}
System.exit(0);
}
CreateRockS();
Buffer=createImage(size().width,size().height);
gBuffer=Buffer.getGraphics();
gBuffer.setColor(Color.blue);
gBuffer.fillRect(0,0,size().width,size().height);
gBuffer.setFont(new Font("Helvetica",Font.PLAIN,32));
gBuffer.setColor(Color.orange);
//if we want to use "" inside a string, we have to mask it with \!
UpdateRockS();
//gBuffer.drawString(""+IceCicles.length,10,70);
DrawPlayer(mousex,mousey);
TestCollision();
}
public void update() {
// Hmmm, is this the right way to do this? Or do we just
// call paintComponent? Does this coalesce calls, not that
// this updates often enuf for that to be important.
this.repaint();
}//end update
public void paint(Graphics g)
{
drawStuff();
g.drawImage (Buffer,0,0, this);
}
private void initComponents() {//GEN-BEGIN:initComponents
jPanel1 = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
formKeyPressed(evt);
}
});
addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseMoved(java.awt.event.MouseEvent evt) {
formMouseMoved(evt);
}
});
jPanel1.setBackground(new java.awt.Color(153, 153, 153));
jPanel1.setFocusCycleRoot(true);
jPanel1.setPreferredSize(new java.awt.Dimension(640, 480));
jPanel1.setAutoscrolls(true);
getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
pack();
}//GEN-END:initComponents
private void formMouseMoved(java.awt.event.MouseEvent evt)
{//GEN-FIRST:event_formMouseMoved
// TODO add your handling code here:
}//GEN-LAST:event_formMouseMoved
private void formKeyPressed(java.awt.event.KeyEvent evt)
{//GEN-FIRST:event_formKeyPressed
if(Dead==false){
// TODO add your handling code here:
int key = evt.getKeyCode();
if(key==evt.VK_LEFT){
mousex = moveLeft(mousex);
}
else
if(key==evt.VK_RIGHT){
mousex = moveRight(mousex);
}
if(mousey!=432){
mousey = 432;
}
}
}//GEN-LAST:event_formKeyPressed
public static void main(String args[]) {
new JFrame().show();
}
// public static void main(String[] args) {
//
// JFrame windo = new JFrame();
// windo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// windo.setVisible(true);
// }//end main
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel jPanel1;
// End of variables declaration//GEN-END:variables
// input: current pos, output: new pos that is within the screen
public int moveLeft(int pos)
{
pos-=32;
if(pos<32)
pos = 32;
return pos;
}
// input: current pos, output: new pos that is within the screen
public int moveRight(int pos)
{
pos+=32;
if(pos>608)
pos = 32;
return pos;
}
//moves all rocks down at their own speed
public void UpdateRockS()
{
for(int Count = 0;Count<15;Count++){
gBuffer.drawString("=",_X[Count],_Y[Count]);
gBuffer.drawString("Score: "+score,400,64);
}
}
//updates the score at 5pts for every rock dodged
public void UpdateScore()
{
}
//checks for an empty rock and hurls it down at a random speed
public void CreateRockS()
{
for(int Count=0;Count<15;Count++)
{
if(speed[Count]<8)
speed[Count] = 8;
_Y[Count] +=speed[Count];
if(_Y[Count]>496){
score+=5;
_Y[Count] = 32;
_X[Count] = Math.abs((int)(Math.random() * 608))-1;
_X[Count] = 32+(_X[Count]-(_X[Count]%32));
speed[Count] = ((int)(Math.random() * 8)+8);
}
}
}
//displays that you are hit and exits
public void Die(){
Dead = true;
gBuffer.fillRect(0,0,size().width,size().height);
gBuffer.setColor(Color.black);
gBuffer.drawString("You died!",180,240);
// gBuffer.setFont(new Font("Helvetica",Font.PLAIN,32));
gBuffer.drawString("Score: "+score,140,320);
gBuffer.drawString("Ethan and Joseph Say: ",140,370);
String Str = "....";
if(score<1000){
Str = "You Suck!";
}
else
if(score>1000&&score<1500){
Str = "You're getting there";
}
else
if(score>1500&&score<3000){
Str = "Oh Yeah!";
}
else
if(score>3000&&score<5000){
Str = "You DA man!!!!!";
}
else
if(score>10000){
Str = "YOUR ON FIRE!!!!!!!!!!!";
}
gBuffer.drawString(Str,140,420);
}
//draws the ascii player at x,y
public void DrawPlayer(int X,int Y)
{
gBuffer.drawString("O",X-3,Y);
gBuffer.drawString("--|--",X-16,Y+32);
gBuffer.drawString("/\\",X,Y+64);
}
// goes to the die method as soon as a rock hits the player
public void TestCollision()
{
for(int Count = 0;Count<15;Count++){
if((Math.abs(mousex-_X[Count])<32)&&(Math.abs(mousey-_Y[Count]))<32){
gBuffer.setFont(new Font("Helvetica",Font.PLAIN,32));
gBuffer.setColor(Color.red);
Die();
}
}
}
}