Skip to content

Commit 82d5ed7

Browse files
author
AppleMaster2000
committed
Adds libGDX game
0 parents  commit 82d5ed7

27 files changed

+663
-0
lines changed

.gitignore

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
## Java
2+
3+
*.class
4+
*.war
5+
*.ear
6+
hs_err_pid*
7+
8+
## GWT
9+
war/
10+
html/war/gwt_bree/
11+
html/gwt-unitCache/
12+
.apt_generated/
13+
html/war/WEB-INF/deploy/
14+
html/war/WEB-INF/classes/
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/x86/
24+
android/gen/
25+
.idea/
26+
*.ipr
27+
*.iws
28+
*.iml
29+
out/
30+
com_crashlytics_export_strings.xml
31+
32+
## Eclipse
33+
.classpath
34+
.project
35+
.metadata
36+
**/bin/
37+
tmp/
38+
*.tmp
39+
*.bak
40+
*.swp
41+
*~.nib
42+
local.properties
43+
.settings/
44+
.loadpath
45+
.externalToolBuilders/
46+
*.launch
47+
48+
## NetBeans
49+
**/nbproject/private/
50+
build/
51+
nbbuild/
52+
dist/
53+
nbdist/
54+
nbactions.xml
55+
nb-configuration.xml
56+
57+
## Gradle
58+
59+
.gradle
60+
gradle-app.setting
61+
build/
62+
63+
## OS Specific
64+
.DS_Store

Ari/PSD/HPBar.psd

380 KB
Binary file not shown.

Ari/PSD/RunningSonic.psd

212 KB
Binary file not shown.

Ari/PSD/SonicFalling.psd

73.8 KB
Binary file not shown.

Ari/RunningSonicBlue.png

32.8 KB
Loading

Ari/RunningSonicGreen.png

35.6 KB
Loading

Ari/RunningSonicRed.png

34.8 KB
Loading

Ari/Sonic to Shadow.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Can you please change sonic to shadow please and can you add two frames of sonic falling even more to the floor.

Ari/hp-bar-new.png

135 KB
Loading

Ari/hp-bar.png

131 KB
Loading

Ari/hp-piece.png

5.45 KB
Loading

Ari/runningSonicOriginal.png

13.2 KB
Loading

build.gradle

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
buildscript {
2+
repositories {
3+
mavenCentral()
4+
}
5+
dependencies {
6+
}
7+
}
8+
9+
allprojects {
10+
apply plugin: "eclipse"
11+
apply plugin: "idea"
12+
13+
version = '1.0'
14+
ext {
15+
appName = 'Test'
16+
gdxVersion = '1.5.2'
17+
roboVMVersion = '1.0.0-beta-01'
18+
box2DLightsVersion = '1.3'
19+
ashleyVersion = '1.3.1'
20+
aiVersion = '1.4.0'
21+
}
22+
23+
repositories {
24+
mavenCentral()
25+
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
26+
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
27+
}
28+
}
29+
30+
project(":desktop") {
31+
apply plugin: "java"
32+
33+
34+
dependencies {
35+
compile project(":core")
36+
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
37+
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
38+
compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
39+
}
40+
}
41+
42+
project(":core") {
43+
apply plugin: "java"
44+
45+
46+
dependencies {
47+
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
48+
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
49+
}
50+
}
51+
52+
tasks.eclipse.doLast {
53+
delete ".project"
54+
}
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
pack.png
3+
format: RGBA8888
4+
filter: Nearest,Nearest
5+
repeat: none
6+
images/RunningSonicBlue
7+
rotate: false
8+
xy: 1, 1
9+
size: 29, 38
10+
orig: 29, 38
11+
offset: 0, 0
12+
index: 3
13+
images/RunningSonicBlue
14+
rotate: false
15+
xy: 32, 1
16+
size: 28, 38
17+
orig: 28, 38
18+
offset: 0, 0
19+
index: 11
20+
images/RunningSonicBlue
21+
rotate: false
22+
xy: 62, 1
23+
size: 23, 38
24+
orig: 23, 38
25+
offset: 0, 0
26+
index: 9
27+
images/RunningSonicBlue
28+
rotate: false
29+
xy: 87, 1
30+
size: 22, 38
31+
orig: 22, 38
32+
offset: 0, 0
33+
index: 1
34+
images/RunningSonicBlue
35+
rotate: false
36+
xy: 111, 1
37+
size: 22, 38
38+
orig: 22, 38
39+
offset: 0, 0
40+
index: 5
41+
images/RunningSonicBlue
42+
rotate: false
43+
xy: 135, 1
44+
size: 22, 38
45+
orig: 22, 38
46+
offset: 0, 0
47+
index: 13
48+
images/RunningSonicBlue
49+
rotate: false
50+
xy: 159, 1
51+
size: 21, 38
52+
orig: 21, 38
53+
offset: 0, 0
54+
index: 7
2.12 KB
Loading

core/assets/badlogic.jpg

66.9 KB
Loading

core/assets/hp-piece.png

5.45 KB
Loading

core/build.gradle

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apply plugin: "java"
2+
3+
sourceCompatibility = 1.6
4+
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
5+
6+
sourceSets.main.java.srcDirs = [ "src/" ]
7+
8+
9+
eclipse.project {
10+
name = appName + "-core"
11+
}

core/src/com/mygdx/test/Game.java

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
package com.mygdx.test;
2+
3+
import com.badlogic.gdx.ApplicationAdapter;
4+
import com.badlogic.gdx.Gdx;
5+
import com.badlogic.gdx.Input;
6+
import com.badlogic.gdx.graphics.GL20;
7+
import com.badlogic.gdx.graphics.OrthographicCamera;
8+
import com.badlogic.gdx.graphics.Texture;
9+
import com.badlogic.gdx.graphics.g2d.*;
10+
import com.badlogic.gdx.math.MathUtils;
11+
import com.badlogic.gdx.math.Rectangle;
12+
import com.badlogic.gdx.math.Vector2;
13+
//import javafx.animation.Animation;
14+
import javafx.scene.Scene;
15+
16+
public class Game extends ApplicationAdapter {
17+
SpriteBatch batch;
18+
Texture img;
19+
Rectangle rect;
20+
Vector2 speed;
21+
boolean speedChanged;
22+
OrthographicCamera camera;
23+
int x = 0;
24+
int y = 0;
25+
private Scene stage;
26+
Sprite sprite;
27+
Sprite staticSprite;
28+
boolean fullscreen;
29+
Animation sonicAnimation;
30+
float elapsedTime;
31+
TextureRegion currentFrame;
32+
33+
@Override
34+
public void create () {
35+
fullscreen = false;
36+
Gdx.graphics.setDisplayMode(1280, 720, fullscreen);
37+
batch = new SpriteBatch();
38+
img = new Texture("badlogic.jpg");
39+
rect = new Rectangle(50, 50, 100, 100);
40+
speed = new Vector2(4, 4);
41+
42+
sprite = new Sprite(img);
43+
// sprite.setPosition(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
44+
sprite.setPosition(0, 0);
45+
sonicAnimation = new Animation(.065f, new TextureAtlas("SonicWalkCut-packed/pack.atlas").getRegions(), Animation.PlayMode.LOOP);
46+
elapsedTime = 0;
47+
staticSprite = new Sprite(new TextureRegion(sonicAnimation.getKeyFrame(elapsedTime)));
48+
camera = new OrthographicCamera();
49+
camera.viewportHeight = Gdx.graphics.getHeight();
50+
camera.viewportWidth = Gdx.graphics.getWidth();
51+
camera.position.x = Gdx.graphics.getWidth()/2;
52+
camera.position.y = Gdx.graphics.getHeight()/2;
53+
camera.position.x = sprite.getX() + sprite.getWidth() / 2;
54+
camera.position.y = sprite.getY() + sprite.getHeight() / 2;
55+
// camera.translate(-Gdx.graphics.getWidth() /2, -Gdx.graphics.getHeight() / 2);
56+
57+
currentFrame = sonicAnimation.getKeyFrame(elapsedTime);
58+
}
59+
@Override
60+
public void render () {
61+
Gdx.gl.glClearColor(1, 0, 0, 1);
62+
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
63+
64+
if(Gdx.input.isKeyPressed(Input.Keys.F) && Gdx.input.isKeyJustPressed(Input.Keys.F)) {
65+
fullscreen = !fullscreen;
66+
if(!fullscreen) {
67+
Gdx.graphics.setDisplayMode(1280, 720, fullscreen);
68+
} else {
69+
70+
Gdx.graphics.setDisplayMode(1920, 1080, fullscreen);
71+
}
72+
}
73+
74+
if (Gdx.input.isKeyPressed(Input.Keys.SPACE) && Gdx.input.isKeyJustPressed(Input.Keys.SPACE)) {
75+
if (speed.x == 4 && !speedChanged) {
76+
speed.x *= 3;
77+
speed.y *= 3;
78+
speedChanged = true;
79+
} else if (speed.x != 4 && speedChanged) {
80+
speed.x = 4;
81+
speed.y = 4;
82+
speedChanged = false;
83+
}
84+
}
85+
if (speed.x == 4) {
86+
System.out.println(4);
87+
}
88+
if (speed.x != 4) {
89+
System.out.println("not 4");
90+
}
91+
if(Gdx.input.isKeyPressed(Input.Keys.D)) {
92+
sprite.setX(sprite.getX() + speed.x);
93+
camera.position.x = camera.position.x + speed.x;
94+
}
95+
96+
if(Gdx.input.isKeyPressed(Input.Keys.A)) {
97+
sprite.setX(sprite.getX() - speed.x);
98+
camera.position.x = camera.position.x - speed.x;
99+
}
100+
if(Gdx.input.isKeyPressed(Input.Keys.K)) {
101+
camera.zoom -= .01f;
102+
}
103+
if(Gdx.input.isKeyPressed(Input.Keys.L)) {
104+
camera.zoom += .01f;
105+
}
106+
if(!(rect.getX() <= 0)) {
107+
if(Gdx.input.isKeyPressed(Input.Keys.LEFT)) {
108+
rect.setX(rect.getX() - speed.x);
109+
camera.position.x = camera.position.x - speed.x;
110+
}
111+
}
112+
if (!(rect.getX() + rect.getWidth() >= Gdx.graphics.getWidth())) {
113+
if(Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
114+
rect.setX(rect.getX() + speed.x);
115+
camera.position.x = camera.position.x + speed.x;
116+
}
117+
}
118+
if(!(rect.getY() <= 0)) {
119+
if(Gdx.input.isKeyPressed(Input.Keys.DOWN)) {
120+
rect.setY(rect.getY() - speed.y);
121+
camera.position.y = camera.position.y- speed.y;
122+
}
123+
}
124+
if (!(rect.getY() + rect.getHeight() >= Gdx.graphics.getHeight())) {
125+
if(Gdx.input.isKeyPressed(Input.Keys.UP)) {
126+
rect.setY(rect.getY() + speed.y);
127+
camera.position.y = camera.position.y + speed.y;
128+
}
129+
}
130+
TextureRegion currentRegion = sonicAnimation.getKeyFrame(elapsedTime);
131+
elapsedTime += Gdx.graphics.getDeltaTime();
132+
if(currentRegion != sonicAnimation.getKeyFrame(elapsedTime)) {
133+
staticSprite.setRegion(sonicAnimation.getKeyFrame(elapsedTime));
134+
staticSprite.setSize(sonicAnimation.getKeyFrame(elapsedTime).getRegionWidth() * 3, sonicAnimation.getKeyFrame(elapsedTime).getRegionHeight() * 3);
135+
}
136+
//camera.position.x = rect.getX();
137+
//camera.position.y = rect.getY();
138+
camera.zoom = MathUtils.clamp(camera.zoom, .1f, 1f);
139+
camera.update();
140+
batch.setProjectionMatrix(camera.combined);
141+
batch.begin();
142+
staticSprite.draw(batch);
143+
//sprite.draw(batch);
144+
batch.draw(img, rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
145+
146+
batch.end();
147+
}
148+
149+
@Override
150+
public void resize(int width, int height) {
151+
// camera.viewportHeight = Gdx.graphics.getHeight();
152+
// camera.viewportWidth = Gdx.graphics.getWidth();
153+
// camera.position.x = Gdx.graphics.getWidth()/2;
154+
// camera.position.y = Gdx.graphics.getHeight()/2;
155+
// camera.update();
156+
}
157+
}

desktop/build.gradle

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
apply plugin: "java"
2+
3+
sourceCompatibility = 1.6
4+
sourceSets.main.java.srcDirs = [ "src/" ]
5+
6+
project.ext.mainClassName = "com.mygdx.test.desktop.DesktopLauncher"
7+
project.ext.assetsDir = new File("../core/assets");
8+
9+
task run(dependsOn: classes, type: JavaExec) {
10+
main = project.mainClassName
11+
classpath = sourceSets.main.runtimeClasspath
12+
standardInput = System.in
13+
workingDir = project.assetsDir
14+
ignoreExitValue = true
15+
}
16+
17+
task dist(type: Jar) {
18+
from files(sourceSets.main.output.classesDir)
19+
from files(sourceSets.main.output.resourcesDir)
20+
from {configurations.compile.collect {zipTree(it)}}
21+
from files(project.assetsDir);
22+
23+
manifest {
24+
attributes 'Main-Class': project.mainClassName
25+
}
26+
}
27+
28+
dist.dependsOn classes
29+
30+
eclipse {
31+
project {
32+
name = appName + "-desktop"
33+
linkedResource name: 'assets', type: '2', location: 'PARENT-1-PROJECT_LOC/core/assets'
34+
}
35+
}
36+
37+
task afterEclipseImport(description: "Post processing after project generation", group: "IDE") {
38+
doLast {
39+
def classpath = new XmlParser().parse(file(".classpath"))
40+
new Node(classpath, "classpathentry", [ kind: 'src', path: 'assets' ]);
41+
def writer = new FileWriter(file(".classpath"))
42+
def printer = new XmlNodePrinter(new PrintWriter(writer))
43+
printer.setPreserveWhitespace(true)
44+
printer.print(classpath)
45+
}
46+
}

0 commit comments

Comments
 (0)