public void initGridPositions(bool allowExit, int holeRows, int holeColumns, int spacing) { // calculate the cell holes for the task int numHoles = holeRows * holeColumns; // create the array of cells for the task moleCells = new List <MoleCell>(0); for (int i = 0; i < numHoles; i++) { if ((i % holeColumns == 0 || i <= holeColumns) && (i != 2 || !allowExit)) { moleCells.Add(new MoleCell(0, 0, 0, 0, MoleCell.CellType.Empty)); } else if (i == 2 && allowExit) { moleCells.Add(new MoleCell(0, 0, 0, 0, MoleCell.CellType.Exit)); } else { moleCells.Add(new MoleCell(0, 0, 0, 0, MoleCell.CellType.Hole)); } } // Store hole parameters for drawing later this.holeRows = holeRows; this.holeColumns = holeColumns; this.spacing = spacing; // Calculate maximum possible size of holes holeOffsetX = 0; holeOffsetY = 0; if (getContentWidth() / holeColumns > getContentHeight() / holeRows) { holeSize = (int)Math.Floor((double)((getContentHeight() - (spacing * (holeRows + 1))) / holeRows)); } else { holeSize = (int)Math.Floor((double)((getContentWidth() - (spacing * (holeColumns + 1))) / holeColumns)); } // set the x and y offset holeOffsetX = (getContentWidth() - holeColumns * holeSize - spacing * (holeColumns + 1)) / 2; holeOffsetY = (getContentHeight() - holeRows * holeSize - spacing * (holeRows + 1)) / 2; // Loop through the holes for (int i = 0; i < moleCells.Count; i++) { // calculate the row and column index (0 based) int row = (int)Math.Floor((double)(i / holeColumns)); int column = i - (row * holeColumns); // retrieve the reference to the hole MoleCell cell = moleCells[i]; // Set position and size cell.x = holeOffsetX + spacing + column * (holeSize + spacing); cell.y = holeOffsetY + spacing + row * (holeSize + spacing); cell.height = holeSize; cell.width = holeSize; } }
protected override void render() { // check if fixation should be shown if (showFixation) { // set the fixation to white glColor3(1f, 1f, 1f); // set the text count int fixationTextWidth = fixationFont.getTextWidth("+"); fixationFont.printLine((int)((getContentWidth() - fixationTextWidth) / 2), (int)((getContentHeight() - fixationFont.height) / 2), "+"); } if (showCountDown >= 0) { // set the countdown to white glColor3(1f, 1f, 1f); // set the text count int countTextWidth = countdownFont.getTextWidth(showCountDown.ToString()); countdownFont.printLine((int)((getContentWidth() - countTextWidth) / 2), (int)((getContentHeight() - countdownFont.height) / 2), showCountDown.ToString()); } // Check if we should draw grid if (showGrid) { // loop through the holes for (int i = 0; i < moleCells.Count; i++) { // retrieve hole reference MoleCell cell = moleCells[i]; if (cell.type == MoleCell.CellType.Hole || cell.type == MoleCell.CellType.Mole || cell.type == MoleCell.CellType.Exit) { // set white color for drawing glColor3(1f, 1f, 1f); // set texture if (cell.type == MoleCell.CellType.Hole) { glBindTexture2D(holeTexture); } else if (cell.type == MoleCell.CellType.Exit) { glBindTexture2D(exitTexture); } else { glBindTexture2D(moleTexture); } // draw hole glBeginTriangles(); // vertex 0 glTexCoord2(1.0f, 1.0f); glVertex3(cell.x + cell.width, cell.y + cell.height, 0.0f); glTexCoord2(1.0f, 0.0f); glVertex3(cell.x + cell.width, cell.y, 0.0f); glTexCoord2(0.0f, 0.0f); glVertex3(cell.x, cell.y, 0.0f); //vertex 1 glTexCoord2(0.0f, 1.0f); glVertex3(cell.x, cell.y + cell.height, 0.0f); glTexCoord2(1.0f, 1.0f); glVertex3(cell.x + cell.width, cell.y + cell.height, 0.0f); glTexCoord2(0.0f, 0.0f); glVertex3(cell.x, cell.y, 0.0f); glEnd(); } } // check if the selection should be drawn if (selectionWidth != 0 && selectionHeight != 0) { // set the color float colorR = 1, colorG = 1, colorB = 0; if (selected) { colorG = 0; } // draw selection drawRectangle(selectionX, selectionY, (selectionX + selectionWidth), (selectionY + selectionHeight), 5, colorR, colorG, colorB); } } // write the score text if (score > -1) { glColor3(1f, 1f, 1f); scoreFont.printLine(getContentWidth() - scoreFont.height * 9, 5, ("Score: " + score)); } // check if text should be shown if (showText.Length != 0) { // set the text to white glColor3(1f, 1f, 1f); // print the text textFont.printLine((getContentWidth() - showTextWidth) / 2, getContentHeight() / 2, showText); } // check if there is no signal if (showConnectionLost) { // set white color for drawing glColor3(1f, 1f, 1f); // print text int textWidth = textFont.getTextWidth("Lost connection with device"); textFont.printLine((int)((getContentWidth() - textWidth) / 2), (int)((getContentHeight()) / 4), "Lost connection with device"); // set texture glBindTexture2D(connectionLostTexture); // draw texture glBeginTriangles(); // vertex 0 glTexCoord2(0.0f, 0.0f); glVertex3((getContentWidth() - 200) / 2, (getContentHeight() - 200) / 2, 0.0f); glTexCoord2(1.0f, 0.0f); glVertex3((getContentWidth() - 200) / 2 + 200, (getContentHeight() - 200) / 2, 0.0f); glTexCoord2(1.0f, 1.0f); glVertex3((getContentWidth() - 200) / 2 + 200, (getContentHeight() - 200) / 2 + 200, 0.0f); //vertex 1 glTexCoord2(0.0f, 0.0f); glVertex3((getContentWidth() - 200) / 2, (getContentHeight() - 200) / 2, 0.0f); glTexCoord2(1.0f, 1.0f); glVertex3((getContentWidth() - 200) / 2 + 200, (getContentHeight() - 200) / 2 + 200, 0.0f); glTexCoord2(0.0f, 1.0f); glVertex3((getContentWidth() - 200) / 2, (getContentHeight() - 200) / 2 + 200, 0.0f); glEnd(); } }