Skip to content
Permalink
Browse files

Added Player class

  • Loading branch information
tpg13002 committed Apr 13, 2016
1 parent 1da24d6 commit 7dcd10686a65a3ea89a798ebc296010951d7b756
Showing with 41 additions and 4 deletions.
  1. +12 −4 src/main/Game.java
  2. +29 −0 src/main/Player.java
@@ -1,5 +1,6 @@
package main;


import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Graphics;
@@ -24,7 +25,8 @@
private BufferedImage spriteSheet = null;


private BufferedImage player;
//private BufferedImage player;
private Player p;

public void init()
{
@@ -37,7 +39,8 @@ public void init()
e.printStackTrace();
}
SpriteSheet ss = new SpriteSheet(spriteSheet);
player = ss.grabimage(1, 1, 16, 16);
//player = ss.grabimage(1, 1, 16, 16);
p = new Player(200, 200, this);
}


@@ -114,7 +117,7 @@ public void run() {


private void tick() {

p.tick();
}
private void render(){
BufferStrategy bufferstrat = this.getBufferStrategy();
@@ -126,11 +129,16 @@ private void render(){
/////////////////
g.drawImage(image, 0, 0, getWidth(), getHeight(), this);

g.drawImage(player, 100, 100, this);
//g.drawImage(player, 100, 100, this);
p.render(g);

/////////////////
g.dispose();
bufferstrat.show();

}

public BufferedImage getSpriteSheet(){
return spriteSheet;
}
}
@@ -0,0 +1,29 @@
package main;
import java.awt.Graphics;
import java.awt.image.BufferedImage;

public class Player {

private double x;
private double y;

private BufferedImage player;

public Player(double x, double y, Game game){
this.x = x;
this.y = y;

SpriteSheet ss = new SpriteSheet(game.getSpriteSheet());

player = ss.grabimage(1 ,1, 32, 32);
}

public void tick(){
x++;
}

public void render(Graphics g){
g.drawImage(player, (int)x, (int)y, null);
}

}

0 comments on commit 7dcd106

Please sign in to comment.
You can’t perform that action at this time.