Friday, January 7, 2011

Obstacle V.001

// This is the source code for the Obstacle game located here.

import java.applet.*;
import java.awt.event.*;
import java.awt.*;

public class Obstacle001 extends Applet implements Runnable, KeyListener {

int width, height;
Thread t = null;
boolean threadSuspended;
int recWidth, recHeight, recXLoc, recYLoc, i;
int ovaWidth, ovaHeight, j;


public void init() {
width = getSize().width;
height = getSize().height;
recWidth = width / 3;
recHeight = height / 7;
recXLoc = (2 * width / 3) + (recWidth);
recYLoc = height / 2;
ovaWidth = 40;
ovaHeight = 40;
i = recXLoc;
j = 20;
setBackground( Color.black );
addKeyListener(this);
}


public void destroy() {

}


public void start() {
if ( t == null ) {
t = new Thread( this );
threadSuspended = false;
t.start();
}
else {
if ( threadSuspended ) {
threadSuspended = false;
synchronized( this ) {
notify();
}
}
}
}


public void stop() {
threadSuspended = true;
}


public void run() {
try {
while (true) {
--i;
if ( i == -(recWidth) ) {
i = recXLoc;
}
if ( threadSuspended ) {
synchronized( this ) {
while ( threadSuspended ) {
wait();
}
}
}
repaint();
t.sleep( 8 );
}
}
catch (InterruptedException e) { }
}

public void keyTyped(KeyEvent txt) {
char key = txt.getKeyChar();

if (key == 'w') {
j = j - 12;
repaint();
txt.consume();
} else {
j = j + 12;
repaint();
txt.consume();
}

}
public void keyPressed(KeyEvent txt) {

}
public void keyReleased(KeyEvent txt) {

}


public void paint( Graphics g ) {
g.setColor( Color.white );
g.fillRect(i, recYLoc, recWidth, recHeight);
g.setColor( Color.white);
g.fillOval(50, j, ovaWidth, ovaHeight);
}
}




============================================================================

Things I want to add / improve for V.002:

1) make the circle a triangle
2) switch from repaint(); to buffer strategy
3) move rectangle to the center of the window
4) make the oval dependent on window size
5) make it so that the oval doesn't go through the rectangle
6) make the oval drop automatically
7) add more obstacles

Thursday, January 6, 2011

Kicking it off

Hey Guys,

I've decided to start another blog where I can share / talk about computer programming and whatever projects I've been working on. I plan on obtaining a masters in computer science after finishing my B.S. in Physics. The last blog I started focused heavily on Physics and physical problems dealing with the real world. I stopped posting on there because the blog was being overrun by bots.

I'd like to start by informing everyone about certain websites and forums for which anyone interested in software programming and / or game design can go to talk and learn. These sites / books / tutorials have really helped me out so far.

Java Gaming forum
+= This site has a lot of projects with people collaborating to develop games in Java. It is very interesting to read what the have to say about game design. Also, this is a great place to pose questions for others to discuss.

Doom Source Code
+= This is awesome. It is the Doom source code in C++.

My project page
+= This is a free site that I plan on using to post my current projects. Right now there is a project called Obstacle which is something that still needs a lot of work but it's a start.

Stendhal MMORPG Source
+= From this site you can download the source code and look through it to better understand how MMORPGs are developed.

Neat Space invaders game
+= One thing that I found here after building the program is that the buffer strategy is much better than using the repaint(); method.

I plan on first running through my Obstacle project code, showing you what I based it off of, explaining what it does, and discuss ideas about making it better. Next, I'd like to run through the space invader code which is more complicated and share some ideas from a 2D game I'd like to develop. Also, I have an idea for a panel that will act like a big collection of shortcuts.

Stay Tuned