diff --git a/sprites/Profont.png b/sprites/Profont.png new file mode 100644 index 0000000..7208fe1 Binary files /dev/null and b/sprites/Profont.png differ diff --git a/sprites/Profont_36.png b/sprites/Profont_36.png new file mode 100644 index 0000000..696bbf0 Binary files /dev/null and b/sprites/Profont_36.png differ diff --git a/sprites/book.png b/sprites/book.png new file mode 100644 index 0000000..98dfd47 Binary files /dev/null and b/sprites/book.png differ diff --git a/sprites/energyball.png b/sprites/energyball.png new file mode 100644 index 0000000..8356d56 Binary files /dev/null and b/sprites/energyball.png differ diff --git a/sprites/player.png b/sprites/player.png new file mode 100644 index 0000000..721be25 Binary files /dev/null and b/sprites/player.png differ diff --git a/src/sig/JavaProjectTemplate.java b/src/sig/JavaProjectTemplate.java index 94d2287..4d4f923 100644 --- a/src/sig/JavaProjectTemplate.java +++ b/src/sig/JavaProjectTemplate.java @@ -1,7 +1,22 @@ package sig; +import sig.engine.AnimatedSprite; import sig.engine.Color; +import sig.engine.Font; +import sig.engine.Key; import sig.engine.Panel; +import sig.engine.Sprite; +import sig.engine.Transform; + +import java.awt.event.KeyEvent; + +class Player{ + AnimatedSprite spr=new AnimatedSprite("player.png",32,32); + double x=200,y=200; + + double animationFrame=0; + double animationSpd=2; +} public class JavaProjectTemplate { public static final String PROGRAM_NAME="Sig's Java Project Template"; @@ -9,17 +24,53 @@ public class JavaProjectTemplate { public static int WINDOW_HEIGHT=720; public static Panel game; - public static void updateGame() { + Player pl = new Player(); + Sprite bookSpr = new Sprite("book.png"); + + JavaProjectTemplate(){ + //Initialize your game here. } - public static void drawGame() { + public void updateGame(double fElapsedTime) { + //Put game update logic in here. + + pl.animationFrame+=pl.animationSpd*fElapsedTime; + + if (Key.isKeyHeld(KeyEvent.VK_A)) { + pl.x-=200*fElapsedTime; + } + if (Key.isKeyHeld(KeyEvent.VK_D)) { + pl.x+=200*fElapsedTime; + } + if (Key.isKeyHeld(KeyEvent.VK_W)) { + pl.y-=200*fElapsedTime; + } + if (Key.isKeyHeld(KeyEvent.VK_S)) { + pl.y+=200*fElapsedTime; + } + } + + public void drawGame() { + //Put rendering logic in here. + game.Clear(Color.BRIGHT_BLUE); + game.Draw(100,20,Color.BLACK); game.Draw_Line(10,10,35,35,Color.BLACK); - game.FillCircle(Color.MAGENTA,200,200,50); + + game.Draw_Sprite(450,75,bookSpr); + game.Draw_Sprite(450,75+bookSpr.getHeight(),bookSpr,Transform.VERTICAL); + + game.Draw_Animated_Sprite(pl.x,pl.y,pl.spr,pl.animationFrame); + + game.Draw_Text(10,40,new sig.engine.String("Hello World!"),Font.PROFONT_12); + game.Draw_Text_Ext(10,52,new sig.engine.String("Hello World 2!"),Font.PROFONT_36,Color.MAGENTA); + + game.Draw_ } public static void main(String[] args) { - Panel.InitializeEngine(); + JavaProjectTemplate gameInstance=new JavaProjectTemplate(); + Panel.InitializeEngine(gameInstance); } } diff --git a/src/sig/engine/AnimatedSprite.java b/src/sig/engine/AnimatedSprite.java index 3996439..94b1906 100644 --- a/src/sig/engine/AnimatedSprite.java +++ b/src/sig/engine/AnimatedSprite.java @@ -8,6 +8,10 @@ public class AnimatedSprite extends Sprite{ int frames; Rectangle[] frames_to_Rectangle; + public AnimatedSprite(java.lang.String filename, int width, int height){ + this(new File(Sprite.SPRITES_FOLDER.getAbsolutePath(),filename),width,height); + } + AnimatedSprite(File filename, int width, int height){ super(filename); this.originalWidth=this.width; diff --git a/src/sig/engine/Font.java b/src/sig/engine/Font.java index 7b323f4..c849963 100644 --- a/src/sig/engine/Font.java +++ b/src/sig/engine/Font.java @@ -2,6 +2,7 @@ package sig.engine; public enum Font { PROFONT_12((byte)7,(byte)14,Sprite.PROFONT), + PROFONT_36((byte)21,(byte)42,Sprite.PROFONT_36), ; byte glyphWidth,glyphHeight; diff --git a/src/sig/engine/Panel.java b/src/sig/engine/Panel.java index 0c71ef6..8f23649 100644 --- a/src/sig/engine/Panel.java +++ b/src/sig/engine/Panel.java @@ -29,6 +29,7 @@ import sig.JavaProjectTemplate; public class Panel extends JPanel implements Runnable,KeyListener { JFrame window; + static JavaProjectTemplate gameInstance; public int pixel[]; final int CIRCLE_PRECISION=32; final int OUTLINE_COL=Color.BRIGHT_WHITE.getColor(); @@ -63,12 +64,14 @@ public class Panel extends JPanel implements Runnable,KeyListener { public static Panel p; public static JFrame f; - public static void InitializeEngine(){ + public static void InitializeEngine(JavaProjectTemplate instance){ System.setProperty("sun.java2d.transaccel", "True"); System.setProperty("sun.java2d.d3d", "True"); System.setProperty("sun.java2d.ddforcevram", "True"); System.setProperty("sun.java2d.xrender", "True"); + gameInstance=instance; + RENDERHINTS.put(RenderingHints.KEY_COLOR_RENDERING,RenderingHints.VALUE_COLOR_RENDER_SPEED); RENDERHINTS.put(RenderingHints.KEY_DITHERING,RenderingHints.VALUE_DITHER_DISABLE); RENDERHINTS.put(RenderingHints.KEY_FRACTIONALMETRICS,RenderingHints.VALUE_FRACTIONALMETRICS_OFF); @@ -97,7 +100,7 @@ public class Panel extends JPanel implements Runnable,KeyListener { dt += System.nanoTime() - lastGameTime; lastGameTime = System.nanoTime(); while (dt >= UPDATE_LOOP_NANOTIME) { - JavaProjectTemplate.updateGame(); + gameInstance.updateGame(UPDATE_LOOP_NANOTIME/1000000000d); dt -= UPDATE_LOOP_NANOTIME; TIME += UPDATE_LOOP_NANOTIME; } @@ -231,7 +234,7 @@ public class Panel extends JPanel implements Runnable,KeyListener { public /* abstract */ void render(){ - JavaProjectTemplate.drawGame(); + gameInstance.drawGame(); } public void FillCircle(Color col,double center_x,double center_y,double r) { @@ -297,10 +300,12 @@ public class Panel extends JPanel implements Runnable,KeyListener { nextScanLine = scanLine+1; do { for (int i=0;i=active_edges.size()-1) break; Edge e1 = active_edges.get(i); Edge e2 = active_edges.get(i+1); //System.out.println("Drawing from "+((int)Math.round(e1.x_of_min_y))+" to "+e2.x_of_min_y+" on line "+scanLine); for (int x=(int)Math.round(e1.x_of_min_y);x<=e2.x_of_min_y;x++) { + if (x<0||x>JavaProjectTemplate.WINDOW_WIDTH) continue; int index = (scanLine+(int)y_offset)*getWidth()+x+(int)x_offset; if (index=0) { Draw(index,col.getColor()); @@ -388,11 +393,7 @@ public class Panel extends JPanel implements Runnable,KeyListener { } finally { g2.dispose(); } - } else { - System.out.println("Invalid frame!"); } - } else { - System.out.println("Invalid frame!"); } updateFPSCounter(); //System.out.println("Repaint "+frameCount++); @@ -573,7 +574,6 @@ public class Panel extends JPanel implements Runnable,KeyListener { sprite.getWidth()-(X-(int)xOffset): (X-(int)xOffset)) +(int)x; - if (((sprite.getImg().getRGB(X,Y)>>>24)&0xFF)==0||index<0||index>=pixel.length) { continue; } else { diff --git a/src/sig/engine/Sprite.java b/src/sig/engine/Sprite.java index 5c3e3a5..50849ff 100644 --- a/src/sig/engine/Sprite.java +++ b/src/sig/engine/Sprite.java @@ -3,54 +3,28 @@ package sig.engine; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; -import java.awt.image.DataBufferByte; import javax.imageio.ImageIO; public class Sprite{ - public final static File SPRITES_FOLDER = new File("..","sprites"); - public final static File BACKGROUNDS_FOLDER = new File("..","backgrounds"); - - //NANA(new File(SPRITES_FOLDER,"3x.png")), - public static Sprite NANA_SMALL = new Sprite(new File(SPRITES_FOLDER,"1x.gif")); - public static Sprite TILE_SHEET = new Sprite(new File(SPRITES_FOLDER,"tiles.gif")); - public static Sprite MAP_TILE_INFO = new Sprite(new File(SPRITES_FOLDER,"maptileinfo.gif")); - public static Sprite PROFONT = new Sprite(new File(SPRITES_FOLDER,"Profont.gif")); - public static Sprite BACKGROUND1 = new Sprite(new File(BACKGROUNDS_FOLDER,"back1.gif")); - public static Sprite BACKGROUND2 = new Sprite(new File(BACKGROUNDS_FOLDER,"back2.gif")); - public static Sprite BACKGROUND3 = new Sprite(new File(BACKGROUNDS_FOLDER,"back3.gif")); - public static AnimatedSprite ERINOAH = new AnimatedSprite(new File(SPRITES_FOLDER,"erinoah.gif"),48,48); - public static AnimatedSprite ERINA = new AnimatedSprite(new File(SPRITES_FOLDER,"erina.gif"),32,32); - public static AnimatedSprite ERINA_WALK = new AnimatedSprite(new File(SPRITES_FOLDER,"erina_walk.gif"),32,32); - public static AnimatedSprite ERINA_JUMP_RISE1 = new AnimatedSprite(new File(SPRITES_FOLDER,"erina_jump_rise1.gif"),32,32); - public static AnimatedSprite ERINA_JUMP_RISE = new AnimatedSprite(new File(SPRITES_FOLDER,"erina_jump_rise.gif"),32,32); - public static AnimatedSprite ERINA_JUMP_FALL1 = new AnimatedSprite(new File(SPRITES_FOLDER,"erina_jump_fall1.gif"),32,32); - public static AnimatedSprite ERINA_JUMP_FALL = new AnimatedSprite(new File(SPRITES_FOLDER,"erina_jump_fall.gif"),32,32); - public static AnimatedSprite ERINA_SLIDE1 = new AnimatedSprite(new File(SPRITES_FOLDER,"erina_slide1.gif"),32,32); - public static AnimatedSprite ERINA_SLIDE = new AnimatedSprite(new File(SPRITES_FOLDER,"erina_slide.gif"),32,32); - public static AnimatedSprite KNIFE_SWING = new AnimatedSprite(new File(SPRITES_FOLDER,"knife-swing.gif"),32,32); - public static AnimatedSprite RED_STAND = new AnimatedSprite(new File(SPRITES_FOLDER,"redgirl_stand.gif"),32,32); - public static AnimatedSprite RED_WALK = new AnimatedSprite(new File(SPRITES_FOLDER,"redgirl_walk.gif"),32,32); - public static AnimatedSprite BLUE_STAND = new AnimatedSprite(new File(SPRITES_FOLDER,"bluegirl_stand.gif"),32,32); - public static AnimatedSprite BLUE_WALK = new AnimatedSprite(new File(SPRITES_FOLDER,"bluegirl_walk.gif"),32,32); - public static AnimatedSprite YELLOW_STAND = new AnimatedSprite(new File(SPRITES_FOLDER,"yellowgirl_stand.gif"),32,32); - public static AnimatedSprite YELLOW_WALK = new AnimatedSprite(new File(SPRITES_FOLDER,"yellowgirl_walk.gif"),32,32); - public static AnimatedSprite GREEN_STAND = new AnimatedSprite(new File(SPRITES_FOLDER,"greengirl_stand.gif"),32,32); - public static AnimatedSprite GREEN_WALK = new AnimatedSprite(new File(SPRITES_FOLDER,"greengirl_walk.gif"),32,32); - public static Sprite WATER_OVERLAY = new Sprite(new File(BACKGROUNDS_FOLDER,"water-overlay.gif")); - - + public final static Sprite PROFONT = new Sprite("Profont.png"); + public final static Sprite PROFONT_36 = new Sprite("Profont_36.png"); BufferedImage img; int height; int width; + + public Sprite(java.lang.String filename){ + this(new File(SPRITES_FOLDER.getAbsolutePath(),filename)); + } Sprite(File filename){ try { BufferedImage img = ImageIO.read(filename); this.width=img.getWidth(); this.height=img.getHeight(); + this.img=img; } catch (IOException e) { e.printStackTrace(); }