fixed some performance things

This commit is contained in:
MrDonuts
2023-11-20 23:25:38 -05:00
parent a875a4ed57
commit 7af60685db
7 changed files with 15 additions and 21 deletions

View File

@@ -12,12 +12,12 @@ var defaultSquareSpacing = 5
var minBorder = 20
var ScoreOffset = 50
var HighScoreOffset = 10
var GameGrid Grid
var GameGrid *Grid
var MaxGridDimension = 20
type Grid struct {
squareSpacing int
squares [][]Square
squares [][]*Square
startX int
startY int
squareSize int
@@ -77,14 +77,14 @@ func BuildGrid(numRows int, numColumns int) {
grd.startY = currentY
grd.squareSize = sqSize
table := make([][]Square, numRows)
table := make([][]*Square, numRows)
for i := 0; i < numRows; i++ {
row := make([]Square, numColumns)
row := make([]*Square, numColumns)
for j := 0; j < numColumns; j++ {
sq := MakeSquare(sqSize)
sq.SetPosition(currentX, currentY)
row[j] = sq
row[j] = &sq
currentX += sqSize + grd.squareSpacing
}
table[i] = row
@@ -133,7 +133,7 @@ func BuildGrid(numRows int, numColumns int) {
}
grd.coloredSquaresRemaining = squaresToColour
GameGrid = grd
GameGrid = &grd
}
func (grd *Grid) Draw(screen *ebiten.Image) {
@@ -174,7 +174,7 @@ func (grd *Grid) ChangeColour(row int, column int, clr color.Color) {
}
func (grd *Grid) GetSquareAt(row int, column int) *Square {
return &grd.squares[row-1][column-1]
return grd.squares[row-1][column-1]
}
func (grd *Grid) ColouredSquaresRemaining() int {

View File

@@ -21,7 +21,7 @@ var CurrentEnergy = defaultStartingEnergy
var CurrentLevel = 1
type Player struct {
square Square
square *Square
row int
col int
currColorIndex int
@@ -41,7 +41,7 @@ func SetupPlayer() {
sq.SetPosition(gridSq.x, gridSq.y)
//setup struct for passing around
ply := Player{square: sq, row: rows, col: 1, currColorIndex: 0}
ply := Player{square: &sq, row: rows, col: 1, currColorIndex: 0}
MainPlayer = &ply
}