Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package myFirstGame;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.Rectangle;
- import javax.swing.ImageIcon;
- public class Player {
- int Width = 15;
- int Height = 20;
- int x;
- int y;
- int speed = 2;
- public boolean imagesLoaded = false;
- boolean Jump = false;
- boolean goingRight = false;
- boolean goingLeft = false;
- boolean goingDown = false;
- public Image player;
- Rectangle boundingBox;
- public Player(int x, int y) {
- this.x = x;
- this.y = y;
- boundingBox = new Rectangle(x, y, Width, Height);
- boundingBox.setBounds(x, y, Width, Height);
- }
- public void tick(Game game) {
- boundingBox.setBounds(x, y, Width, Height);
- if (Jump && y - 5>= 0) {
- y-= 3;
- }
- if (goingRight && x + Width + 5 <= game.getWidth()) {
- x+= 5;
- }
- if (goingLeft && x - 5>= 0) {
- x-= 5;
- }
- if (goingDown && y + Height + 5<= game.getHeight()) {
- y+= 2;
- }
- }
- public void render(Graphics g) {
- player = new ImageIcon("C:/Users/Bruker/Pictures/myGuy.PNG").getImage();
- g.setColor(Color.blue);
- g.fillRect(x, y, Width, Height);
- }
- }
Add Comment
Please, Sign In to add comment