Guest User

Player class

a guest
Mar 29th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. package myFirstGame;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.awt.Image;
  6. import java.awt.Rectangle;
  7.  
  8. import javax.swing.ImageIcon;
  9.  
  10. public class Player {
  11.    
  12.     int Width = 15;
  13.     int Height = 20;
  14.     int x;
  15.     int y;
  16.     int speed = 2;
  17.    
  18.     public boolean imagesLoaded = false;
  19.    
  20.     boolean Jump = false;
  21.     boolean goingRight = false;
  22.     boolean goingLeft = false;
  23.     boolean goingDown = false;
  24.    
  25.     public Image player;
  26.    
  27.     Rectangle boundingBox;
  28.    
  29.         public Player(int x, int y) {
  30.             this.x = x;
  31.             this.y = y;
  32.            
  33.             boundingBox = new Rectangle(x, y, Width, Height);
  34.             boundingBox.setBounds(x, y, Width, Height);
  35.         }
  36.        
  37.         public void tick(Game game) {
  38.             boundingBox.setBounds(x, y, Width, Height);
  39.             if (Jump && y - 5>= 0) {
  40.                 y-= 3;
  41.             }
  42.             if (goingRight && x + Width + 5  <= game.getWidth()) {
  43.                 x+= 5;
  44.             }
  45.             if (goingLeft && x - 5>= 0) {
  46.                 x-= 5;
  47.             }
  48.             if (goingDown && y + Height + 5<= game.getHeight()) {
  49.                 y+= 2;
  50.             }
  51.            
  52.            
  53.         }
  54.        
  55.         public void render(Graphics g) {
  56.            
  57.             player = new ImageIcon("C:/Users/Bruker/Pictures/myGuy.PNG").getImage();
  58.            
  59.            
  60.             g.setColor(Color.blue);
  61.             g.fillRect(x, y, Width, Height);
  62.         }
  63.  
  64. }
Add Comment
Please, Sign In to add comment