Skip to content

Commit 946d36c

Browse files
First commit
0 parents  commit 946d36c

File tree

14 files changed

+705
-0
lines changed

14 files changed

+705
-0
lines changed

.gitignore

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
## Java
2+
3+
*.class
4+
*.war
5+
*.ear
6+
hs_err_pid*
7+
8+
## Robovm
9+
/ios/robovm-build/
10+
11+
## GWT
12+
/html/war/
13+
/html/gwt-unitCache/
14+
.apt_generated/
15+
.gwt/
16+
gwt-unitCache/
17+
www-test/
18+
.gwt-tmp/
19+
20+
## Android Studio and Intellij and Android in general
21+
/android/libs/armeabi/
22+
/android/libs/armeabi-v7a/
23+
/android/libs/arm64-v8a/
24+
/android/libs/x86/
25+
/android/libs/x86_64/
26+
/android/gen/
27+
.idea/
28+
*.ipr
29+
*.iws
30+
*.iml
31+
/android/out/
32+
com_crashlytics_export_strings.xml
33+
34+
## Eclipse
35+
36+
.classpath
37+
.project
38+
.metadata/
39+
/android/bin/
40+
/core/bin/
41+
/desktop/bin/
42+
/html/bin/
43+
/ios/bin/
44+
*.tmp
45+
*.bak
46+
*.swp
47+
*~.nib
48+
.settings/
49+
.loadpath
50+
.externalToolBuilders/
51+
*.launch
52+
53+
## NetBeans
54+
55+
/nbproject/private/
56+
/android/nbproject/private/
57+
/core/nbproject/private/
58+
/desktop/nbproject/private/
59+
/html/nbproject/private/
60+
/ios/nbproject/private/
61+
62+
/build/
63+
/android/build/
64+
/core/build/
65+
/desktop/build/
66+
/html/build/
67+
/ios/build/
68+
69+
/nbbuild/
70+
/android/nbbuild/
71+
/core/nbbuild/
72+
/desktop/nbbuild/
73+
/html/nbbuild/
74+
/ios/nbbuild/
75+
76+
/dist/
77+
/android/dist/
78+
/core/dist/
79+
/desktop/dist/
80+
/html/dist/
81+
/ios/dist/
82+
83+
/nbdist/
84+
/android/nbdist/
85+
/core/nbdist/
86+
/desktop/nbdist/
87+
/html/nbdist/
88+
/ios/nbdist/
89+
90+
nbactions.xml
91+
nb-configuration.xml
92+
93+
## Gradle
94+
95+
/local.properties
96+
.gradle/
97+
gradle-app.setting
98+
/build/
99+
/android/build/
100+
/core/build/
101+
/desktop/build/
102+
/html/build/
103+
/ios/build/
104+
105+
## OS Specific
106+
.DS_Store
107+
Thumbs.db
108+
109+
## iOS
110+
/ios/xcode/*.xcodeproj/*
111+
!/ios/xcode/*.xcodeproj/xcshareddata
112+
!/ios/xcode/*.xcodeproj/project.pbxproj
113+
/ios/xcode/native/
114+
/ios/IOSLauncher.app
115+
/ios/IOSLauncher.app.dSYM

build.gradle

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
buildscript {
2+
3+
4+
repositories {
5+
mavenLocal()
6+
mavenCentral()
7+
gradlePluginPortal()
8+
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
9+
google()
10+
}
11+
dependencies {
12+
13+
14+
}
15+
}
16+
17+
allprojects {
18+
apply plugin: "eclipse"
19+
20+
version = '1.0'
21+
ext {
22+
appName = "Dijkstra Algorithm Project"
23+
gdxVersion = '1.10.0'
24+
roboVMVersion = '2.3.12'
25+
box2DLightsVersion = '1.5'
26+
ashleyVersion = '1.7.3'
27+
aiVersion = '1.8.2'
28+
gdxControllersVersion = '2.1.0'
29+
}
30+
31+
repositories {
32+
mavenLocal()
33+
mavenCentral()
34+
google()
35+
gradlePluginPortal()
36+
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
37+
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
38+
}
39+
}
40+
41+
project(":core") {
42+
apply plugin: "java-library"
43+
44+
45+
dependencies {
46+
api "com.badlogicgames.gdx:gdx:$gdxVersion"
47+
api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
48+
49+
}
50+
}
51+
52+
project(":desktop") {
53+
apply plugin: "java-library"
54+
55+
56+
dependencies {
57+
implementation project(":core")
58+
api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
59+
api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
60+
api "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
61+
62+
}
63+
}

core/assets/badlogic.jpg

66.9 KB
Loading

core/build.gradle

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
sourceCompatibility = 1.7
2+
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
3+
4+
sourceSets.main.java.srcDirs = [ "src/" ]
5+
6+
eclipse.project.name = appName + "-core"
+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package com.dijkstra.game;
2+
3+
import com.badlogic.gdx.ApplicationAdapter;
4+
import com.badlogic.gdx.Gdx;
5+
import com.badlogic.gdx.graphics.Color;
6+
import com.badlogic.gdx.graphics.OrthographicCamera;
7+
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
8+
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
9+
import com.badlogic.gdx.math.Vector2;
10+
import com.badlogic.gdx.math.Vector3;
11+
import com.badlogic.gdx.utils.ScreenUtils;
12+
13+
public class Dijkstra extends ApplicationAdapter {
14+
public SpriteBatch batch;
15+
public OrthographicCamera camera;
16+
private ShapeRenderer shapeRenderer;
17+
18+
private Spot[][] grid;
19+
private static final int ROWS = 25;
20+
private static final int WIDTH = 600;
21+
22+
@Override
23+
public void create () {
24+
batch = new SpriteBatch();
25+
camera = new OrthographicCamera();
26+
camera.setToOrtho(false, 600, 600);
27+
shapeRenderer = new ShapeRenderer();
28+
makeGrid();
29+
}
30+
31+
@Override
32+
public void render () {
33+
ScreenUtils.clear(255, 255, 255, 0);
34+
batch.begin();
35+
drawSpots();
36+
drawGrid();
37+
batch.end();
38+
39+
if (Gdx.input.isTouched()) {
40+
Vector3 touchPos = new Vector3();
41+
touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
42+
camera.unproject(touchPos);
43+
Vector3 aux = getMousePosition(touchPos);
44+
45+
int row = (int) aux.x;
46+
int col = (int) aux.y;
47+
48+
System.out.println("row: " + row + " col: " + col);
49+
grid[row][col].setColor(Color.BLUE);
50+
}
51+
}
52+
53+
@Override
54+
public void dispose () {
55+
batch.dispose();
56+
shapeRenderer.dispose();
57+
}
58+
59+
private void makeGrid()
60+
{
61+
int gap = WIDTH / ROWS;
62+
Spot[][] aux = new Spot[ROWS][WIDTH];
63+
for(int i = 0; i < ROWS; i++)
64+
for (int j = 0; j < WIDTH; j++)
65+
aux[i][j] = new Spot(i, j, gap, ROWS);
66+
setGrid(aux);
67+
}
68+
69+
private void drawGrid()
70+
{
71+
int gap = WIDTH / ROWS;
72+
for(int i = 0; i < ROWS; i++)
73+
{
74+
drawLine(shapeRenderer, new Vector2(0, i * gap), new Vector2(WIDTH, i * gap),1 ,Color.GRAY);
75+
for(int j = 0; j < ROWS; j++)
76+
{
77+
drawLine(shapeRenderer, new Vector2(j * gap, 0), new Vector2(j * gap, WIDTH), 1, Color.GRAY);
78+
}
79+
}
80+
}
81+
82+
private void drawSpots()
83+
{
84+
for(int i = 0; i < ROWS; i++)
85+
for(int j = 0; j < WIDTH; j++)
86+
grid[i][j].drawSpot(shapeRenderer);
87+
}
88+
89+
private static void drawLine(ShapeRenderer shapeRenderer,Vector2 start, Vector2 end, int lineWidth, Color color)
90+
{
91+
Gdx.gl.glLineWidth(lineWidth);
92+
93+
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
94+
shapeRenderer.setColor(color);
95+
shapeRenderer.line(start, end);
96+
shapeRenderer.end();
97+
98+
Gdx.gl.glLineWidth(1);
99+
}
100+
101+
102+
public Vector3 getMousePosition(Vector3 pos)
103+
{
104+
int gap = WIDTH / ROWS;
105+
int x = (int) pos.x;
106+
int y =(int) pos.y;
107+
108+
int row = x / gap;
109+
int col = y / gap;
110+
111+
pos.set(row, col, 0);
112+
113+
return pos;
114+
}
115+
116+
public void setGrid(Spot[][] grid) {
117+
this.grid = grid;
118+
}
119+
}

core/src/com/dijkstra/game/Spot.java

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.dijkstra.game;
2+
3+
import com.badlogic.gdx.Game;
4+
import com.badlogic.gdx.Screen;
5+
import com.badlogic.gdx.graphics.Color;
6+
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
7+
import com.badlogic.gdx.math.Vector2;
8+
9+
public class Spot
10+
{
11+
private Vector2 pos;
12+
private Color color;
13+
private int spotWidth;
14+
private int totalRows;
15+
16+
public Spot(int row, int col, int spotWidth, int totalRows)
17+
{
18+
this.setSpotWidth(spotWidth);
19+
this.setPos(new Vector2(row * spotWidth, col * spotWidth));
20+
this.setTotalRows(totalRows);
21+
this.setColor(Color.WHITE);
22+
}
23+
24+
public void drawSpot(ShapeRenderer shapeRenderer)
25+
{
26+
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
27+
shapeRenderer.setColor(this.getColor());
28+
shapeRenderer.rect(this.getPos().x, this.getPos().y, this.getSpotWidth(), this.getSpotWidth());
29+
shapeRenderer.end();
30+
}
31+
32+
public Vector2 getPos() {
33+
return pos;
34+
}
35+
36+
public void setPos(Vector2 pos) {
37+
this.pos = pos;
38+
}
39+
40+
public Color getColor() {
41+
return color;
42+
}
43+
44+
public void setColor(Color color) {
45+
this.color = color;
46+
}
47+
48+
public int getSpotWidth() {
49+
return spotWidth;
50+
}
51+
52+
public void setSpotWidth(int spotWidth) {
53+
this.spotWidth = spotWidth;
54+
}
55+
56+
public int getTotalRows() {
57+
return totalRows;
58+
}
59+
60+
public void setTotalRows(int totalRows) {
61+
this.totalRows = totalRows;
62+
}
63+
64+
65+
}

0 commit comments

Comments
 (0)