Membuat Game Maze Menggunakan Aplikasi Processing
Assalamualaikum Sahabat Malam, disini saya akan memberikan acuan untuk membuat game Maze pada aplikasi processing.
untuk tutorial tahap 2 dapat dilihat pada link berikutuntuk tutorial tahap 3 dapat dilihat pada link berikut
berikut coding yang digunakan untuk membuat game MAZE.
// Simple maze game
//
// As any maze game, you start from somewhere (red square) and you have to find
// the exit (green square) as fast as possible.
// Each step is counted, so at the end, you will know how many steps you have walked
// in conparaison to the minimal needed steps to escape.
// Keys :
// R : Restart the game. A new maze is generated and time is cleared
// SPACE : Start the game
// A : Left
// D : Right
// W : Up
// S : Down
color white = color (0xFF, 0xFF, 0xFF);
color blue = color (0x00, 0x00, 0xFF);
color red = color (0xFF, 0x00, 0x00);
color green = color (0x00, 0xFF, 0x00);
color black = color (0x00, 0x00, 0x00);
int state_init = 0;
int state_run = 1;
int state_end = 2;
//=============== GAME ================
class Game {
Game () {
Reset();
}
void Reset () {
_state = state_init;
_maze = new Maze (20, 40, int (random(1, 6)));
_maze.compute ();
_maze.show (8);
_needToRedraw = true;
_startTime = 0;
_endTime = 0;
ClearTextArea();
textAlign(CENTER);
fill(black);
text("Press SPACE to start",160, 220);
}
void Start() {
if (_state == state_init) {
Run();
return;
}
}
void Move (int k) {
if (_state == state_run) {
if (k == 'a') _maze.goWest();
else if (k == 'd') _maze.goEast();
else if (k == 's') _maze.goSouth();
else if (k == 'w') _maze.goNorth();
}
}
void Run() {
_state = state_run;
_startTime = millis();
// Clear and draw score
ClearTextArea();
}
void End() {
_state = state_end;
_endTime = millis();
ClearTextArea();
textAlign(CENTER);
fill(black);
text("FINISHED in",160, 180);
int delta = (_endTime - _startTime) / 1000;
int m = delta / 60;
int s = (delta - m*60);
String ti = "Time : " + m + "'" + s + "\"";
text(ti ,160, 200);
String p = "Current : " + _maze.getStep() + " steps";
text(p ,160, 220);
String d = "Best : " + _maze.getMaxDistance () + " steps";
text(d ,160, 240);
}
void ClearTextArea () {
fill (white);
rect(0, 160, 320, 60);
}
void KeyPressed (int k) {
if (k == 'r') Reset(); // Resetting game
if (k == ' ') Start(); // Start
Move (k);
}
void Manage() {
if (_state == state_run) {
if (_maze.AtEnd()) End();
else { // Updating current time
fill (white);
rect(0, 180, 320, 20);
fill (black);
int delta = (millis() - _startTime) / 1000;
int m = delta / 60;
int s = (delta - m*60);
String ti = "Time : " + m + "'" + s + "\"";
text(ti ,160, 200);
}
}
}
int _state;
boolean _needToRedraw;
int _startTime;
int _endTime;
Maze _maze;
};
int VIDE=0;
int MUR=1;
int PAS=2;
//=============== NODE ================
class Node {
int _x;
int _y;
int _dir;
int _distance;
Node (int x, int y, int dir, int distance) {
_x = x;
_y = y;
_dir = dir;
_distance = distance;
}
int getX () { return _x; }
int getY () { return _y; }
int getDir () { return _dir; }
int getDistance () { return _distance; }
};
//=============== MAZE ================
class Maze {
Maze (int h, int w, int p) {
_h = h;
_w = w;
_sx = 1;
_sy = 1;
_dirs = 0;
_p = p;
if (_w < 5) _w = 5;
if (_h < 5) _h = 5;
_m = new int [_h][_w];
_nodes = new ArrayList();
reset();
}
Makasih bg, tp kalau boleh dibuat in indonesia nya ya bg hehe
ReplyDeleteaku ganteng๐
ReplyDeleteMantap gan๐๐๐
ReplyDeleteCukup paten paten kaliii
ReplyDeleteMntap gan , di tunggu game game lainnya
ReplyDeleteMantull bosqueeee๐๐๐๐๐
ReplyDeletesangat berfaedah min..izin share min
ReplyDeletemantaapp boosss
ReplyDelete