Intializing Applet
Author |
Message |
jamonathin
|
Posted: Wed Dec 21, 2005 2:47 pm Post subject: Intializing Applet |
|
|
Hey all, wanted to get back into making games (as some of you may know) and i'm just going to start with a basic brickout style game. But i cant seem to get anything to start. How do I go about initializing my applet?
Here's my code. The only part I wanna see right now is refresh();. The other stuff is there for later on.
Java: |
import java.awt.*;
public class Tetris
{
Thread fThread;
Image offScreenImage;
Graphics offScreenGraphics;
int xPlayer = 100;
int yPlayer = 20;
int gameSpeed = 4;
int bxSize = 30; // Block - x size.
int bySize = 30; // Block - y size.
int maxx = 360;
int maxy = 360;
boolean keyUp = false;
boolean keyDown = false;
boolean keyLeft = false;
boolean keyRight = false;
// 2-D map
byte fMap [];
static final byte W = 1; // wall
static final byte O = 0; // opening
static final int mapWidth = 12;
static final int mapHeight = 12;
public void map ()
{
// Making a map - 2D
byte[] map=
{
O,O,O,O,O,O,O,O,O,O,O,O,
O,O,O,O,O,W,W,O,O,O,O,O,
O,O,O,O,W,W,W,W,O,O,O,O,
O,O,O,W,W,W,W,W,W,O,O,O,
O,O,W,W,W,W,W,W,W,W,O,O,
O,W,W,W,W,W,W,W,W,W,W,O,
O,O,O,O,W,W,W,W,O,O,O,O,
O,O,O,O,O,O,O,O,O,O,O,O,
O,O,O,O,O,O,O,O,O,O,O,O,
O,O,O,O,O,O,O,O,O,O,O,O,
O,O,O,O,O,O,O,O,O,O,O,O,
O,O,O,O,O,O,O,O,O,O,O,O,
};
fMap=map;
}
public void refresh ()
{
for (int i = 0 ; i < maxx / 2 ; ++i )
{
offScreenGraphics. setColor(new Color (i / (maxx / 2), i / (maxx / 2), i / (maxx / 2)));
offScreenGraphics. fillRect(i, i, maxx - i, maxy - i );
}
}
public void move ()
{
while (true)
{
if (keyLeft && xPlayer - gameSpeed > 0)
{
xPlayer -= gameSpeed;
}
else if (keyRight && xPlayer + gameSpeed < maxx )
{
xPlayer += gameSpeed;
}
}
}
public void main (String []args )
{
refresh ();
}
}
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
wtd
|
Posted: Wed Dec 21, 2005 2:48 pm Post subject: (No subject) |
|
|
That's in even the most basic applet tutorial.
Google is your friend, especially with "site:java.sun.com". |
|
|
|
|
|
jamonathin
|
Posted: Thu Dec 22, 2005 10:32 am Post subject: (No subject) |
|
|
Yeah turns out i needed
and
I saw those in the other example, but I thought they were just user created names, not that init and run were needed . |
|
|
|
|
|
jamonathin
|
Posted: Thu Dec 22, 2005 10:33 am Post subject: (No subject) |
|
|
Yeah turns out i needed
and
I saw those in the other example, but I thought they were just user created names, not that init and run were needed . |
|
|
|
|
|
|
|