Advertisement
Guest User

Untitled

a guest
Feb 21st, 2014
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.64 KB | None | 0 0
  1. package flappy.model.pillars;
  2.  
  3. import java.awt.Graphics2D;
  4.  
  5. import flappy.graphics.Sprite;
  6.  
  7. public class Pillar {
  8.  
  9.     private int x;
  10.     private int y;
  11.     private Sprite s;
  12.     private int width;
  13.     private int height;
  14.     private Sprite end;
  15.    
  16.     public Pillar(int x, int y, int height, Sprite s, Sprite s1) {
  17.         this.x = x;
  18.         this.y = y;
  19.         this.s = s;
  20.         this.height = height;
  21.         this.width = s.getWidth();
  22.         this.end = s1;
  23.     }
  24.    
  25.     public int getWidth() {
  26.         return this.width;
  27.     }
  28.    
  29.     public int getHeight() {
  30.         return this.height;
  31.     }
  32.    
  33.     public int getX() {
  34.         return this.x;
  35.     }
  36.    
  37.     public int getY() {
  38.         return this.y;
  39.     }
  40.    
  41.     public void render(Graphics2D g) {
  42.         g.drawImage(this.s.getSprite(), this.x, this.y, this.width, this.height, null);
  43.         g.drawImage(this.end.getSprite(), this.x - 1, this.y + this.height, null);
  44.     }
  45.    
  46.    
  47. }
  48.  
  49.  
  50. package flappy.model.pillars;
  51.  
  52. import java.awt.Graphics2D;
  53.  
  54. public class Pillars {
  55.  
  56.     public Pillar top;
  57.     public Pillar bottom;
  58.    
  59.     public Pillars(Pillar a, Pillar b) {
  60.         this.top = a;
  61.         this.bottom = b;
  62.     }
  63.    
  64.     public Pillar getTop() {
  65.         return this.top;
  66.     }
  67.    
  68.     public Pillar getBottom() {
  69.         return this.bottom;
  70.     }
  71.    
  72.     public void renderPillars(Graphics2D g) {
  73.         this.top.render(g);
  74.         this.bottom.render(g);
  75.     }
  76.  
  77. }
  78.  
  79. package flappy.model.pillars;
  80.  
  81. import flappy.Constants;
  82. import flappy.graphics.Sprite;
  83.  
  84. public class PillarsFactory {
  85.  
  86.     public static Pillars createPillars(int x, PillarType p) {
  87.         Pillar a = new Pillar(x, p.getTopY(), p.getTopHeight(),
  88.                 createPillarSprite(), createPillarEnd(false));
  89.         Pillar b = new Pillar(x, p.getBottomY(), p.getBottomHeight(),
  90.                 createPillarSprite(), createPillarEnd(true));
  91.         return new Pillars(a, b);
  92.     }
  93.    
  94.     private static Sprite createPillarSprite() {
  95.         return new Sprite(Constants.PILLAR);
  96.     }
  97.    
  98.     private static Sprite createPillarEnd(boolean isBottom) {
  99.         return (isBottom) ? new Sprite(Constants.END) : new Sprite(Constants.END_BOTTOM);
  100.     }
  101. }
  102.  
  103.  
  104. package flappy.model.pillars;
  105.  
  106. import flappy.Constants;
  107.  
  108. public enum PillarType {
  109.  
  110.     TOP(0, 95, Constants.HEIGHT, -290),
  111.     MIDDLE(0, 170, Constants.HEIGHT, -185),
  112.     BOTTOM(0, 250, Constants.HEIGHT, -110);
  113.    
  114.     private int topY, topHeight, bottomY, bottomHeight;
  115.    
  116.     PillarType(int topY, int topHeight, int bottomY, int bottomHeight) {
  117.         this.topY = topY;
  118.         this.topHeight = topHeight;
  119.         this.bottomY = bottomY;
  120.         this.bottomHeight = bottomHeight;
  121.     }
  122.    
  123.     public int getTopY() {
  124.         return this.topY;
  125.     }
  126.    
  127.     public int getBottomY() {
  128.         return this.bottomY;
  129.     }
  130.    
  131.     public int getTopHeight() {
  132.         return this.topHeight;
  133.     }
  134.    
  135.     public int getBottomHeight() {
  136.         return this.bottomHeight;
  137.     }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement