Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added Player class
  • Loading branch information
tpg13002 committed Apr 13, 2016
1 parent 1da24d6 commit 7dcd106
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/main/Game.java
@@ -1,5 +1,6 @@
package main;


import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Graphics;
Expand All @@ -24,7 +25,8 @@ public class Game extends Canvas implements Runnable{
private BufferedImage spriteSheet = null;


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

public void init()
{
Expand All @@ -37,7 +39,8 @@ public class Game extends Canvas implements Runnable{
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);
}


Expand Down Expand Up @@ -114,7 +117,7 @@ public class Game extends Canvas implements Runnable{


private void tick() {

p.tick();
}
private void render(){
BufferStrategy bufferstrat = this.getBufferStrategy();
Expand All @@ -126,11 +129,16 @@ public class Game extends Canvas implements Runnable{
/////////////////
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;
}
}
29 changes: 29 additions & 0 deletions src/main/Player.java
@@ -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.