<commit_before>import IPoint from './interfaces/point';
import { ISize } from './interfaces/size';
import Board from './models/board';
import { getPanel } from './models/panel';
import Player from './models/player';
import clearPanel from './services/clear-panel';
import drawGrid from './services/draw-grid';
import drawMatrix from './services/draw-matrix';
import { matrixContains, matrixesColliding, mergeMatrixes } from './services/matrix-calculations';
import getRandomShape from './services/random-shape';

// Define sizes
const ctxSize: ISize = { width: 400, height: 600 };
const tileSize = 20;
const boardSize: ISize = {
    width: ctxSize.width / tileSize,
    height: ctxSize.height / tileSize
};

// Create panel
const panel = getPanel('game', ctxSize);
const board = new Board(boardSize);

// Place a random shape
const startingPoint = { x: 9, y: 0 };
const player = new Player(getRandomShape(), startingPoint);

// Update loop
function update(): void {
    // TODO: Only draw changes
    const newPos: IPoint = { x: player.position.x, y: player.position.y + 1 };

    if (board.collides(player.shape.blocks, newPos)) {
        board.place(player.shape, player.position);

        player.shape = getRandomShape();
        player.position.y = 0;
    } else {
        player.position = newPos;
    }

    draw();
}

function draw(): void {
    const viewMatrix = mergeMatrixes(board.blocks, player.shape.blocks, player.position);

    clearPanel(panel);
    drawGrid(panel, boardSize);
    drawMatrix(panel, viewMatrix, tileSize);<commit_msg>Fixed player starting position reset<commit_after>import { clonePoint } from './interfaces/point';
import { ISize } from './interfaces/size';
import Board from './models/board';
import { getPanel } from './models/panel';
import Player from './models/player';
import clearPanel from './services/clear-panel';
import drawGrid from './services/draw-grid';
import drawMatrix from './services/draw-matrix';
import { mergeMatrixes } from './services/matrix-calculations';
import getRandomShape from './services/random-shape';

// Define sizes
const ctxSize: ISize = { width: 400, height: 600 };
const tileSize = 20;
const boardSize: ISize = {
    width: ctxSize.width / tileSize,
    height: ctxSize.height / tileSize
};

// Create panel
const panel = getPanel('game', ctxSize);
const board = new Board(boardSize);

// Place a random shape
const startingPoint = { x: 9, y: 0 };
const player = new Player(getRandomShape(), clonePoint(startingPoint));

// Update loop
function update(): void {
    // TODO: Only draw changes
    const newPos = {
        x: player.position.x,
        y: player.position.y + 1
    };

    if (board.collides(player.shape.blocks, newPos)) {
        board.place(player.shape, player.position);

        player.shape = getRandomShape();
        player.position = clonePoint(startingPoint);
    } else {
        player.position = newPos;
    }

    draw();
}

function draw(): void {
    const viewMatrix = mergeMatrixes(board.blocks, player.shape.blocks, player.position);

    clearPanel(panel);
    drawGrid(panel, boardSize);
    drawMatrix(panel, viewMatrix, tileSize);
{'fraction_non_alphanumeric': 0.1354100445009536, 'fraction_numerical': 0.007310870947234584, 'mean_word_length': 3.634756995581738, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1591142', 'n_tokens_mistral': 928, 'n_tokens_neox': 894, 'n_words': 264}