Skip to content
This repository was archived by the owner on Aug 15, 2019. It is now read-only.

Commit c360627

Browse files
committed
Added game project
1 parent fc5e935 commit c360627

File tree

73 files changed

+1275
-4
lines changed

Some content is hidden

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

73 files changed

+1275
-4
lines changed

Pong-html/.gwt/.gwt-log

+92
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,95 @@ Public resources found in...
3434
Translatable source found in...
3535
Found 0 cached/archived units. Used 0 / 2719 units from cache.
3636
Compiling...
37+
10% complete (ETR: 23 seconds)
38+
10% complete (ETR: 23 seconds)
39+
20% complete (ETR: 21 seconds)
40+
30% complete (ETR: 16 seconds)
41+
40% complete (ETR: 13 seconds)
42+
50% complete (ETR: 9 seconds)
43+
60% complete (ETR: 7 seconds)
44+
70% complete (ETR: 5 seconds)
45+
80% complete (ETR: 3 seconds)
46+
90% complete (ETR: 1 seconds)
47+
100% complete (ETR: 0 seconds)
48+
Compilation completed in 74.64 seconds
49+
Removing invalidated units
50+
Finding entry point classes
51+
Public resources found in...
52+
Translatable source found in...
53+
Found 2719 cached/archived units. Used 2719 / 2719 units from cache.
54+
Compiling...
55+
Compilation completed in 0.00 seconds
56+
Removing invalidated units
57+
Finding entry point classes
58+
Public resources found in...
59+
Translatable source found in...
60+
Found 2719 cached/archived units. Used 2719 / 2719 units from cache.
61+
Compiling...
62+
Compilation completed in 0.00 seconds
63+
Removing invalidated units
64+
Finding entry point classes
65+
Public resources found in...
66+
Translatable source found in...
67+
Found 0 cached/archived units. Used 0 / 2719 units from cache.
68+
Compiling...
69+
10% complete (ETR: 41 seconds)
70+
10% complete (ETR: 41 seconds)
71+
20% complete (ETR: 28 seconds)
72+
30% complete (ETR: 21 seconds)
73+
40% complete (ETR: 16 seconds)
74+
50% complete (ETR: 12 seconds)
75+
60% complete (ETR: 9 seconds)
76+
70% complete (ETR: 6 seconds)
77+
80% complete (ETR: 4 seconds)
78+
90% complete (ETR: 2 seconds)
79+
100% complete (ETR: 0 seconds)
80+
Compilation completed in 21.03 seconds
81+
Removing invalidated units
82+
Finding entry point classes
83+
Public resources found in...
84+
Translatable source found in...
85+
Found 2719 cached/archived units. Used 2719 / 2719 units from cache.
86+
Compiling...
87+
Compilation completed in 0.00 seconds
88+
Removing invalidated units
89+
Finding entry point classes
90+
Public resources found in...
91+
Translatable source found in...
92+
Found 2719 cached/archived units. Used 2719 / 2719 units from cache.
93+
Compiling...
94+
Compilation completed in 0.00 seconds
95+
Removing invalidated units
96+
Finding entry point classes
97+
Public resources found in...
98+
Translatable source found in...
99+
Found 0 cached/archived units. Used 0 / 2719 units from cache.
100+
Compiling...
101+
0% complete (ETR: 46 seconds)
102+
10% complete (ETR: 46 seconds)
103+
20% complete (ETR: 27 seconds)
104+
30% complete (ETR: 19 seconds)
105+
40% complete (ETR: 14 seconds)
106+
50% complete (ETR: 10 seconds)
107+
60% complete (ETR: 7 seconds)
108+
70% complete (ETR: 5 seconds)
109+
80% complete (ETR: 3 seconds)
110+
90% complete (ETR: 1 seconds)
111+
100% complete (ETR: 0 seconds)
112+
Compilation completed in 80.07 seconds
113+
Removing invalidated units
114+
Finding entry point classes
115+
Public resources found in...
116+
Translatable source found in...
117+
Found 2719 cached/archived units. Used 2719 / 2719 units from cache.
118+
Compiling...
119+
Compilation completed in 0.00 seconds
120+
Removing invalidated units
121+
Finding entry point classes
122+
Public resources found in...
123+
Translatable source found in...
124+
Found 2719 cached/archived units. Used 2719 / 2719 units from cache.
125+
Compiling...
126+
Compilation completed in 0.00 seconds
127+
Removing invalidated units
128+
Finding entry point classes

Pong-html/war/WEB-INF/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/classes
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.mvmgd.pong;
2+
3+
import com.badlogic.gdx.physics.box2d.Contact;
4+
import com.badlogic.gdx.physics.box2d.ContactImpulse;
5+
import com.badlogic.gdx.physics.box2d.ContactListener;
6+
import com.badlogic.gdx.physics.box2d.Manifold;
7+
8+
public class CollisionListener implements ContactListener {
9+
10+
@Override
11+
public void beginContact(Contact contact) {
12+
System.out.println("ITS A COLLISIOn");
13+
}
14+
15+
@Override
16+
public void endContact(Contact contact) {
17+
System.out.println("ITS A COLLISIOn end");
18+
}
19+
20+
@Override
21+
public void preSolve(Contact contact, Manifold oldManifold) {
22+
// TODO Auto-generated method stub
23+
24+
}
25+
26+
@Override
27+
public void postSolve(Contact contact, ContactImpulse impulse) {
28+
// TODO Auto-generated method stub
29+
30+
}
31+
32+
}

Pong/src/com/mvmgd/pong/Global.java

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.mvmgd.pong;
2+
3+
import com.badlogic.gdx.physics.box2d.World;
4+
5+
public class Global {
6+
public static final float PHYSICS_SCALE = 1/50f;
7+
public static World world;
8+
}
+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.mvmgd.pong.actor;
2+
3+
import com.badlogic.gdx.graphics.g2d.Batch;
4+
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
5+
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
6+
import com.badlogic.gdx.physics.box2d.Body;
7+
import com.badlogic.gdx.physics.box2d.BodyDef;
8+
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
9+
import com.badlogic.gdx.physics.box2d.CircleShape;
10+
import com.badlogic.gdx.physics.box2d.FixtureDef;
11+
import com.badlogic.gdx.scenes.scene2d.Actor;
12+
import com.mvmgd.pong.Global;
13+
14+
public class Ball extends Actor {
15+
private AtlasRegion region;
16+
private float speed = 5;
17+
private Body body;
18+
19+
public Ball(TextureAtlas atlas) {
20+
region = atlas.findRegion("ball");
21+
BodyDef bDef = new BodyDef();
22+
bDef.type = BodyType.DynamicBody;
23+
body = Global.world.createBody(bDef);
24+
25+
CircleShape shape = new CircleShape();
26+
shape.setRadius(32 * Global.PHYSICS_SCALE);
27+
28+
FixtureDef fDef = new FixtureDef();
29+
fDef.shape = shape;
30+
fDef.restitution = 2;
31+
fDef.density = 1;
32+
33+
body.createFixture(fDef);
34+
body.setUserData(this);
35+
36+
shape.dispose();
37+
38+
}
39+
40+
@Override
41+
public void translate(float x, float y) {
42+
super.translate(x, y);
43+
44+
body.setTransform((getX() + x) * Global.PHYSICS_SCALE, (getY() + y) * Global.PHYSICS_SCALE, 0);
45+
}
46+
47+
@Override
48+
public void setPosition(float x, float y) {
49+
super.setPosition(x, y);
50+
body.setTransform((x) * Global.PHYSICS_SCALE, (y) * Global.PHYSICS_SCALE, 0);
51+
}
52+
53+
@Override
54+
public void setX(float x) {
55+
super.setX(x);
56+
57+
body.setTransform((x) * Global.PHYSICS_SCALE, (getY()) * Global.PHYSICS_SCALE, 0);
58+
}
59+
60+
@Override
61+
public void act(float delta) {
62+
63+
}
64+
65+
@Override
66+
public void draw(Batch batch, float parentAlpha) {
67+
batch.draw(region, getX(), getY());
68+
}
69+
}

Pong/src/com/mvmgd/pong/actor/Paddle.java

+47-2
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,70 @@
33
import com.badlogic.gdx.graphics.g2d.Batch;
44
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
55
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
6+
import com.badlogic.gdx.physics.box2d.Body;
7+
import com.badlogic.gdx.physics.box2d.BodyDef;
8+
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
9+
import com.badlogic.gdx.physics.box2d.Fixture;
10+
import com.badlogic.gdx.physics.box2d.FixtureDef;
11+
import com.badlogic.gdx.physics.box2d.PolygonShape;
612
import com.badlogic.gdx.scenes.scene2d.Actor;
13+
import com.mvmgd.pong.Global;
714

815
public class Paddle extends Actor {
916
private AtlasRegion region;
1017
private boolean moveUp, moveDown;
1118
private static final int speed = 5;
19+
private Body body;
1220

1321
public Paddle(TextureAtlas atlas) {
1422
region = atlas.findRegion("paddle");
23+
setSize(region.originalWidth, region.originalHeight);
24+
25+
BodyDef bDef = new BodyDef();
26+
bDef.type = BodyType.KinematicBody;
27+
body = Global.world.createBody(bDef);
28+
29+
PolygonShape shape = new PolygonShape();
30+
shape.setAsBox(16 * Global.PHYSICS_SCALE, 128 * Global.PHYSICS_SCALE);
31+
32+
FixtureDef fDef = new FixtureDef();
33+
fDef.shape = shape;
34+
fDef.isSensor = true;
35+
36+
body.createFixture(fDef);
37+
body.setUserData(this);
38+
39+
shape.dispose();
40+
41+
}
42+
43+
@Override
44+
public void translate(float x, float y) {
45+
super.translate(x, y);
46+
47+
body.setTransform((getX() + x + getWidth()/2) * Global.PHYSICS_SCALE, (getY() + y + getHeight()/2) * Global.PHYSICS_SCALE, 0);
48+
}
49+
50+
@Override
51+
public void setX(float x) {
52+
super.setX(x);
53+
54+
body.setTransform((x + getWidth()/2) * Global.PHYSICS_SCALE, (getY() + getHeight()/2) * Global.PHYSICS_SCALE, 0);
1555
}
1656

1757
@Override
1858
public void act(float delta) {
59+
setPosition(body.getPosition().x / Global.PHYSICS_SCALE, body.getPosition().y / Global.PHYSICS_SCALE);
60+
float s = 0;
61+
1962
if(moveUp) {
20-
translate(0, speed);
63+
s += speed;
2164
}
2265
if(moveDown) {
23-
translate(0, -speed);
66+
s -= speed;
2467
}
68+
69+
body.setLinearVelocity(0, s);
2570
}
2671

2772
public void moveUp(boolean move) {
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.mvmgd.pong.actor;
2+
3+
import com.badlogic.gdx.Gdx;
4+
import com.badlogic.gdx.physics.box2d.Body;
5+
import com.badlogic.gdx.physics.box2d.BodyDef;
6+
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
7+
import com.badlogic.gdx.physics.box2d.FixtureDef;
8+
import com.badlogic.gdx.physics.box2d.PolygonShape;
9+
import com.badlogic.gdx.scenes.scene2d.Actor;
10+
import com.mvmgd.pong.Global;
11+
12+
public class Wall extends Actor {
13+
private Body body;
14+
15+
public Wall(float y) {
16+
17+
BodyDef bDef = new BodyDef();
18+
bDef.type = BodyType.StaticBody;
19+
bDef.position.set(Gdx.graphics.getWidth()/2 * Global.PHYSICS_SCALE, y * Global.PHYSICS_SCALE);
20+
body = Global.world.createBody(bDef);
21+
22+
PolygonShape shape = new PolygonShape();
23+
shape.setAsBox(Gdx.graphics.getWidth() * Global.PHYSICS_SCALE, 20 * Global.PHYSICS_SCALE);
24+
25+
FixtureDef fDef = new FixtureDef();
26+
fDef.shape = shape;
27+
fDef.isSensor = true;
28+
29+
body.createFixture(fDef);
30+
body.setUserData(this);
31+
32+
shape.dispose();
33+
34+
}
35+
36+
@Override
37+
public void act(float delta) {
38+
}
39+
}

Pong/src/com/mvmgd/pong/screen/GameScreen.java

+24-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,27 @@
77
import com.badlogic.gdx.graphics.GL10;
88
import com.badlogic.gdx.graphics.OrthographicCamera;
99
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
10+
import com.badlogic.gdx.math.Vector2;
11+
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
12+
import com.badlogic.gdx.physics.box2d.World;
1013
import com.badlogic.gdx.scenes.scene2d.InputEvent;
1114
import com.badlogic.gdx.scenes.scene2d.Stage;
1215
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
16+
import com.mvmgd.pong.CollisionListener;
17+
import com.mvmgd.pong.Global;
18+
import com.mvmgd.pong.actor.Ball;
1319
import com.mvmgd.pong.actor.Paddle;
20+
import com.mvmgd.pong.actor.Wall;
1421

1522
public class GameScreen implements Screen {
1623
private Stage stage;
24+
Box2DDebugRenderer debug;
1725

1826
public GameScreen() {
27+
Global.world = new World(new Vector2(), true);
28+
Global.world.setContactListener(new CollisionListener());
29+
debug = new Box2DDebugRenderer();
30+
1931
Camera camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
2032
stage = new Stage();
2133
Gdx.input.setInputProcessor(stage);
@@ -25,11 +37,17 @@ public GameScreen() {
2537

2638
final Paddle paddle = new Paddle(atlas);
2739
stage.addActor(paddle);
28-
40+
2941
final Paddle paddle2 = new Paddle(atlas);
3042
paddle2.setX(Gdx.graphics.getWidth()-32);
3143
stage.addActor(paddle2);
32-
Gdx.app.log("lots of", "butts");//This is the most important line of code
44+
45+
Ball ball = new Ball(atlas);
46+
stage.addActor(ball);
47+
48+
Wall bWall = new Wall(0);
49+
Wall tWall = new Wall(Gdx.graphics.getHeight());
50+
3351
stage.addListener(new ClickListener() {
3452
@Override
3553
public boolean keyDown(InputEvent event, int keycode) {
@@ -72,8 +90,12 @@ public void render(float delta) {
7290
Gdx.gl.glClearColor(1, 1, 1, 1);
7391
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
7492

93+
Global.world.step(delta, 6, 2);
94+
7595
stage.act(delta);
7696
stage.draw();
97+
98+
debug.render(Global.world, stage.getCamera().combined.scl(1/Global.PHYSICS_SCALE));
7799
}
78100

79101
@Override

mgdc-android/.classpath

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="src" path="gen"/>
5+
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/mgdc"/>
6+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
7+
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
8+
<classpathentry exported="true" kind="lib" path="/mgdc/libs/gdx.jar" sourcepath="/mgdc/libs/gdx-sources.jar"/>
9+
<classpathentry exported="true" kind="lib" path="libs/gdx-backend-android.jar" sourcepath="libs/gdx-backend-android-sources.jar"/>
10+
<classpathentry exported="true" kind="lib" path="/mgdc/libs/bodyeditor-loader.jar" sourcepath="/mgdc/libs/bodyeditor-loader-sources.jar"/>
11+
<classpathentry exported="true" kind="lib" path="/mgdc/libs/tween-engine-api.jar" sourcepath="/mgdc/libs/tween-engine-api-sources.jar"/>
12+
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
13+
<classpathentry kind="output" path="bin/classes"/>
14+
</classpath>

0 commit comments

Comments
 (0)