Anda di halaman 1dari 16

DTETRIS

Oleh :
Dyah Agustinah W

(2210121034)

Imaduddin Mukhtar (2210121055)


Suryo Aji Waskitho

1.1

(2210121058)

Teori
Tetris adalah teka-teki Permainan video awalnya dirancang dan diprogram Dibuat
Aleksei Pajitnov di Uni Soviet. Hal ini dirilis pada tanggal 6 Juni 1984, ketika ia sedang
bekerja untuk Komputasi Dorodnicyn Pusat Akademi Sains Uni Soviet di Moskow,
Rusia. Dia berasal namanya dari bahasa Yunani numerik awalan tetra-(semua potongan
permainan, yang dikenal sebagai Tetrominoes, berisi empat segmen) dan tenis, olahraga
favorit Pajitnov's. Suami hal dirilis PADA Tanggal 6 Juni 1984,, & e diameter bekerja
untuk Pusat Komputasi Dorodnicyn Dari Akademi Sains Uni Soviet di Moskow, Rusia.
Dia berasal Dari Nama Yunani numerik awalan tetra-(potongan * Semua Permainan's,
Yang Tetrominoes sebagai dikenal, segment Empat berisi) Tenis dan, Olahraga favorit
Pajitnov. Permainan Tetris tetrominoes populer adalah penggunaan, Khusus elemen
Empat KASUS polyominoes. Polyominoes telah digunakan dalam teka-teki populer
setidaknya sejak 1907, dan nama diberikan oleh matematikawan Salomo W. Golomb
pada tahun 1953. Polyominoes telah perlengkapan KESAWAN teka-teki populer
setidaknya sejak 1907, dan diberikan Dibuat matematikawan Nama Salomo W. Golomb
PADA years 1953. Namun, bahkan penghitungan pentominoes adalah tanggal ke kuno.
Namun, bahkan pentominoes penghitungan adalah Kuno ke Tanggal.
Hal ini bahkan mengilhami Tetris yang menyajikan masakan dan telah diputar di
sisi berbagai bangunan, dengan pemegang rekor terbesar permainan dunia berfungsi
penuh Tetris menjadi upaya oleh siswa Belanda pada tahun 1995 yang menerangi semua
15 lantai dari jurusan Teknik Elektro di Delft University of Technology. Permainan (salah
Satu Dari BANYAK nya atau varian) Tersedia untuk hampir * Semua konsol Permainan
video dan sistem Aktiva lain Komputer, Serta PADA perangkat Pembongkaran Grafik
kalkulator, ponsel, portable media player, PDA, pemutar musik dan Jaringan Telur
Paskah bahkan sebagai non-Produk media osiloskop Pembongkaran. Hal Suami bahkan
mengilhami Tetris menyajikan masakan Yang dan telah diputar di berbagai Sisi
Bangunan, Artikel Baru PER sepenuhnya Rekor Dunia fungsional terbesarnya Permainan
Tetris menjadi Upaya Siswa Belanda years PADA Dibuat 1995 Yang menerangi * Semua
15 Lantai Dari jurusan Teknik Elektro di Delft University of Technology.

Sementara versi Tetris terjual untuk berbagai platform 1980-an komputer rumah, itu
adalah versi handheld yang sangat sukses untuk Game Boy diluncurkan pada tahun 1989
yang didirikan permainan sebagai salah satu yang paling populer yang pernah. Electronic
Gaming Bulanan 's isu ke-100 telah Tetris di tempat pertama sebagai "Greatest Game of
All Time". Saccharin versi Tetris untuk berbagai TERJUAL 1980-an rumah Komputer
platform, Sangat adalah sukses ITU genggam untuk versi Game Boy years diluncurkan
Satu salah PADA 1989 Yang didirikan Permainan Yang Pernah populer sebagai pagar
yang. Gaming Elektronik Bulanan 's telah ke-100 SPI Tetris di Tempat Pertama sebagai
"Greatest Game of All Time". Pada tahun 2007, Tetris berada di posisi kedua di IGN s
'"100 Greatest Video Game of All Time". Hal ini telah terjual lebih dari 70 juta kopi. Pada
bulan Januari 2010, ia mengumumkan bahwa Tetris telah terjual lebih dari 100 juta kopi
untuk ponsel sendiri sejak tahun 2005. PADA years 2007, Tetris berada di Posisi kedua di
IGN s '"100 Greatest Video Games Sepanjang Masa". Hal Suami telah lebih Dari
TERJUAL 70 juta kopi. PADA bulan Januari 2010, besarbesaran mengumumkan bahwa
telah Tetris Dari TERJUAL lebih 100 juta eksemplar untuk ponsel Sendiri years sejak
2005.
Tujuan dari permainan ini adalah untuk memanipulasi tetrominoes ini, dengan
memindahkan masing-masing ke samping dan berputar itu dengan 90 unit derajat, dengan
tujuan menciptakan garis horizontal blok tanpa sela. Composition Komposisi Permainan
Dari Suami adalah untuk memanipulasi tetrominoes Suami, memindahkan ke masingmasing Artikel Baru Samping dan Artikel Baru ITU berputar 90 derajat unit, menciptakan
Composition Komposisi Artikel Baru sela blok Tanpa Garis horisontal. Ketika seperti
garis dibuat, menghilang, dan setiap blok di atas garis yang dihapus akan jatuh. Ketika
Pembongkaran Garis Dibuat, menghilang, dan terkait masih berlangsung di blok tetap
Permanent Garis Yang Jatuh akan dihapus. Dengan setiap sepuluh garis yang dihapus,
permainan memasuki tingkat yang baru. Garis Sepuluh terkait masih berlangsung untuk
Artikel Yang dihapus, Permainan memasuki tingkat Yang Baru. Ketika permainan
berlangsung, setiap tingkat menyebabkan tetrominoes jatuh lebih cepat, dan permainan
berakhir ketika tumpukan tetrominoes mencapai bagian atas lapangan bermain dan tidak
ada tetrominoes baru bisa masuk. Ketika Permainan berlangsung, tetrominoes tingkat
terkait masih berlangsung menyebabkan lebih Cepat Jatuh, dan Permainan berakhir
ketika tumpukan mencapai Name of tetrominoes tetap Permanent Lapangan Bermain dan
regular tidak ADA tetrominoes Baru Bisa Masuk. Dalam versi tertentu, permainan juga
dapat berakhir jika pemain sampai ke tingkat 15. KESAWAN versi tertentu, Permainan
Juga dapat berakhir jika Pemain Sampai ke tingkat 15.
Semua tetrominoes mampu membersihkan tunggal dan ganda. I, J, dan L mampu
tiga kali lipat jelas. * Semua tetrominoes Mampu membersihkan ganda dan tunggal,. I, J
dan L Mampu Tiga kali lipat jelas. Hanya tetromino I memiliki kapasitas untuk
menghapus empat baris secara simultan, dan ini disebut sebagai "tetris". Hanya tetromino
Aku memiliki kapasitas untuk menghapus Empat Baris Secara simultan, dan Suami
disebut sebagai "tetris". (Ini mungkin bervariasi tergantung pada aturan rotasi dan

kompensasi dari setiap pelaksanaan Tetris tertentu. Misalnya, dalam Rotasi Super Sistem
yang digunakan dalam implementasi yang paling kini, situasi tertentu memungkinkan T,
S, dan Z untuk 'snap' ke tempat yang ketat dan jelas tiga kali lipat ) (. Ini mungkin
bervariasi tergantung PADA konsisten menyediakan kompensasi dan rotasi Dari terkait
masih berlangsung pelaksanaan Tetris spesifik, Misalnya KESAWAN. Rotasi Super
Sistem KESAWAN perlengkapan Yang Implementasi Yang pagar terkini, T; batasan
tertentu memungkinkan, S, Tempat ke 'snap' dan Z untuk Yang dan ketat jelas Tiga kali
lipat.)
1.2

Hasil

1.3

Program
/
==========================================================
================
// fungsi highscore
//=========================================================
=================
void highscoreLoad(){
std::ifstream inFile;
inFile.open("highscores.txt");
for(int i=0;i<10;i++){
inFile>>highscoreNames[i];
inFile >> highscoreValues[i];
}
}
void highscoreSave(){
std::ofstream outFile;
outFile.open("highscores.txt");
for(int i=0;i<10;i++){
outFile << highscoreNames[i];
outFile << " " << highscoreValues[i];
outFile << std::endl;
}
}
//=========================================================
=================
// Fungsi utk berinteraksi dengan Keyboard
//=========================================================
=================
void appKeyboardFunc ( unsigned char key, int x, int y ){
if(gameState == 0){
switch ( key ){
case 13:// button enter pressed
if(gameSubState==0){// Main Menu
if(
selectedMenuItem == 0){
gameSubState = 1;
}// New Game
else if(selectedMenuItem == 1){
selectedMenuItem=0;
gameSubState = 2;
}// Game Info
else if(selectedMenuItem == 2){
selectedMenuItem=0;
gameSubState = 3;
}// High Scores
else if(selectedMenuItem == 3){
selectedMenuItem=0;
gameSubState = 4;
exit(1); }// Exit
}

else if(gameSubState==1){ // New Game Selected


if(selectedMenuItem == 0){ // Easy Selected
gp=7,gl=7;
fallp=10;
printf("\n\n====================================");
printf("\nEasy Mode");
printf("\n====================================");
printf("\nWidth
: %d",gp);
printf("\nHeight
: %d",gl);
printf("\nFall Position: %d",fallp);
grid = new Grid(gp,10,gl);
grid->difficulty = 0;
fallingPiece = new FallingObject();
fallingPiece->setPosition(grid,1,fallp,1);
gameState = 1;
gameSubState = 0;
}
else if(selectedMenuItem == 1){ // Normal Selected
gp=10,gl=10;
fallp=15;
printf("\n\n====================================");
printf("\nNormal Mode");
printf("\n====================================");
printf("\nWidth
: %d",gp);
printf("\nHeight
: %d",gl);
printf("\nFall Position: %d",fallp);
grid = new Grid(gp,10,gl);
grid->difficulty = 1;
fallingPiece = new FallingObject();
fallingPiece->setPosition(grid,2,fallp,2);
gameState = 1;
gameSubState = 0;
}
else if(selectedMenuItem == 2){// Hard Selected
gp=4,gl=4;
fallp=8;
printf("\n\n====================================");
printf("\nHard Mode");
printf("\n====================================");
printf("\nWidth
: %d",gp);
printf("\nHeight
: %d",gl);
printf("\nFall Position: %d",fallp);
grid = new Grid(gp,10,gl);
grid->difficulty = 2;

fallingPiece = new FallingObject();


fallingPiece->setPosition(grid,2,fallp,2);
gameState = 1;
gameSubState = 0;
}
else if(selectedMenuItem == 3){ // Custom Selected
printf("\n\n====================================");
printf("\nCustom Mode");
printf("\n====================================");
printf("\nWidth
: "); scanf("%d",&gp);
printf("\nHeight
: "); scanf("%d",&gl);
printf("\nFall Position: "); scanf("%d",&fallp);
grid = new Grid(gp,10,gl);
grid->difficulty = 0;
fallingPiece = new FallingObject();
fallingPiece->setPosition(grid,10,fallp,2);
gameState = 1;
gameSubState = 0;
}
else if(selectedMenuItem == 4){ // Return to Menu Selected
gameSubState = 0;
selectedMenuItem = 0;
menu=0;
}
}
else if(gameSubState==2 && selectedMenuItem == 3){
gameSubState = 0;
selectedMenuItem = 0;
}
else if(gameSubState==3){
gameSubState = 0;
}
currentMenuImage = selectedMenuItem;
currentMenuImage +=4*gameSubState;
break;
}
}
else{
const double inc=0.25;
int xChange = 0,zChange = 0;
if(gameSubState == 1){
if(key==13){
if(newHighScore>=0){
for(int i=10;i>newHighScore;i--){
highscoreNames[i] = highscoreNames[i-1];
highscoreValues[i] = highscoreValues[i-1];
}
std::string name(highscoreNameInput);

highscoreNames[newHighScore] = name;
highscoreValues[newHighScore] = grid->score;
highscoreSave();
}
gameState = 0;
gameSubState = 0;
selectedMenuItem = 0;
}else{
if(highscoreNameInputLoc>0 && (key == 127 || key == 8)){
highscoreNameInputLoc--;
highscoreNameInput[highscoreNameInputLoc]='\0';
}
else if(highscoreNameInputLoc<254 && key !=' '){
highscoreNameInput[highscoreNameInputLoc]=key;
highscoreNameInputLoc++;
highscoreNameInput[highscoreNameInputLoc]='\0';
}
}
}
else{
switch ( key ){
case ' ': timeTillFall=0;
break;
case '1': grid->removeLayer(0);
break;
case 'w':
xChange=0;
zChange=1;
break;
case 'a': xChange=1;
zChange=0;
break;
case 's':
xChange=0;
zChange=-1;
break;
case 'd':
xChange=-1;
zChange=0;
break;
case 'e': fallingPiece->rotateY(grid); break;
case 'q': fallingPiece->rotateX(grid); break;
case 'z': glPolygonMode( GL_FRONT_AND_BACK, GL_LINE);break;
case 'x': glPolygonMode( GL_FRONT_AND_BACK,
GL_FILL);glShadeModel(GL_FLAT);smoothShading=false;break;
case 'c': glPolygonMode( GL_FRONT_AND_BACK,
GL_FILL);glShadeModel(GL_SMOOTH);smoothShading=true;break;
case 27 : exit(1); // Esc was pressed
default: return; // return without rendering
}
if(zChange != 0 || xChange != 0){
double angle = (App->roty)*3.14/180;
double xmove = (xChange*cos(angle) - zChange*sin(angle));
double zmove = (xChange*sin(angle) + zChange*cos(angle));
//printf("xm %f zm %f \n",xmove,zmove);
if(xmove*xmove <zmove*zmove){
xmove=0;
if(zmove<0)zmove=-1;
else zmove=1;
}

else{
zmove=0;
if(xmove<0)xmove=-1;
else xmove=1;
}
fallingPiece->move(grid,(int)xmove,0,(int)zmove);
}
}
}
glutPostRedisplay();
}

////////////////
//Derek Burch
#include "stdafx.h"
# include <math.h>
# include <stdio.h>
# include <fstream>
# include "glutapp.h"
# include "draw.h"
#ifdef WIN32
#include <sys/types.h>
#include <sys/timeb.h>
#else
#include <sys/time.h>
#endif
textures* Textures;
double get_time (){
#ifdef WIN32
// if better precision is needed in Windows, use QueryPerformanceCounter
_timeb tp;
_ftime_s(&tp);
return 0.001*(double)tp.millitm + (double)tp.time;
#else
timeval tp;
if ( gettimeofday(&tp,0)==-1 ) return 0;
return 0.000001*(double)tp.tv_usec + (double)tp.tv_sec;
#endif
}
void initTextures(){Textures = new textures();}
void draw_axis ( double r ){
double d=r/20.0;
glBegin ( GL_LINES );
glColor3f ( 1, 0, 0 );
glVertex3d ( -r, 0, 0 ); glVertex3d ( r, 0, 0 );

glVertex3d ( r-d, -d, 0 ); glVertex3d ( r, 0, 0 );


glVertex3d ( r-d, d, 0 ); glVertex3d ( r, 0, 0 );
glColor3f ( 0, 1, 0 );
glVertex3d ( 0, -r, 0 ); glVertex3d ( 0, r, 0 );
glVertex3d ( 0, r-d, -d ); glVertex3d ( 0, r, 0 );
glVertex3d ( 0, r-d, d ); glVertex3d ( 0, r, 0 );
glColor3f ( 0, 0, 1 );
glVertex3d ( 0, 0, -r ); glVertex3d ( 0, 0, r );
glVertex3d ( 0, -d, r-d ); glVertex3d ( 0, 0, r );
glVertex3d ( 0, d, r-d ); glVertex3d ( 0, 0, r );
glEnd();
}
//=========================================================
=================
// loadTexture_FromBMP is a helper function to make it simple to load bmp
// files without setting a color to alpha
// file points the a string with the name of the file to load.
//=========================================================
=================
GLuint loadTexture_FromBMP(char* file){
return loadTexture_FromBMP(file,0,0,0,false);
}
//=========================================================
=================
// loadTexture_FromBMP is a function to load a bmp file into a texture
// the arguments ar,ag,ab determine which color will be considered as
// transparent (full alpha). useAlpha mus be true for the alpha colors to be
// considered. file points the a string with the name of the file to load.
// The function can only read 24-bit BMP files that have sizes in powers of 2
//=========================================================
=================
GLuint loadTexture_FromBMP(char* file, unsigned char ar,unsigned char ag,unsigned char ab,bool
useAlpha){
std::ifstream bmpFile(file, std::ios::in |std::ios::binary);
if(bmpFile.is_open()){
unsigned int FileSize = 0;
unsigned int rawPixelDataSize = 0;
unsigned int width = 0;
unsigned int height = 0;
GLuint texture = 0;
//the file type is never tested and is assumed to be a 24-bit bmp
//dont pass in other file types

//move to correct positions and read their values


bmpFile.seekg(2);

bmpFile.read((char

bmpFile.seekg(18);

bmpFile.read((char

*)&FileSize,4);
*)&width,4);
bmpFile.read((char *)&height,4);
bmpFile.seekg(54);
rawPixelDataSize = FileSize-54;
//printf("texture %s | found\n",file);
//printf("size=%d,width=%d,height=%d\n",FileSize,width,height);
//load in the raw pixel data including any padding
unsigned char* rawpixelData = new unsigned char[rawPixelDataSize];
bmpFile.read((char*)rawpixelData,rawPixelDataSize);
bmpFile.close(); //the file is no longer needed
//determine the paddedWidth of the image(as a number of bytes)
unsigned int paddedWidth = width*3;
while(paddedWidth%4)paddedWidth++;
//the images width must be a power of 2
if(paddedWidth == width*3){
unsigned char* purepixelData;
if(useAlpha) purepixelData = new unsigned
char[rawPixelDataSize+rawPixelDataSize/3];
else purepixelData = new unsigned char[rawPixelDataSize];
//if alpha is used colors matching ar,ag,ab will gain an alpha of 255
// otherwise an alpha of 0 is assigned
if(useAlpha){
for(unsigned int i=0;i < rawPixelDataSize/3;i++){
purepixelData[i*4+2]=rawpixelData[i*3];
purepixelData[i*4+1]=rawpixelData[i*3+1];
purepixelData[i*4]=rawpixelData[i*3+2];
if(
purepixelData[i*4]==ar &&
purepixelData[i*4+1]==ag && purepixelData[i*4+2]==ab){
purepixelData[i*4+3]=0;}
else{purepixelData[i*4+3]=255;}
}
}else{for(unsigned int i=0;i < rawPixelDataSize;i+=3){
purepixelData[i+2]=rawpixelData[i];
purepixelData[i+1]=rawpixelData[i+1];
purepixelData[i]=rawpixelData[i+2];
}
}
glGenTextures( 1, &texture );
glBindTexture( GL_TEXTURE_2D, texture );
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,
GL_MODULATE );//mix colors for shading
//mip map settings
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_NEAREST );

glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );


//repeat the texture if coords are greater than 1
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_REPEAT);
//create the 2d midmaps with the above parameters
if(useAlpha)gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGBA,width,
height, GL_RGBA, GL_UNSIGNED_BYTE, purepixelData );
else
printf("",gluErrorString(gluBuild2DMipmaps( GL_TEXTURE_2D, 3,
width,
height, GL_RGB, GL_UNSIGNED_BYTE, purepixelData )));
delete [] purepixelData;
}else{
//printf("Error - Invalid texture size: %s\n",file);
}
delete [] rawpixelData;
return texture;
}
//file read failed
//printf("Error - Unable to load texture: %s\n",file);
return 0;
}
void renderStrokeFontString(
float x, float y, float z, float scale,
void *font,
char *string) {
char *c;
glPushMatrix();
glTranslatef(x, y,z);
glScaled(scale,scale,scale);
for (c=string; *c != '\0'; c++) {glutStrokeCharacter(font, *c);}
glPopMatrix();
}
//=========================================================
=================
// setMaterial_Color is a shortcut function for setting the current fill color
// used when drawing solids (sets material property)
//=========================================================
=================
void setMaterial_Color(float r,float g,float b,float a){
float color[4];
color[0]=r;
color[1]=g;
color[2]=b;
color[3]=a;
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color);
}
//=========================================================
=================
// Draws a solid box with the given paramenters

// size=width/height/depth
// tex=texture that is applied to each side of the cube
// the box is centered at the origin
//=========================================================
=================
void draw_texturedbox(double size,GLuint tex){
glEnable( GL_TEXTURE_2D);
glBindTexture( GL_TEXTURE_2D, tex );
//front face
glBegin(GL_POLYGON);
glNormal3d(0,0,-1);
glTexCoord2d(0,0);
glVertex3d(size/2,-size/2,-size/2);
glTexCoord2d(1,0);
glVertex3d(-size/2,-size/2,-size/2);
glTexCoord2d(1,1);
glVertex3d(-size/2,size/2,-size/2);
glTexCoord2d(0,1);
glVertex3d(size/2,size/2,-size/2);
glEnd();
//back face
glBegin(GL_POLYGON);
glNormal3d(0,0,1);
glTexCoord2d(0,0);
glVertex3d(size/2,-size/2,size/2);
glTexCoord2d(1,0);
glVertex3d(-size/2,-size/2,size/2);
glTexCoord2d(1,1);
glVertex3d(-size/2,size/2,size/2);
glTexCoord2d(0,1);
glVertex3d(size/2,size/2,size/2);
glEnd();
//left face
glBegin(GL_POLYGON);
glNormal3d(1,0,0);
glTexCoord2d(0.0,0.0);
glVertex3d(size/2,-size/2,size/2);
glTexCoord2d(1.0,0.0);
glVertex3d(size/2,-size/2,-size/2);
glTexCoord2d(1.0,1.0);
glVertex3d(size/2,size/2,-size/2);
glTexCoord2d(0.0,1.0);
glVertex3d(size/2,size/2,size/2);
glEnd();
//right face
glBegin(GL_POLYGON);
glNormal3d(-1,0,0);
glTexCoord2d(0,1);
glVertex3d(-size/2,-size/2,size/2);
glTexCoord2d(0,0);
glVertex3d(-size/2,-size/2,-size/2);
glTexCoord2d(1,0);
glVertex3d(-size/2,size/2,-size/2);
glTexCoord2d(1,1);
glVertex3d(-size/2,size/2,size/2);
glEnd();
//top face
glBegin(GL_POLYGON);
glNormal3d(0,1,0);
glTexCoord2d(0,1);
glVertex3d(size/2,size/2,-size/2);
glTexCoord2d(0,0);
glVertex3d(-size/2,size/2,-size/2);
glTexCoord2d(1,0);
glVertex3d(-size/2,size/2,size/2);
glTexCoord2d(1,1);
glVertex3d(size/2,size/2,size/2);
glEnd();
//front face

glBegin(GL_POLYGON);
glNormal3d(0,-1,0);
glVertex3d(size/2,-size/2,-size/2);
glVertex3d(-size/2,-size/2,-size/2);
glVertex3d(-size/2,-size/2,size/2);
glVertex3d(size/2,-size/2,size/2);
glEnd();
glDisable( GL_TEXTURE_2D);

glTexCoord2d(0,1);
glTexCoord2d(0,0);
glTexCoord2d(1,0);
glTexCoord2d(1,1);

}
//=========================================================
=================
//function used to render the grid object and the falling object
//=========================================================
=================
void draw_grid(Grid* g, FallingObject *o){
float squareSize = 2.5;
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glPushMatrix();
glTranslated(-(g->xSize-1)*squareSize/2,-6,-(g->zSize-1)*squareSize/2);
//draw bottom grid
glPushMatrix();
glTranslated(-squareSize/2,-squareSize/2,-squareSize/2);
for(int z=0;z<g->zSize;z++){
for(int x=0;x<g->xSize;x++){
glDisable(GL_LIGHTING);
glColor3d(0.1,0.1,0.1);
glBegin ( GL_LINES );
glVertex3d ( squareSize*x, 0, squareSize*z ); glVertex3d ( squareSize*(x+1), 0,
squareSize*z );
glVertex3d ( squareSize*(x+1), 0, squareSize*z );glVertex3d ( squareSize*(x+1),
0, squareSize*(z+1));
glVertex3d ( squareSize*(x+1), 0, squareSize*(z+1)); glVertex3d ( squareSize*x,
0, squareSize*(z+1) );
glVertex3d ( squareSize*x, 0, squareSize*(z+1) ); glVertex3d ( squareSize*x, 0,
squareSize*z );
glEnd();
glEnable(GL_LIGHTING);
}
}
//draw the elements in the grid
glPopMatrix();
for(int z=0;z<g->zSize;z++){
for(int y=0;y<g->ySize;y++){
for(int x=0;x<g->xSize;x++){
if(g->occupied[x][y][z] > 0){

glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, g>color[x][y][z]);


glPushMatrix();
glTranslated(x*squareSize,y*squareSize,z*squareSize);
if(g->difficulty <2 && g->occupied[x][y][z]==2)
draw_texturedbox(squareSize,Textures->bombTexture);
else draw_texturedbox(squareSize,Textures->cubeTexture);
glPopMatrix();
}
}
}
}
//draw the falling object
for(int p = 0;p<5;p++){
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, o->color);
glPushMatrix();
glTranslated((o->position[0]+o->pieceLoc[p][0])*squareSize,(o->position[1]+o>pieceLoc[p][1])*squareSize,(o->position[2]+o->pieceLoc[p][2])*squareSize);
if(g->difficulty <2 && o->bombLocation==p)
draw_texturedbox(squareSize,Textures->bombTexture);
else draw_texturedbox(squareSize,Textures->cubeTexture);
glPopMatrix();
}
//draw the outline for where the falling object will land
int helperPos[3] ;
for(int i=0;i<3;i++)helperPos[i]=o->position[i];
while(o->checkLocation(g,helperPos,o->pieceLoc)){
helperPos[1]--;
}
helperPos[1]++;
for(int p = 0;p<5;p++){
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, o->color);
glPushMatrix();
glTranslated((helperPos[0]+o->pieceLoc[p][0])*squareSize,(helperPos[1]+o>pieceLoc[p][1])*squareSize,(helperPos[2]+o->pieceLoc[p][2])*squareSize);
glutWireCube(squareSize);
glPopMatrix();
}
glPopMatrix();
glDisable(GL_BLEND);
}

1.4

Analisa
Pada program draw.cpp yaitu membuat balok tetris 3 dimensi pada fungsi void
initTextures dan fungsi void draw_axis. Selanjutnya membuat texturedbox dengan
GL_POLYGON pada front face, back face, left face, right face, dan top face. Kemudian
melakukan dungsi untuk merender ketika melakukan grid objek dan saat objek dijatuhkan
dari atas kebawah, dengan menggambar grid bawah, menggambar elemen pada grid,

menggambar objek ketika terjatuh, menggambar garis luar untuk posisi jatuhnya objek
ketika akan landing. Pada game terdapat beberapa menu yaitu highscores, highscores
tersebut akan diload dan disimpan dengan fungsi outFile pada txt. Fungsi untuk
berinteraksi dengan keyboard yaitu menggunakan tombol kursor keyboard bawah untuk
memilih menu. Jika memilih menu maka dapat ditekan enter. Kemudian ketika pada
menu new game ada beberapa level yang dapat dipilih yaitu level easy (mudah), normal
(biasa), dan hard (sulit). Untuk mengarahkan baloknya dengan unsi switch case pada key
w,a,s,d,e,q,z,x,c. Jika ketika memainkan game balok tersusun hingga pembatas atas maka
dikatakan game over. Untuk melihat pandang kamera ke segala arah maka digunakan
kursor arah pada keyboard.
1.5

Kesimpulan
Pada game kali ini penambahan pada music/sound, menu, dan level. Untuk mengarahkan
baloknya dengan unsi switch case pada key w,a,s,d,e,q,z,x,c. Jika ketika memainkan
game balok tersusun hingga pembatas atas maka dikatakan game over. Untuk melihat
pandang kamera ke segala arah maka digunakan kursor arah pada keyboard.

Anda mungkin juga menyukai