Wednesday, November 18, 2009

Developing a Multiplayer Maze Game in Java - Part 2

A game can not be completed without a sprite. Now, what this sprite thing. If you already know then you can skip the definition below


Sprite : A 2D or 3D character/object in game.


A sprite can have various properties like its position, name, features, memory etc. The class below represents a sprite which has following properties -


int x; // x - position
int y; // y - position
double theta; // direction
String name; // name of sprite
boolean explored[][]; //memory of explored map
BufferedImage img[]; //face for our sprite

----------------------------
Code for Part two
--------------------------------
import java.awt.image.*;


class sprite{
int x;
int y;
double theta;
String name;
boolean explored[][];
BufferedImage img[];

public  sprite(String n, int x1,int y1){
name = n;
x=x1;
y=y1;
theta = 0;
explored = new boolean[20][20];
img = new BufferedImage[4];
explored[x][y] = true;
}

No comments:

Post a Comment