Engine is mostly feature-complete

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
gpu
sigonasr2 2 years ago
parent ca082c3f2c
commit 7b663847ef
  1. BIN
      sprites/Profont.png
  2. BIN
      sprites/Profont_36.png
  3. BIN
      sprites/book.png
  4. BIN
      sprites/energyball.png
  5. BIN
      sprites/player.png
  6. 59
      src/sig/JavaProjectTemplate.java
  7. 4
      src/sig/engine/AnimatedSprite.java
  8. 1
      src/sig/engine/Font.java
  9. 16
      src/sig/engine/Panel.java
  10. 40
      src/sig/engine/Sprite.java

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

@ -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);
}
}

@ -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;

@ -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;

@ -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();i+=2) {
if (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<pixel.length&&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 {

@ -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();
}

Loading…
Cancel
Save