Add ball and paddle
This commit is contained in:
		@ -2,22 +2,23 @@ package com.me.brickbuster;
 | 
			
		||||
 | 
			
		||||
import com.badlogic.gdx.ApplicationAdapter;
 | 
			
		||||
import com.badlogic.gdx.Gdx;
 | 
			
		||||
import com.badlogic.gdx.graphics.Color;
 | 
			
		||||
import com.badlogic.gdx.graphics.GL20;
 | 
			
		||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
 | 
			
		||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
 | 
			
		||||
import com.me.brickbuster.entity.Ball;
 | 
			
		||||
import com.me.brickbuster.entity.Paddle;
 | 
			
		||||
 | 
			
		||||
public class BrickBuster extends ApplicationAdapter {
 | 
			
		||||
 | 
			
		||||
    public static final int WIDTH = 800;
 | 
			
		||||
    public static final int HEIGHT = 600;
 | 
			
		||||
    public static final String TITLE = "Brick Buster";
 | 
			
		||||
	public static final int WIDTH = 800;
 | 
			
		||||
	public static final int HEIGHT = 600;
 | 
			
		||||
	public static final String TITLE = "Brick Buster";
 | 
			
		||||
 | 
			
		||||
	Ball ball;
 | 
			
		||||
	Paddle paddle;
 | 
			
		||||
 | 
			
		||||
	ShapeRenderer shapeRenderer;
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public void create () {
 | 
			
		||||
		this.shapeRenderer = new ShapeRenderer();
 | 
			
		||||
		ball = new Ball();
 | 
			
		||||
		paddle = new Paddle();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
@ -26,16 +27,14 @@ public class BrickBuster extends ApplicationAdapter {
 | 
			
		||||
 | 
			
		||||
		Gdx.gl.glClearColor(0.5f,1,1,1);
 | 
			
		||||
		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) {
 | 
			
		||||
		
 | 
			
		||||
		ball.update(dt);
 | 
			
		||||
		paddle.update(dt);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										30
									
								
								core/src/com/me/brickbuster/entity/Ball.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								core/src/com/me/brickbuster/entity/Ball.java
									
									
									
									
									
										Normal 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);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										40
									
								
								core/src/com/me/brickbuster/entity/Entity.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								core/src/com/me/brickbuster/entity/Entity.java
									
									
									
									
									
										Normal 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;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										30
									
								
								core/src/com/me/brickbuster/entity/Paddle.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								core/src/com/me/brickbuster/entity/Paddle.java
									
									
									
									
									
										Normal 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) {
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user