Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "zcommon.acs"
- #library "zdoomtest"
- #include "commonFuncs.h"
- #include "tetDefs.h"
- int PlayingTetris[PLAYERMAX];
- int KeysPressed[KEYCOUNT];
- int TetrisField[MATRIX_Y][MATRIX_X];
- int LinesDeleted[MATRIX_Y] = {0};
- int ComboLevel, LastLineType, LastLineSpin;
- int GameOver, TetrisPaused;
- int Gravity;
- int TetrisScore, TetrisLines, TetrisLevel, TetrisPlaced, TetrisTics;
- int PieceX, PieceY, PieceType, PieceRot, PieceLocking, PieceLocking2;
- int HoldType, HoldRot, DidHold;
- int PieceDrop;
- int OldX, OldY, OldRot, OldPaused;
- int TetrisFont;
- int BagTemp[BLOCKCOUNT];
- int NextPieces[NEXTCOUNT];
- function void SetKeysPressed(void)
- {
- int i, j, down;
- for (i = 0; i < KEYCOUNT; i++)
- {
- j = Keymaps[i];
- down = GetPlayerInput(-1, INPUT_BUTTONS) & j;
- KeysPressed[i] = cond(down, KeysPressed[i]+1, 0);
- }
- }
- function int TetKey(int key)
- {
- return KeysPressed[key];
- }
- function int AddScore(int add)
- {
- TetrisScore += (add * TetrisLevel);
- return TetrisScore;
- }
- function int GetBlock(int bX, int bY)
- {
- if (bX < 0 || bX >= MATRIX_X
- || bY >= MATRIX_Y) { return -1; }
- if (bY < 0) { return 0; }
- return TetrisField[bY][bX];
- }
- function void SetBlock(int bX, int bY, int type)
- {
- if (bX < 0 || bX >= MATRIX_X
- || bY < 0 || bY >= MATRIX_Y) { return; }
- TetrisField[bY][bX] = type;
- }
- function int PieceBlock(int x, int y, int type, int rotation)
- {
- return TetrisBlocks[type-1][rotation][y][x];
- }
- function int PieceCollides(int pX, int pY, int type, int rotation)
- {
- int tx, ty;
- int block;
- int fieldBlock;
- for (ty = BLOCK_YMAX-1; ty >= 0; ty--)
- {
- for (tx = BLOCK_XMAX-1; tx >= 0; tx--)
- {
- block = PieceBlock(tx, ty, type, rotation);
- if (!block) { continue; }
- fieldBlock = GetBlock(tx + pX, ty + pY);
- if (fieldBlock != 0)
- {
- return 1;
- }
- }
- }
- return 0;
- }
- function int LowestDrop(int x, int y, int type, int rot)
- {
- int i, j, collided, collides;
- collides = 0; collided = 0;
- y = cond(y, y, -BLOCK_YMAX);
- for (i = y; i < MATRIX_Y; i++)
- {
- collided = collides;
- collides = PieceCollides(x, i, type, rot);
- if (collides && !collided)
- {
- return i-1;
- }
- }
- return -0x80000000;
- }
- function int MovePieceX(int x, int y, int type, int rot)
- {
- int i, j;
- int goleft, goright;
- int dasdelay = GetCVar("tetris_dasdelay");
- int das = GetCVar("tetris_das");
- goright = TetKey(KEY_RIGHT) % 4 == 1;
- int baseleft = TetKey(KEY_LEFT);
- int baseright = TetKey(KEY_RIGHT);
- int dasleft, dasright;
- if (das == 0)
- {
- dasleft = cond(baseleft > dasdelay, MATRIX_X, 0);
- dasright = cond(baseright > dasdelay, MATRIX_X, 0);
- }
- else
- {
- if (baseleft > dasdelay) { dasleft = ((baseleft - dasdelay) % das) == 0; }
- else { dasleft = 0; }
- if (baseright > dasdelay) { dasright = ((baseright - dasdelay) % das) == 0; }
- else { dasright = 0; }
- }
- goleft = dasleft;
- goright = dasright;
- if (baseleft == 1 && dasdelay != 0) { goleft = 1; }
- if (baseright == 1 && dasdelay != 0) { goright = 1; }
- int ret = (goright - goleft);
- for (i = 0; i <= abs(ret); i++)
- {
- j = i * sign(ret);
- if (PieceCollides(x+j, y, type, rot))
- {
- ret = max(0, (i-1)) * sign(ret);
- break;
- }
- if (PieceCollides(x+j, y+1, type, rot) && i != 0)
- {
- LocalAmbientSound("acstris/pieceland", 127);
- }
- }
- if (ret) { LocalAmbientSound("acstris/movepiece", 127); }
- return ret+x;
- }
- function int MovePieceY(int x, int y, int type, int rot)
- {
- int ret;
- int drop;
- int dropping = TetKey(KEY_CROUCH);
- int i, j;
- //PieceDrop += (TetrisLevel * sqrt(itof(TetrisLevel))) / 35;
- PieceDrop += Gravity;
- ret = ftoi(PieceDrop);
- PieceDrop %= 1.0;
- if (dropping)
- {
- if (GetCVar("tetris_dropspeed") == 0)
- {
- ret = LowestDrop(x, y, type, rot) - y;
- }
- else
- {
- if (dropping % GetCVar("tetris_dropspeed") == 0)
- {
- ret += 1;
- if (PieceCollides(x, y+ret, type, rot)) { ret -= 1; }
- }
- }
- AddScore(ret);
- }
- for (i = 0; i <= abs(ret); i++)
- {
- j = i * sign(ret);
- if (PieceCollides(x, y+j, type, rot))
- {
- ret = max(0, (i-1)) * sign(ret);
- break;
- }
- }
- return ret + y;
- }
- // http://tetrisconcept.net/wiki/SRS#How_Guideline_SRS_Really_Works
- function int Kick(void)
- {
- int kickmod, kx1, ky1, kx2, ky2, kx, ky, i;
- if (!PieceCollides(PieceX, PieceY, PieceType, PieceRot)) { return 0; }
- /*
- for (i = 0; i < KICKCOUNT_X; i++)
- {
- for (j = 0; j < KICKCOUNT_Y; j++)
- {
- kx = XKicks[i];
- ky = YKicks[j];
- if (PieceRot - OldRot == 1) { kx = -kx; }
- if (!PieceCollides(PieceX+kx, PieceY+ky, PieceType, PieceRot))
- {
- PieceX += kx;
- PieceY += ky;
- return 1;
- }
- }
- }
- */
- for (i = 0; i < KICKCOUNT; i++)
- {
- if (mod(PieceRot - OldRot, ROTCOUNT) == 2)
- {
- kx = SRS180Kicks[PieceType-1][i][0];
- ky = -SRS180Kicks[PieceType-1][i][1];
- }
- /*
- else
- {
- kx1 = SRSBases[PieceType-1][OldRot][i][0];
- ky1 = -SRSBases[PieceType-1][OldRot][i][1];
- kx2 = SRSBases[PieceType-1][PieceRot][i][0];
- ky2 = -SRSBases[PieceType-1][PieceRot][i][1];
- kx = kx1 - kx2;
- ky = ky1 - ky2;
- }
- */
- else
- {
- // CW if 0, CCW is 1
- kickmod = (mod(PieceRot - OldRot, ROTCOUNT) != 1);
- if (PieceType == B_I)
- {
- kx = SRSKicks_I[PieceRot + kickmod][i][0];
- ky = SRSKicks_I[PieceRot + kickmod][i][1];
- }
- else
- {
- kx = SRSKicks[PieceRot + kickmod][i][0];
- ky = SRSKicks[PieceRot + kickmod][i][1];
- }
- }
- //Log(s:"Trying kick (", d:kx, s:", ", d:ky, s:") (", d:OldRot, s:" -> ", d:PieceRot, s:")");
- if (!PieceCollides(PieceX+kx, PieceY+ky, PieceType, PieceRot))
- {
- PieceX += kx;
- PieceY += ky;
- return 1;
- }
- }
- return 0;
- }
- function void HardDrop(int x, int y, int type, int rot)
- {
- int dY = LowestDrop(x, y, type, rot);
- AddPiece(x, dY, type, rot);
- AddScore(2 * (dY - y));
- LocalAmbientSound("acstris/pieceland", 127);
- }
- function void AddPiece(int pX, int pY, int type, int rotation)
- {
- int tx, ty, x, y;
- int block, isspin, cleared = 1;
- int deleted, linetype, combo, score, dogameover = 1;
- TetrisPlaced++;
- if (!PieceCollides(pX, pY, type, rotation) &&
- PieceCollides(pX+1, pY, type, rotation) &&
- PieceCollides(pX-1, pY, type, rotation) &&
- PieceCollides(pX, pY-1, type, rotation))
- {
- isspin = 1;
- }
- for (ty = BLOCK_YMAX-1; ty >= 0; ty--)
- {
- for (tx = BLOCK_XMAX-1; tx >= 0; tx--)
- {
- block = PieceBlock(tx, ty, type, rotation);
- if (!block) { continue; }
- SetBlock(tx + pX, ty + pY, type);
- if (ty + pY >= 0) { dogameover = 0; }
- }
- }
- if (dogameover) { GameOver = 1; }
- deleted = CheckLines();
- x = MATRIX_DRAWX + ((GRAPHIC_SIZE / 2) * (MATRIX_X - 1));
- y = MATRIX_DRAWY + GRAPHIC_SIZE;
- x = intFloat(x * 0.75) + 0.4;
- y = intFloat(y * 0.75) + 0.1;
- for (ty = MATRIX_Y-1; ty >= 0; ty--)
- {
- for (tx = 0; tx < MATRIX_X; tx++)
- {
- if (GetBlock(tx, ty)) { cleared = 0; break; }
- }
- if (cleared == 0) { break; }
- }
- if (deleted)
- {
- linetype = middle(0, deleted - 1, LINETYPES);
- combo = middle(0, ComboLevel-2, COMBOSOUNDS);
- score = itof(50 * pow(2, deleted));
- score = FixedMul(score, 0.5 * (ComboLevel+1));
- score = ftoi(score);
- SetHudSize(480, 360, 1);
- SetFont("SMALLFONT");
- if (isspin)
- {
- HudMessage(s:PieceLetters[type], s:"-Spin ", s:LineNames[linetype][0]; HUDMSG_PLAIN | HUDMSG_COLORSTRING, 401,
- LineNames[linetype][1], x, y, 1.5);
- LocalAmbientSound(SpinBreaks[linetype], 127);
- if (LastLineSpin)
- {
- LocalAmbientSound("acstris/tetriscont", 127);
- score *= 6;
- }
- else
- {
- LocalAmbientSound("acstris/tetrisstart", 127);
- score *= 3;
- }
- LastLineSpin = 1;
- }
- else
- {
- HudMessage(s:LineNames[linetype][0]; HUDMSG_PLAIN | HUDMSG_COLORSTRING, 401,
- LineNames[linetype][1], x, y, 1.5);
- LocalAmbientSound(LineBreaks[linetype], 127);
- if (LastLineSpin)
- {
- LocalAmbientSound("acstris/tetrisend", 127);
- }
- LastLineSpin = 0;
- }
- if (ComboLevel > 1)
- {
- LocalAmbientSound(Combos[combo], 127);
- SetHudSize(480, 360, 1);
- SetFont("SMALLFONT");
- HudMessage(d:ComboLevel-1, s:"-Combo"; HUDMSG_PLAIN, 402,
- CR_CYAN, x, y+12.0, 1.5);
- }
- else
- {
- HudMessage(s:""; HUDMSG_PLAIN, 402, 0, 0, 0, 1);
- }
- if (linetype == 3)
- {
- if (LastLineType != 3) { LocalAmbientSound("acstris/tetrisstart", 127); }
- else { score *= 2; LocalAmbientSound("acstris/tetriscont", 127); }
- }
- else if (LastLineType == 3)
- {
- LocalAmbientSound("acstris/tetrisend", 127);
- }
- if (cleared)
- {
- LocalAmbientSound("acstris/clear", 127);
- score += 2000;
- }
- LastLineType = linetype;
- }
- else if (isspin)
- {
- score = 400;
- SetHudSize(480, 360, 1);
- SetFont("SMALLFONT");
- HudMessage(s:PieceLetters[type], s:"-Spin"; HUDMSG_PLAIN, 401,
- CR_LIGHTBLUE, x, y, 1.5);
- LocalAmbientSound("acstris/spin", 127);
- }
- AddScore(score);
- NewPiece();
- }
- function void SubtractPiece(int pX, int pY, int type, int rotation)
- {
- int tx, ty;
- int block;
- for (ty = BLOCK_YMAX-1; ty >= 0; ty--)
- {
- for (tx = BLOCK_XMAX-1; tx >= 0; tx--)
- {
- block = PieceBlock(tx, ty, type, rotation);
- if (!block) { continue; }
- SetBlock(tx + pX, ty + pY, 0);
- }
- }
- }
- function int CheckLines(void)
- {
- int x, y;
- int deleted;
- for (y = 0; y < MATRIX_Y; y++)
- {
- LinesDeleted[y] = 0;
- for (x = 0; x < MATRIX_X; x++)
- {
- if (GetBlock(x, y) == 0) { break; }
- if (x == (MATRIX_X - 1))
- {
- deleted++;
- DeleteLine(y);
- ShiftLines(y);
- }
- }
- }
- if (deleted)
- {
- ComboLevel++;
- }
- else
- {
- ComboLevel = 0;
- }
- return deleted;
- }
- function void DeleteLine(int y)
- {
- int x, i;
- TetrisLines++;
- int drawy = itof(MATRIX_DRAWY + ((y - MATRIX_Y) * GRAPHIC_SIZE));
- for (x = 0; x < MATRIX_X; x++)
- {
- SetBlock(x, y, 0);
- SetFont("TETFLASH");
- SetHudSize(640, 480, 1);
- HudMessage(s:"A"; HUDMSG_FADEOUT, 22000 + (y * MATRIX_Y) + x, CR_UNTRANSLATED,
- itof(MATRIX_DRAWX + (x * GRAPHIC_SIZE)), drawy, 0.0, 0.15);
- }
- for (i = 0; i < y; i++)
- {
- LinesDeleted[i] += 1;
- }
- }
- function void ShiftLines(int final)
- {
- int x, y, toShift;
- for (y = final; y >= 0; y--)
- {
- toShift = LinesDeleted[y];
- for (x = 0; x < MATRIX_X; x++)
- {
- SetBlock(x, y, GetBlock(x, y-1));
- }
- }
- }
- function void Hold(void)
- {
- int type = PieceType, rot = PieceRot;
- if (DidHold)
- {
- LocalAmbientSound("acstris/holdfail", 127);
- return;
- }
- PieceX = (MATRIX_X / 2) - 2;
- PieceY = 0;
- if (HoldType == 0)
- {
- PieceType = NextPiece();
- PieceRot = 0;
- LocalAmbientSound("acstris/firsthold", 127);
- }
- else
- {
- PieceType = HoldType;
- PieceRot = HoldRot;
- LocalAmbientSound("acstris/hold", 127);
- }
- LocalAmbientSound(NextSounds[NextPieces[0] - 1], 127);
- HoldType = type;
- HoldRot = rot;
- DidHold = 1;
- PieceLocking = 0;
- PieceLocking2 = 0;
- PieceDrop = 0;
- }
- function void NewPiece(void)
- {
- int oldlevel = TetrisLevel;
- int drop;
- PieceX = (MATRIX_X / 2) - 2;
- PieceY = 0;
- PieceType = NextPiece();
- PieceRot = 0;
- PieceLocking = 0;
- PieceLocking2 = 0;
- TetrisLevel = (TetrisLines / 10) + 1;
- PieceDrop = 0;
- DidHold = 0;
- drop = itof(max(1, TetrisLevel)) / max(1, 40 - (TetrisLevel * 2));
- Gravity = FixedMul(drop, 60.0/35);
- LocalAmbientSound(NextSounds[NextPieces[0] - 1], 127);
- if (oldlevel != TetrisLevel && TetrisLevel != 1)
- {
- LocalAmbientSound("acstris/levelup", 127);
- }
- if (PieceCollides(PieceX, PieceY, PieceType, PieceRot))
- {
- GameOver = 1;
- }
- }
- function int NextPiece(void)
- {
- int i, next;
- if (NextPieces[NEXTCOUNT-BLOCKCOUNT] == 0)
- {
- PopulateBag(0);
- }
- next = NextPieces[0];
- for (i = 0; i < NEXTCOUNT-1; i++)
- {
- NextPieces[i] = NextPieces[i+1];
- }
- NextPieces[NEXTCOUNT-1] = 0;
- return next;
- }
- function void PopulateBag(int rebuild)
- {
- int i, j, k, topop, next;
- for (i = 0; i < BLOCKCOUNT; i++)
- {
- if (BagTemp[i] == 0)
- {
- j = i;
- break;
- }
- }
- if (j == 0) { j = BLOCKCOUNT; }
- for (i = 0; i < NEXTCOUNT; i++)
- {
- if (NextPieces[i] != 0 && !rebuild) { continue; }
- if (BagTemp[0] == 0)
- {
- for (k = 0; k < BLOCKCOUNT; k++)
- {
- BagTemp[k] = k+1;
- }
- j = BLOCKCOUNT;
- }
- j -= 1;
- topop = random(0, j);
- NextPieces[i] = BagTemp[topop];
- BagTemp[topop] = BagTemp[j];
- BagTemp[j] = 0;
- }
- }
- function void DrawBlock(int x, int y, int type, int id)
- {
- DrawBlockColor(x, y, type, id, 0);
- }
- function void DrawBlockColor(int bX, int bY, int blockType, int printID, int color)
- {
- int ghost;
- int explicit = !!color;
- if (bX < 0 || bX >= MATRIX_X || bY >= MATRIX_Y) { return; }
- if (printID == 0) { printID = 61000 + (bX * MATRIX_Y) + bY; }
- if (blockType < 0) { blockType *= -1; ghost = 1; }
- if (blockType == 0) { blockType = GetBlock(bX, bY); }
- if (color == 0)
- {
- if (ghost) { color = GhostColors[blockType]; }
- else { color = TetrisColors[blockType]; }
- }
- if (blockType == 0 || (MATRIX_Y - bY) > 20)
- {
- HudMessage(s:" "; HUDMSG_PLAIN, printID, CR_UNTRANSLATED, 0, 0, 1.0);
- }
- else
- {
- SetFont(TetrisFont);
- SetHudSize(640, 480, 1);
- HudMessage(s:"A"; HUDMSG_PLAIN | HUDMSG_COLORSTRING, printID, color,
- itof(MATRIX_DRAWX + (bX * GRAPHIC_SIZE)),
- itof(MATRIX_DRAWY + ((bY - MATRIX_Y) * GRAPHIC_SIZE)),
- 1.0);
- }
- }
- function void DrawPiece(int x, int y, int type, int rotation, int id)
- {
- int i, j, block;
- id = cond(id, id, 71000);
- for (i = 0; i < BLOCK_XMAX; i++)
- {
- for (j = 0; j < BLOCK_YMAX; j++)
- {
- block = PieceBlock(i, j, abs(type), rotation);
- if (block)
- {
- DrawBlock(x+i, y+j, type, id++);
- }
- }
- }
- }
- function void DrawGhost(int x, int y, int type, int rot)
- {
- int i, j, collided, collides;
- collides = 0; collided = 0;
- i = LowestDrop(x, y, type, rot);
- DrawPiece(x, i, -type, rot, 72000);
- }
- function void ClearPiece(void)
- {
- int i;
- for (i = 0; i < (BLOCK_XMAX * BLOCK_YMAX); i++)
- {
- HudMessage(s:""; HUDMSG_PLAIN, 71000+i, 0, 0, 0, 1);
- }
- }
- function void ClearGhost(void)
- {
- int i;
- for (i = 0; i < (BLOCK_XMAX * BLOCK_YMAX); i++)
- {
- HudMessage(s:""; HUDMSG_PLAIN, 72000+i, 0, 0, 0, 1);
- }
- }
- function void DrawField(void)
- {
- DrawFieldBorder();
- DrawBlocks();
- DrawHold();
- DrawNextPieces();
- DrawStats();
- DrawGhost(PieceX, PieceY, PieceType, PieceRot);
- DrawPiece(PieceX, PieceY, PieceType, PieceRot, 0);
- }
- function void DrawFieldGameOver(int level)
- {
- int x, y, y2;
- DrawFieldBorder();
- DrawBlocks();
- DrawNextPieces();
- DrawStats();
- ClearGhost();
- ClearPiece();
- for (y = 0; y < level; y++)
- {
- y2 = MATRIX_Y - (y + 1);
- for (x = 0; x < MATRIX_X; x++)
- {
- DrawBlockColor(x, y2, 0, 21000 + (y2 * MATRIX_Y) + x, "TetrisBlack");
- }
- }
- }
- function void DrawStats(void)
- {
- SetHudSize(640, 480, 1);
- SetFont("CONFONT");
- int x = itof(MATRIX_DRAWX - 60);
- int y = itof(MATRIX_DRAWY) - 39.8;
- int bpm, lpm;
- int mins, secs;
- if (TetrisTics == 0) { bpm = 0; }
- else
- {
- lpm = itof(TetrisLines) / TetrisTics;
- lpm *= 60 * 35;
- lpm = ftoi(lpm);
- }
- if (TetrisTics == 0) { bpm = 0; }
- else
- {
- bpm = itof(TetrisPlaced) / TetrisTics;
- bpm *= 60 * 35;
- bpm = ftoi(bpm);
- }
- mins = TetrisTics / (60 * 35);
- secs = (TetrisTics / 35) % 60;
- HudMessage(s:"SCORE"; HUDMSG_PLAIN, 3500, CR_GOLD, x, y - 120.0, 1.0);
- HudMessage(d:TetrisScore; HUDMSG_PLAIN, 3501, CR_WHITE, x, y - 110.0, 1.0);
- HudMessage(s:"LEVEL"; HUDMSG_PLAIN, 3502, CR_GOLD, x, y - 90.0, 1.0);
- HudMessage(d:TetrisLevel; HUDMSG_PLAIN, 3503, CR_WHITE, x, y - 80.0, 1.0);
- HudMessage(s:"LINES"; HUDMSG_PLAIN, 3504, CR_GOLD, x, y - 60.0, 1.0);
- HudMessage(d:TetrisLines; HUDMSG_PLAIN, 3505, CR_WHITE, x, y - 50.0, 1.0);
- HudMessage(s:"BPM"; HUDMSG_PLAIN, 3506, CR_GOLD, x, y - 30.0, 1.0);
- HudMessage(d:bpm; HUDMSG_PLAIN, 3507, CR_WHITE, x, y - 20.0, 1.0);
- HudMessage(s:"LPM"; HUDMSG_PLAIN, 3508, CR_GOLD, x, y, 1.0);
- HudMessage(d:lpm; HUDMSG_PLAIN, 3509, CR_WHITE, x, y + 10.0, 1.0);
- mins = padStringL(StrParam(d:mins), "0", 2);
- secs = padStringL(StrParam(d:secs), "0", 2);
- HudMessage(s:mins, s:"\cf:\c-", s:secs; HUDMSG_PLAIN, 3510, CR_WHITE, x, y + 35.0, 1.0);
- }
- function void DrawHold(void)
- {
- int x = itof(MATRIX_DRAWX - 60) + 0.4;
- int y = itof(MATRIX_DRAWY - (GRAPHIC_SIZE * MATRIX_Y));
- int x2 = intFloat(1.5 * (MATRIX_DRAWX - 60)) + 0.4;
- int y2 = intFloat(1.5 * (MATRIX_DRAWY - (GRAPHIC_SIZE * MATRIX_Y)));
- int dx, dy, tx, ty;
- int block;
- int printid = 2600; // omg hackers
- SetHudSize(640, 480, 1);
- SetFont("CONFONT");
- HudMessage(s:"HOLD"; HUDMSG_PLAIN, printid++, CR_GOLD, x, y, 1.0);
- if (HoldType == 0) { return; }
- for (ty = 0; ty < BLOCK_YMAX; ty++)
- {
- for (tx = 0; tx < BLOCK_XMAX; tx++)
- {
- block = TetrisBlocks[HoldType-1][HoldRot][ty][tx];
- if (block == 0)
- {
- HudMessage(s:""; HUDMSG_PLAIN, printid++, 0, 0, 0, 1);
- continue;
- }
- SetHudSize(960, 720, 1);
- SetFont(TetrisFont);
- dx = x2 + itof((tx - 1) * GRAPHIC_SIZE);
- dy = y2 + itof(ty * GRAPHIC_SIZE) + 48.0;
- HudMessage(s:"A"; HUDMSG_PLAIN | HUDMSG_COLORSTRING, printid++,
- TetrisColors[HoldType], dx, dy, 1.0);
- }
- }
- }
- function void DrawBlocks(void)
- {
- int x, y;
- for (x = 0; x < MATRIX_X; x++)
- {
- for (y = 0; y < MATRIX_Y; y++)
- {
- DrawBlock(x, y, 0, 0);
- }
- }
- }
- function void DrawFieldBorder(void)
- {
- int printID = 75000;
- int i;
- int y;
- for (i = -1; i <= MATRIX_X; i++)
- {
- SetFont(TetrisFont);
- SetHudSize(640, 480, 1);
- HudMessage(s:"A"; HUDMSG_PLAIN | HUDMSG_COLORSTRING, printID++,
- "TetrisBlack",
- itof(MATRIX_DRAWX + (i * GRAPHIC_SIZE)),
- itof(MATRIX_DRAWY),
- 1.0);
- }
- for (i = 0; i < 20; i++)
- {
- y = itof(MATRIX_DRAWY - ((i+1) * GRAPHIC_SIZE));
- SetFont(TetrisFont);
- SetHudSize(640, 480, 1);
- HudMessage(s:"A"; HUDMSG_PLAIN | HUDMSG_COLORSTRING, printID++,
- "TetrisBlack",
- itof(MATRIX_DRAWX - GRAPHIC_SIZE), y,
- 1.0);
- HudMessage(s:"A"; HUDMSG_PLAIN | HUDMSG_COLORSTRING, printID++,
- "TetrisBlack",
- itof(MATRIX_DRAWX + (MATRIX_X * GRAPHIC_SIZE)), y,
- 1.0);
- }
- }
- function void DrawNextPieces(void)
- {
- int printID = 12500;
- int i;
- int x = itof(MATRIX_DRAWX + (GRAPHIC_SIZE * (MATRIX_X + 5))) + 0.4;
- int y = itof(MATRIX_DRAWY - (GRAPHIC_SIZE * MATRIX_Y)) + 0.2;
- SetHudSize(640, 480, 1);
- SetFont("CONFONT");
- HudMessage(s:"NEXT"; HUDMSG_PLAIN, printID++, CR_GOLD,
- x, y, 1.0);
- for (i = 0; i < 7; i++)
- {
- DrawNextPiece(i);
- }
- }
- function void DrawNextPiece(int offset)
- {
- int type = NextPieces[offset];
- int printid = 13500 + (offset * BLOCK_XMAX * BLOCK_YMAX);
- int block;
- int x, y;
- int dx, dy;
- offset *= GRAPHIC_SIZE * (BLOCK_YMAX + 1);
- dx = intFloat(1.5 * (MATRIX_DRAWX + (GRAPHIC_SIZE * MATRIX_X))) + itof(GRAPHIC_SIZE * 6);
- dy = intFloat(1.5 * (MATRIX_DRAWY - (GRAPHIC_SIZE * MATRIX_Y))) + itof(GRAPHIC_SIZE * 2) + itof(offset);
- for (y = 0; y < BLOCK_YMAX; y++)
- {
- for (x = 0; x < BLOCK_XMAX; x++)
- {
- block = TetrisBlocks[type-1][0][y][x];
- if (block == 0)
- {
- HudMessage(s:""; HUDMSG_PLAIN, printid++, 0, 0, 0, 1);
- continue;
- }
- SetHudSize(960, 720, 1);
- SetFont(TetrisFont);
- HudMessage(s:"A"; HUDMSG_PLAIN | HUDMSG_COLORSTRING, printid++,
- TetrisColors[type],
- dx + itof(x * GRAPHIC_SIZE),
- dy + itof(y * GRAPHIC_SIZE), 1.0);
- }
- }
- }
- function void BeginGame(void)
- {
- int x, y;
- for (x = 0; x < MATRIX_X; x++)
- {
- for (y = 0; y < MATRIX_Y; y++)
- {
- SetBlock(x, y, 0);
- }
- }
- PopulateBag(1);
- GameOver = 0;
- TetrisScore = 0;
- TetrisLines = 0;
- TetrisPlaced = 0;
- TetrisTics = 0;
- ComboLevel = 0;
- LastLineType = 0;
- HoldType = 0;
- HoldRot = 0;
- DidHold = 0;
- }
- script 123 (void) net
- {
- int pln;
- PlayingTetris[pln] = !PlayingTetris[pln];
- ACS_ExecuteAlways(124, 0, PlayingTetris[pln],0,0);
- SetPlayerProperty(0, PlayingTetris[pln], PROP_TOTALLYFROZEN);
- }
- script 124 (int play) clientside
- {
- int pln = PlayerNumber();
- if (pln != ConsolePlayerNumber()) { terminate; }
- PlayingTetris[pln] = play;
- int x, y, type, rot;
- int tolog, i;
- int gameoverY, gameovertic;
- x = itof(MATRIX_DRAWX + ((GRAPHIC_SIZE / 2) * (MATRIX_X - 1))) + 0.4;
- y = itof(MATRIX_DRAWY - ((GRAPHIC_SIZE / 2) * MATRIX_Y));
- if (GetCVar("tetris_varsexist") != 1)
- {
- saveCVar("tetris_varsexist", 1);
- saveCVar("tetris_das", 3);
- saveCVar("tetris_dasdelay", 6);
- saveCVar("tetris_dropspeed", 2);
- }
- if (!PlayingTetris[pln]) { terminate; }
- if (!TetrisPaused)
- {
- while (!keyPressed(BT_USE))
- {
- DrawFieldBorder();
- SetHudSize(640, 480, 1);
- SetFont("SMALLFONT");
- HudMessage(s:"Move left - \cj", k:"+moveleft", s:"\c- or \cj", k:"+left";
- HUDMSG_PLAIN, 701, CR_GREEN, x, y - 50.0, 1.0);
- HudMessage(s:"Move right - \cj", k:"+moveright", s:"\c- or \cj", k:"+right";
- HUDMSG_PLAIN, 702, CR_GREEN, x, y - 40.0, 1.0);
- HudMessage(s:"Rotate clockwise - \cj", k:"+forward", s:"\c- or \cj", k:"+lookup";
- HUDMSG_PLAIN, 703, CR_GREEN, x, y - 28.0, 1.0);
- HudMessage(s:"Rotate counterclockwise - \cj", k:"+back", s:"\c- or \cj", k:"+lookdown";
- HUDMSG_PLAIN, 704, CR_GREEN, x, y - 18.0, 1.0);
- HudMessage(s:"Soft drop - \cj", k:"+crouch";
- HUDMSG_PLAIN, 705, CR_GREEN, x, y-6.0, 1.0);
- HudMessage(s:"Hard drop - \cj", k:"+jump";
- HUDMSG_PLAIN, 706, CR_GREEN, x, y+4.0, 1.0);
- HudMessage(s:"180 degree turn - \cj", k:"+speed";
- HUDMSG_PLAIN, 707, CR_GREEN, x, y + 16.0, 1.0);
- HudMessage(s:"Hold piece - \cj", k:"+user1";
- HUDMSG_PLAIN, 708, CR_GREEN, x, y + 28.0, 1.0);
- HudMessage(s:"Pause - \cj", k:"+use";
- HUDMSG_PLAIN, 709, CR_GREEN, x, y + 40.0, 1.0);
- HudMessage(s:"Hit \cf", k:"+use", s:"\c- to begin.";
- HUDMSG_PLAIN, 716, CR_GREEN, x, y + 55.0, 1.0);
- HudMessage(s:"Puke script 123 again to kill ACSTris.";
- HUDMSG_PLAIN, 717, CR_BRICK, x, y + 70.0, 1.0);
- HudMessage(s:"This will reset your game unless you paused.";
- HUDMSG_PLAIN, 718, CR_BRICK, x, y + 78.0, 1.0);
- Delay(1);
- }
- HudMessage(s:""; HUDMSG_PLAIN, 702, CR_UNTRANSLATED, 0, 0, 1);
- HudMessage(s:""; HUDMSG_PLAIN, 703, CR_UNTRANSLATED, 0, 0, 1);
- HudMessage(s:""; HUDMSG_PLAIN, 704, CR_UNTRANSLATED, 0, 0, 1);
- HudMessage(s:""; HUDMSG_PLAIN, 705, CR_UNTRANSLATED, 0, 0, 1);
- HudMessage(s:""; HUDMSG_PLAIN, 706, CR_UNTRANSLATED, 0, 0, 1);
- HudMessage(s:""; HUDMSG_PLAIN, 707, CR_UNTRANSLATED, 0, 0, 1);
- HudMessage(s:""; HUDMSG_PLAIN, 708, CR_UNTRANSLATED, 0, 0, 1);
- HudMessage(s:""; HUDMSG_PLAIN, 709, CR_UNTRANSLATED, 0, 0, 1);
- HudMessage(s:""; HUDMSG_PLAIN, 716, CR_UNTRANSLATED, 0, 0, 1);
- HudMessage(s:""; HUDMSG_PLAIN, 717, CR_UNTRANSLATED, 0, 0, 1);
- HudMessage(s:""; HUDMSG_PLAIN, 718, CR_UNTRANSLATED, 0, 0, 1);
- BeginGame();
- for (i = 0; i < 60; i++)
- {
- DrawFieldBorder();
- DrawNextPieces();
- DrawHold();
- DrawStats();
- SetKeysPressed();
- if (i == 0)
- {
- LocalAmbientSound("acstris/ready", 127);
- SetFont("BIGFONT");
- HudMessage(s:"Ready..."; HUDMSG_PLAIN, 701, CR_WHITE, x, y, 1.0);
- }
- else if (i == 30)
- {
- LocalAmbientSound("acstris/go", 127);
- SetFont("BIGFONT");
- HudMessage(s:"GO!"; HUDMSG_PLAIN, 701, CR_WHITE, x, y, 1.0);
- }
- Delay(1);
- }
- NewPiece();
- }
- else
- {
- TetrisPaused = 0;
- }
- while (!GameOver && PlayingTetris[pln])
- {
- SetKeysPressed();
- OldPaused = TetrisPaused;
- TetrisPaused = !!TetrisPaused ^ !!keyPressed(BT_USE);
- if (OldPaused != TetrisPaused) { LocalAmbientSound(PauseSounds[TetrisPaused], 127); }
- if (TetrisPaused)
- {
- DrawField();
- SetFont("BIGFONT");
- HudMessage(s:"Paused"; HUDMSG_PLAIN, 701, CR_GREEN, x, y, 1.0);
- Delay(1);
- continue;
- }
- HudMessage(s:""; HUDMSG_PLAIN, 701, CR_UNTRANSLATED, 0, 0, 1);
- if (TetKey(KEY_HOLD) == 1) { Hold(); }
- TetrisTics++;
- OldX = PieceX;
- OldY = PieceY;
- OldRot = PieceRot;
- PieceRot += (TetKey(KEY_UP) == 1) - (TetKey(KEY_DOWN) == 1) + (2 * (TetKey(KEY_SPEED) == 1));
- PieceType = mod((PieceType-1), BLOCKCOUNT) + 1;
- PieceRot = mod(PieceRot, ROTCOUNT);
- Kick();
- PieceX = MovePieceX(PieceX, PieceY, PieceType, PieceRot);
- PieceY = MovePieceY(PieceX, PieceY, PieceType, PieceRot);
- if (PieceCollides(PieceX, PieceY, PieceType, PieceRot))
- {
- PieceX = OldX;
- PieceY = OldY;
- PieceRot = OldRot;
- }
- if (PieceRot != OldRot)
- {
- LocalAmbientSound("acstris/rotate", 127);
- }
- if (PieceCollides(PieceX, PieceY+1, PieceType, PieceRot))
- {
- PieceLocking += 1;
- PieceLocking2 += 1;
- if (PieceLocking2 == 1)
- {
- LocalAmbientSound("acstris/pieceland", 127);
- }
- if (PieceLocking >= LOCKTIME || PieceLocking2 >= LOCKTIME2)
- {
- AddPiece(PieceX, PieceY, PieceType, PieceRot);
- }
- }
- else
- {
- PieceLocking = 0;
- }
- if (OldX != PieceX || OldY != PieceY || OldRot != PieceRot)
- {
- PieceLocking = 0;
- }
- if (TetKey(KEY_JUMP) == 1) { HardDrop(PieceX, PieceY, PieceType, PieceRot); }
- /*
- tolog = "";
- for (i = 0; i < NEXTCOUNT; i++)
- {
- tolog = StrParam(s:tolog, d:NextPieces[i], s:" ");
- }
- Log(s:tolog);
- */
- DrawField();
- Delay(1);
- }
- while (PlayingTetris[pln])
- {
- gameOverY = min(gameOverY + 1, MATRIX_Y);
- DrawFieldGameOver(gameOverY);
- gameovertic++;
- if (gameovertic > 35)
- {
- SetHudSize(640, 480, 1);
- SetFont("BIGFONT");
- HudMessage(s:"GAME OVER."; HUDMSG_FADEOUT, 1500, CR_WHITE, x, y, 1.0, 0.5);
- }
- if (gameovertic == 35) { LocalAmbientSound("acstris/gameover", 127); }
- if (gameovertic > 105)
- {
- SetHudSize(640, 480, 1);
- SetFont("SMALLFONT");
- HudMessage(s:"Puke script 123 to exit."; HUDMSG_FADEOUT, 1501, CR_WHITE, x, y+32.0, 1.0, 0.5);
- }
- Delay(1);
- }
- }
- script 133 ENTER
- {
- Print(s:"Puke script 123 to play ACSTris.");
- }
- script 134 OPEN clientside
- {
- while (1)
- {
- TetrisFont = TetrisFonts[middle(1, defaultCVar("tetris_skin", 1), FONTCOUNT)-1];
- Delay(1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement