Advertisement
Guest User

JPanel

a guest
Nov 28th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. package Main;
  2.  
  3.  
  4.  
  5. import java.awt.*;
  6. import java.awt.event.*;
  7.  
  8. import javax.swing.*;
  9.  
  10.  
  11. public class GamePanel extends JPanel implements ActionListener {
  12.  
  13.     private static final long serialVersionUID = 1L;
  14.     private static int STEP = 1;
  15.    
  16.     private Timer timer;
  17.     private Background bg;
  18.     private boolean win=false, isFirst=true;
  19.     private Graphics g;
  20.     private Player p;
  21.     private KeyHandler keyHandler;
  22.    
  23.     public GamePanel(){
  24.         bg=new Background();
  25.         timer = new Timer(45,this);
  26.         timer.start();
  27.         p= new Player();
  28.     }
  29.    
  30.    
  31.    
  32.    
  33.  
  34.     public void paint(Graphics g){
  35.         super.paint(g);
  36.         if(!win){
  37.             for(int x=0; x<17; x++){
  38.                 for(int y=0; y<13; y++){
  39.                     if(bg.getMap(x, y).equals("0")){
  40.                         g.drawImage(bg.getPath(), (x/2)*64, (y/2)*64, null);
  41.                     }
  42.                     if(bg.getMap(x, y).equals("1")){
  43.                         g.drawImage(bg.getWall1(), (x/2)*64-5, (y/2)*64, null);
  44.                     }
  45.                     if(bg.getMap(x, y).equals("2")){
  46.                         g.drawImage(bg.getWall2(), (x/2)*64, (y/2)*64-5, null);
  47.                     }
  48.                    
  49.                 }
  50.             }
  51.              
  52.         g.drawImage(p.getPlayer(),p.getTileX()*64,p.getTileY()*64,null);
  53.         }  
  54.     }
  55.    
  56.    
  57.     public void actionPerformed(ActionEvent e) {
  58.         if(isFirst){
  59.             g=getGraphics();
  60.         }
  61.         repaint();
  62.     }
  63.    
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement