Skip to content

Commit 861fa23

Browse files
committed
Efficiency, small mouse changes.
1 parent 694f353 commit 861fa23

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+16
-10
lines changed

PathFinder/Graphics.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ Graphics::Graphics(std::vector<std::vector<int>> the_maze, Coordinate start, Coo
3232
this->sprite_sheet.loadFromFile("mouse_and_cheese_sprite.png");
3333

3434
Mouse.setTexture(this->sprite_sheet);
35-
Mouse.setTextureRect(IntRect(0, 8, 75, 42));
36-
this->Mouse.setScale(2.0 / 5.0, 3.0 / 5.0);
37-
this->Mouse.setPosition(this->StartOfMaze.X * 30, this->StartOfMaze.Y * 30);
35+
Mouse.setTextureRect(IntRect(0, 10, 75, 42));
36+
this->Mouse.setScale(2.0 / 6.0, 3.0 / 6.0);
37+
this->Mouse.setPosition((this->StartOfMaze.X * 30)+15, (this->StartOfMaze.Y * 30)+15);
3838
this->Mouse.setOrigin(0, 0);
3939
Cheese.setTexture(this->sprite_sheet);
4040
Cheese.setTextureRect(IntRect(160, 8, 75, 50));
@@ -99,6 +99,7 @@ void Graphics::update()
9999
int y = 0;
100100
int x = 0;
101101

102+
102103
for (int square_counter = 0; square_counter < squares.size(); square_counter++)
103104
{
104105
if (std::find(path.begin(), path.end(), Coordinate(x, y)) != path.end()) {
@@ -121,23 +122,23 @@ void Graphics::update()
121122
}
122123
if (mouse_pos < path.size())
123124
{
124-
if(this->Mouse.getPosition().x < path[mouse_pos].X*30)
125+
if(this->Mouse.getPosition().x < (path[mouse_pos].X*30)+15)
125126
{
126127
this->move_mouse_right();
127128
}
128-
else if (this->Mouse.getPosition().x > path[mouse_pos].X * 30)
129+
else if (this->Mouse.getPosition().x > (path[mouse_pos].X * 30)+15)
129130
{
130131
this->move_mouse_left();
131132
}
132-
else if (this->Mouse.getPosition().y < path[mouse_pos].Y * 30)
133+
else if (this->Mouse.getPosition().y < (path[mouse_pos].Y * 30)+15)
133134
{
134135
this->move_mouse_down();
135136
}
136-
else if (this->Mouse.getPosition().y > path[mouse_pos].Y * 30)
137+
else if (this->Mouse.getPosition().y > (path[mouse_pos].Y * 30)+15)
137138
{
138139
this->move_mouse_up();
139140
}
140-
else if (this->Mouse.getPosition().x == path[mouse_pos].X * 30 && this->Mouse.getPosition().y == path[mouse_pos].Y * 30)
141+
else if (this->Mouse.getPosition().x == (path[mouse_pos].X * 30)+15 && this->Mouse.getPosition().y == (path[mouse_pos].Y * 30)+15)
141142
{
142143
mouse_pos++;
143144
}
@@ -148,11 +149,11 @@ void Graphics::update()
148149
}
149150
if (this->Mouse.getRotation() == 90 || this->Mouse.getRotation() == 180)
150151
{
151-
this->Mouse.setOrigin(75, 42);
152+
this->Mouse.setOrigin(75/2, 42/2);
152153
}
153154
else
154155
{
155-
this->Mouse.setOrigin(0, 0);
156+
this->Mouse.setOrigin(75/2, 42/2);
156157
; }
157158
for (int i = 0; i < squares.size(); i++)
158159
{

PathFinder/PathFinder.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ void PathFinder::BranchAll(Coordinate Start, std::vector<Coordinate> OldPath, Br
5757
//Actually add coordinates to the path...
5858
Path.push_back(Start);
5959

60+
//If it exceeds any first path found, it will delete itself since it knows it's longer and worthless garbage, and it should feel bad about itself!
61+
if (AllPaths.size() > 0 && Path.size() >= GetShortest(EndOfMaze).size())
62+
{
63+
return;
64+
}
6065

6166

6267
//Check it's not at the end!
76.5 KB
Binary file not shown.
794 KB
Binary file not shown.
1.63 MB
Binary file not shown.
838 KB
Binary file not shown.
39 KB
Binary file not shown.
972 KB
Binary file not shown.
971 KB
Binary file not shown.
57 KB
Binary file not shown.

0 commit comments

Comments
 (0)