Add ball and paddle

This commit is contained in:
BlueNutterfly 2018-11-10 22:30:23 +04:00
parent c9fda66879
commit bb6ecf2923
4 changed files with 114 additions and 15 deletions

View File

@ -2,10 +2,9 @@ package com.me.brickbuster;
import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.me.brickbuster.entity.Ball;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType; import com.me.brickbuster.entity.Paddle;
public class BrickBuster extends ApplicationAdapter { public class BrickBuster extends ApplicationAdapter {
@ -13,11 +12,13 @@ public class BrickBuster extends ApplicationAdapter {
public static final int HEIGHT = 600; public static final int HEIGHT = 600;
public static final String TITLE = "Brick Buster"; public static final String TITLE = "Brick Buster";
ShapeRenderer shapeRenderer; Ball ball;
Paddle paddle;
@Override @Override
public void create () { public void create () {
this.shapeRenderer = new ShapeRenderer(); ball = new Ball();
paddle = new Paddle();
} }
@Override @Override
@ -26,16 +27,14 @@ public class BrickBuster extends ApplicationAdapter {
Gdx.gl.glClearColor(0.5f,1,1,1); Gdx.gl.glClearColor(0.5f,1,1,1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
this.shapeRenderer.begin(ShapeType.Filled);
this.shapeRenderer.setColor(Color.CHARTREUSE);
this.shapeRenderer.circle(0,0, 100, 50);
this.shapeRenderer.end();
ball.render();
paddle.render();
} }
@Override
public void update(float dt) { public void update(float dt) {
ball.update(dt);
paddle.update(dt);
} }
@Override @Override

View File

@ -0,0 +1,30 @@
package com.me.brickbuster.entity;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.me.brickbuster.BrickBuster;
public class Ball extends Entity {
public static final int RADIUS = 25;
public static final Color BALL_COLOR = Color.CHARTREUSE;
public Ball() {
super(400, 300);
}
@Override
public void render() {
getShapeRenderer().begin(ShapeRenderer.ShapeType.Filled);
getShapeRenderer().setColor(BALL_COLOR);
getShapeRenderer().circle(this.getX(), this.getY(), RADIUS, 50);
getShapeRenderer().end();
}
@Override
public void update(float dt) {
if (this.getX() + RADIUS < BrickBuster.WIDTH) {
this.setX(this.getX() + 1);
}
}
}

View File

@ -0,0 +1,40 @@
package com.me.brickbuster.entity;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
public abstract class Entity {
private ShapeRenderer shapeRenderer;
private int x, y;
public Entity(int x, int y) {
this.shapeRenderer = new ShapeRenderer();
this.x = x;
this.y = y;
}
public abstract void render();
public abstract void update(float dt);
public ShapeRenderer getShapeRenderer() {
return shapeRenderer;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}

View File

@ -0,0 +1,30 @@
package com.me.brickbuster.entity;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.me.brickbuster.BrickBuster;
public class Paddle extends Entity {
public static final Color PADDLE_COLOR = Color.BLACK;
public static final int PADDLE_WIDTH = 50;
public static final int PADDLE_HEIGHT = 15;
public Paddle() {
super(BrickBuster.WIDTH/2, 50);
}
@Override
public void render() {
getShapeRenderer().begin(ShapeRenderer.ShapeType.Filled);
getShapeRenderer().setColor(PADDLE_COLOR);
getShapeRenderer().rect(getX() - (PADDLE_WIDTH/2), getY() - (PADDLE_HEIGHT/2), PADDLE_WIDTH, PADDLE_HEIGHT);
getShapeRenderer().end();
}
@Override
public void update(float dt) {
}
}