Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package myFirstGame;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.Rectangle;
- import javax.swing.ImageIcon;
- public class Player {
- int Width = 25;
- int Height = 45;
- public int x;
- public int y;
- int speed = 2;
- int gravity = 7;
- Image playerChar;
- public boolean loaded = false;
- public boolean imagesLoaded = false;
- boolean Jump = false;
- boolean goingRight = false;
- boolean goingLeft = false;
- boolean goingDown = false;
- 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 -= 100;
- }
- if (goingRight && x + Width + 5 <= game.getWidth()) {
- x += 3;
- }
- if (goingLeft && x - 5 >= 0) {
- x -= 3;
- }
- if (goingDown && y + Height + 5 <= game.getHeight()) {
- y += 0;
- }
- if (y + Height < 405 && !Jump) {
- y += gravity;
- }
- }
- public void render(Graphics g) {
- loaded = true;
- playerChar = new ImageIcon("C:\\Users\\Bruker\\Pictures\\player.gif").getImage();
- if (Game.player.loaded) {
- g.drawImage(Game.player.playerChar, x, y, null);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement