Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package flappy.model.pillars;
- import java.awt.Graphics2D;
- import flappy.graphics.Sprite;
- public class Pillar {
- private int x;
- private int y;
- private Sprite s;
- private int width;
- private int height;
- private Sprite end;
- public Pillar(int x, int y, int height, Sprite s, Sprite s1) {
- this.x = x;
- this.y = y;
- this.s = s;
- this.height = height;
- this.width = s.getWidth();
- this.end = s1;
- }
- public int getWidth() {
- return this.width;
- }
- public int getHeight() {
- return this.height;
- }
- public int getX() {
- return this.x;
- }
- public int getY() {
- return this.y;
- }
- public void render(Graphics2D g) {
- g.drawImage(this.s.getSprite(), this.x, this.y, this.width, this.height, null);
- g.drawImage(this.end.getSprite(), this.x - 1, this.y + this.height, null);
- }
- }
- package flappy.model.pillars;
- import java.awt.Graphics2D;
- public class Pillars {
- public Pillar top;
- public Pillar bottom;
- public Pillars(Pillar a, Pillar b) {
- this.top = a;
- this.bottom = b;
- }
- public Pillar getTop() {
- return this.top;
- }
- public Pillar getBottom() {
- return this.bottom;
- }
- public void renderPillars(Graphics2D g) {
- this.top.render(g);
- this.bottom.render(g);
- }
- }
- package flappy.model.pillars;
- import flappy.Constants;
- import flappy.graphics.Sprite;
- public class PillarsFactory {
- public static Pillars createPillars(int x, PillarType p) {
- Pillar a = new Pillar(x, p.getTopY(), p.getTopHeight(),
- createPillarSprite(), createPillarEnd(false));
- Pillar b = new Pillar(x, p.getBottomY(), p.getBottomHeight(),
- createPillarSprite(), createPillarEnd(true));
- return new Pillars(a, b);
- }
- private static Sprite createPillarSprite() {
- return new Sprite(Constants.PILLAR);
- }
- private static Sprite createPillarEnd(boolean isBottom) {
- return (isBottom) ? new Sprite(Constants.END) : new Sprite(Constants.END_BOTTOM);
- }
- }
- package flappy.model.pillars;
- import flappy.Constants;
- public enum PillarType {
- TOP(0, 95, Constants.HEIGHT, -290),
- MIDDLE(0, 170, Constants.HEIGHT, -185),
- BOTTOM(0, 250, Constants.HEIGHT, -110);
- private int topY, topHeight, bottomY, bottomHeight;
- PillarType(int topY, int topHeight, int bottomY, int bottomHeight) {
- this.topY = topY;
- this.topHeight = topHeight;
- this.bottomY = bottomY;
- this.bottomHeight = bottomHeight;
- }
- public int getTopY() {
- return this.topY;
- }
- public int getBottomY() {
- return this.bottomY;
- }
- public int getTopHeight() {
- return this.topHeight;
- }
- public int getBottomHeight() {
- return this.bottomHeight;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement