Beginnings of a separated engine

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
gpu
sigonasr2 2 years ago
parent 36e5bc0f77
commit 010ac996e6
  1. 25
      src/sig/JavaProjectTemplate.java
  2. 42
      src/sig/engine/AnimatedSprite.java
  3. 2
      src/sig/engine/Edge.java
  4. 46
      src/sig/engine/Font.java
  5. 31
      src/sig/engine/Key.java
  6. 10
      src/sig/engine/MouseScrollValue.java
  7. 461
      src/sig/engine/Panel.java
  8. 10
      src/sig/engine/Point.java
  9. 61
      src/sig/engine/Rectangle.java
  10. 92
      src/sig/engine/Sprite.java
  11. 187
      src/sig/engine/String.java
  12. 8
      src/sig/engine/Transform.java
  13. 1
      utils/.updateDirectories
  14. 4
      utils/md5

@ -1,21 +1,24 @@
package sig;
import javax.swing.JFrame;
import sig.engine.Color;
import sig.engine.Panel;
import java.awt.RenderingHints;
public class JavaProjectTemplate {
public static final String PROGRAM_NAME="Sig's Java Project Template";
public static int WINDOW_WIDTH=1280;
public static int WINDOW_HEIGHT=720;
public static Panel game;
public static void drawGame() {
game.Clear(Color.BRIGHT_BLUE);
game.Draw_Line(null, WINDOW_HEIGHT, WINDOW_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT, 0);
}
public static void main(String[] args) {
JFrame f = new JFrame(PROGRAM_NAME);
Panel p = new Panel(f);
p.init();
f.add(p);
f.setSize(1280,720);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
p.render();
Panel.InitializeEngine();
}
}

@ -0,0 +1,42 @@
package sig.engine;
import java.io.File;
public class AnimatedSprite extends Sprite{
int originalWidth;
int originalHeight;
int frames;
Rectangle[] frames_to_Rectangle;
AnimatedSprite(File filename, int width, int height){
super(filename);
this.originalWidth=this.width;
this.originalHeight=this.height;
this.width = width;
this.height = height;
frames = (originalWidth/width)*(originalHeight/height);
frames_to_Rectangle = new Rectangle[frames];
for(int i=0;i<frames;i++){
int x_tile = i%(originalWidth/width);
int y_tile = i/(originalWidth/width);
frames_to_Rectangle[i] = new Rectangle(x_tile*width, y_tile*height, width, height);
}
}
public Rectangle getFrame(int index){
return frames_to_Rectangle[index%frames];
}
public int getFrame_count(){
return frames;
}
@Override
public int getCanvasHeight() {
return originalHeight;
}
@Override
public int getCanvasWidth() {
return originalWidth;
}
}

@ -25,7 +25,7 @@ public class Edge {
inverse_slope=(double)(a.x-b.x)/(a.y-b.y);
}
@Override
public String toString() {
public java.lang.String toString() {
return "Edge [a=" + a + ", b=" + b + ", min_y=" + min_y + ", max_y=" + max_y + ", min_x=" + min_x + ", max_x="
+ max_x + ", x_of_min_y=" + x_of_min_y + ", inverse_slope=" + inverse_slope + "]";
}

@ -0,0 +1,46 @@
package sig.engine;
public enum Font {
PROFONT_12((byte)7,(byte)14,Sprite.PROFONT),
;
byte glyphWidth,glyphHeight;
int glyphCountX,glyphCountY;
Rectangle[] charBounds;
Sprite spr;
Font(byte glyphWidth, byte glyphHeight, Sprite spr) {
this.glyphWidth=glyphWidth;
this.glyphHeight=glyphHeight;
this.glyphCountX=spr.width/glyphWidth;
this.glyphCountY=spr.height/glyphHeight;
this.charBounds = new Rectangle[256];
for (int y=0;y<glyphCountY;y++) {
for (int x=0;x<glyphCountX;x++) {
if (y*glyphCountX+x<256) {
charBounds[y*glyphCountX+x]=new Rectangle(x*glyphWidth,y*glyphHeight,glyphWidth,glyphHeight);
}
}
}
this.spr=spr;
}
public Rectangle getCharacterBounds(char c) {
return charBounds[c];
}
public byte getGlyphWidth() {
return glyphWidth;
}
public byte getGlyphHeight() {
return glyphHeight;
}
public Rectangle getCharInfo(char c) {
return charBounds[c];
}
public Sprite getSprite() {
return spr;
}
}

@ -0,0 +1,31 @@
package sig.engine;
import java.util.HashMap;
public class Key{
static HashMap<Integer,Boolean> KEYS = new HashMap<>();
protected Key(int keycode) {
this.keycode=keycode;
}
int keycode;
public int getKeyCode() {
return keycode;
}
public static void setKeyHeld(int keycode,boolean pressed) {
KEYS.put(keycode,pressed);
//System.out.println(KEYS);
}
public static boolean isKeyHeld(int keycode) {
return KEYS.getOrDefault(keycode,false);
}
public boolean isKeyHeld() {
return KEYS.getOrDefault(keycode,false);
}
}

@ -0,0 +1,10 @@
package sig.engine;
public enum MouseScrollValue {
UP(), //-1 is up
DOWN() /*1 is down*/;
public static MouseScrollValue getValue(int value) {
return value==-1?UP:DOWN;
}
}

@ -1,24 +1,35 @@
package sig.engine;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.ColorModel;
import java.awt.image.MemoryImageSource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.GraphicsEnvironment;
import java.awt.GraphicsConfiguration;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.event.MouseInputListener;
import java.awt.event.KeyListener;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import sig.JavaProjectTemplate;
public class Panel extends JPanel implements Runnable {
public class Panel extends JPanel implements Runnable,KeyListener {
JFrame window;
public int pixel[];
public int width=1280;
public int height=720;
final int CIRCLE_PRECISION=32;
final int OUTLINE_COL=Color.BRIGHT_WHITE.getColor();
private Thread thread;
@ -31,15 +42,111 @@ public class Panel extends JPanel implements Runnable {
double y_offset=0;
int frameCount=0;
long lastSecond=0;
int lastFrameCount=0;
boolean resizing=false;
long lastUpdate=System.nanoTime();
final long TARGET_FRAMETIME = 8333333l;
public double nanaX = 0;
public double nanaY = 0;
public int button = 0;
public HashMap<Integer,Boolean> MOUSE = new HashMap<>();
private Point mousePosition = new Point(0,0);
private MouseScrollValue scrollWheel=null;
public static RenderingHints RENDERHINTS = new RenderingHints(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
static long lastReportedTime = System.currentTimeMillis();
public static long TIME = 0;
public static long scaleTime;
public static Panel p;
public static JFrame f;
public static void InitializeEngine(){
System.setProperty("sun.java2d.transaccel", "True");
System.setProperty("sun.java2d.d3d", "True");
System.setProperty("sun.java2d.ddforcevram", "True");
System.setProperty("sun.java2d.xrender", "True");
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);
RENDERHINTS.put(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_SPEED);
f = new JFrame(JavaProjectTemplate.PROGRAM_NAME);
f.setResizable(false);
f.setSize(JavaProjectTemplate.WINDOW_WIDTH,JavaProjectTemplate.WINDOW_HEIGHT);
p = new Panel(f);
JavaProjectTemplate.game=p;
p.init();
f.add(p);
f.addKeyListener(p);
f.setLocation((int) ((Toolkit.getDefaultToolkit().getScreenSize().getWidth() - f.getWidth()) / 2),
(int) ((Toolkit.getDefaultToolkit().getScreenSize().getHeight() - f.getHeight()) / 2));
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
f.createBufferStrategy(2);
p.render();
}
public Panel(JFrame f) {
super(true);
this.window=f;
thread = new Thread(this, "MyPanel Thread");
this.addMouseListener(new MouseInputListener(){
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
MOUSE.put(e.getButton(),true);
}
@Override
public void mouseReleased(MouseEvent e) {
MOUSE.put(e.getButton(),false);
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseDragged(MouseEvent e) {
}
@Override
public void mouseMoved(MouseEvent e) {
}
});
this.addMouseMotionListener(new MouseMotionListener(){
@Override
public void mouseDragged(MouseEvent e) {
mousePosition.set(e.getX(),e.getY());
}
@Override
public void mouseMoved(MouseEvent e) {
mousePosition.set(e.getX(),e.getY());
}
});
this.addMouseWheelListener(new MouseWheelListener(){
//-1 is UP, 1 is DOWN
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
scrollWheel=MouseScrollValue.getValue(e.getWheelRotation());
}
});
}
/**
/**
* Get Best Color model available for current screen.
* @return color model
*/
@ -50,41 +157,32 @@ public class Panel extends JPanel implements Runnable {
return gfx_config.getColorModel();
}
/**
* Call it after been visible and after resizes.
*/
public void init(){
cm = getCompatibleColorModel();
int screenSize = width * height;
int screenSize = JavaProjectTemplate.WINDOW_WIDTH * JavaProjectTemplate.WINDOW_HEIGHT;
if(pixel == null || pixel.length < screenSize){
pixel = new int[screenSize];
}
if(thread.isInterrupted() || !thread.isAlive()){
thread.start();
}
mImageProducer = new MemoryImageSource(width, height, cm, pixel,0, width);
}
mImageProducer = new MemoryImageSource(JavaProjectTemplate.WINDOW_WIDTH, JavaProjectTemplate.WINDOW_HEIGHT, cm, pixel,0, JavaProjectTemplate.WINDOW_WIDTH);
mImageProducer.setAnimated(true);
mImageProducer.setFullBufferUpdates(true);
imageBuffer = Toolkit.getDefaultToolkit().createImage(mImageProducer);
imageBuffer = Toolkit.getDefaultToolkit().createImage(mImageProducer);
if(thread.isInterrupted() || !thread.isAlive()){
thread.start();
}
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
// perform draws on pixels
render();
// ask ImageProducer to update image
mImageProducer.newPixels();
// draw it on panel
g.drawImage(this.imageBuffer, 0, 0, this);
if (window!=null&&System.currentTimeMillis()-lastSecond>=1000) {
window.setTitle(JavaProjectTemplate.PROGRAM_NAME+" - FPS: "+(frameCount-lastFrameCount));
lastFrameCount=frameCount;
lastSecond=System.currentTimeMillis();
}
frameCount++;
//super.paintComponent(g);
// perform draws on pixels
long startTime = System.currentTimeMillis();
g.drawImage(this.imageBuffer,0,0,JavaProjectTemplate.WINDOW_WIDTH,JavaProjectTemplate.WINDOW_HEIGHT,0,0,JavaProjectTemplate.WINDOW_WIDTH,JavaProjectTemplate.WINDOW_HEIGHT,this);
scaleTime=System.currentTimeMillis()-startTime;
}
/**
@ -99,54 +197,14 @@ public class Panel extends JPanel implements Runnable {
* Do your draws in here !!
* pixel is your canvas!
*/
public /* abstract */ void render(){
int[] p = pixel; // this avoid crash when resizing
//a=h/w
for (int x=0;x<width;x++) {
for (int y=0;y<height;y++) {
p[y*width+x]=(0<<16)+(0<<8)+0;
}
}
x_offset+=1;
y_offset=50;
FillPolygon(p,Color.WHITE,50,50,new Point[] {
new Point(135,2),
new Point(166,96),
new Point(265,97),
new Point(185,156),
new Point(215,251),
new Point(134,192),
new Point(54,251),
new Point(84,156),
new Point(4,97),
new Point(103,96),
});
FillPolygon(p,Color.BRIGHT_CYAN,x_offset,y_offset,new Point[] {
new Point(28,29),
new Point(78,103),
new Point(120,31),
new Point(123,221),
new Point(30,218),
});
//FillRect(p,Color.BRIGHT_RED,200,200,600,64);
final Color testAlpha = new Color(150,0,0,128);
FillCircle(p,testAlpha,150,150,100);
FillOval(p,Color.BRIGHT_GREEN,300,150,100,50);
JavaProjectTemplate.drawGame();
}
public void FillRect(int[] p,Color col,double x,double y,double w,double h) {
for (int xx=0;xx<w;xx++) {
for (int yy=0;yy<h;yy++) {
int index = ((int)y+yy)*width+(int)x+xx;
p[index]=col.getColor();
}
}
}
public void FillCircle(int[] p,Color col,double center_x,double center_y,double r) {
public void FillCircle(byte[] p,byte col,double center_x,double center_y,double r) {
int counter=0;
Point[] points = new Point[CIRCLE_PRECISION];
for (double theta=0;theta<Math.PI*2;theta+=((Math.PI*2)/CIRCLE_PRECISION)) {
@ -158,7 +216,7 @@ public class Panel extends JPanel implements Runnable {
}
public void FillOval(int[] p,Color col,double center_x,double center_y,double w,double h) {
public void FillOval(byte[] p,byte col,double center_x,double center_y,double w,double h) {
int counter=0;
Point[] points = new Point[CIRCLE_PRECISION];
double r = Math.max(w,h);
@ -179,7 +237,7 @@ public class Panel extends JPanel implements Runnable {
FillPolygon(p,col,0,0,points);
}
public void FillPolygon(int[] p,Color col,double x_offset,double y_offset,Point...points) {
public void FillPolygon(byte[] p,byte col,double x_offset,double y_offset,Point...points) {
Edge[] edges = new Edge[points.length];
List<Edge> edges_sorted = new ArrayList<Edge>();
for (int i=0;i<points.length;i++) {
@ -213,9 +271,9 @@ public class Panel extends JPanel implements Runnable {
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++) {
int index = (scanLine+(int)y_offset)*width+x+(int)x_offset;
int index = (scanLine+(int)y_offset)*getWidth()+x+(int)x_offset;
if (index<p.length&&index>=0) {
Draw(p,index,col.getColor());
Draw(p,index,col);
}
}
}
@ -277,38 +335,237 @@ public class Panel extends JPanel implements Runnable {
}
}
public void Draw(int[] canvas,int index, int col) {
int alpha = col>>>24;
if (alpha==0) {
return;}
else
if (alpha==255) {
canvas[index]=col;
} else {
float ratio=alpha/255f;
int prev_col=canvas[index];
int prev_r=(prev_col&0xFF);
int prev_g=(prev_col&0xFF00)>>>8;
int prev_b=(prev_col&0xFF0000)>>>16;
int r=(col&0xFF);
int g=(col&0xFF00)>>>8;
int b=(col&0xFF0000)>>>16;
int new_r=(int)(ratio*r+(1-ratio)*prev_r);
int new_g=(int)(ratio*g+(1-ratio)*prev_g);
int new_b=(int)(ratio*b+(1-ratio)*prev_b);
canvas[index]=new_r+(new_g<<8)+(new_b<<16)+(col&0xFF000000);
}
public void Draw(int index, byte col) {
pixel[index]=col;
}
@Override
public void run() {
if (mImageProducer==null) return;
while (true) {
// request a JPanel re-drawing
repaint();
//repaint();
render();
mImageProducer.newPixels();
if (f!=null&&f.getBufferStrategy()!=null) {
do {
do {
if (f.getBufferStrategy()!=null) {
Graphics2D g2 = (Graphics2D)f.getBufferStrategy().getDrawGraphics();
g2.setRenderingHints(RENDERHINTS);
if (g2!=null) {
try {
paintComponent(g2);
} finally {
g2.dispose();
}
}
}
} while (f.getBufferStrategy().contentsRestored());
f.getBufferStrategy().show();
Toolkit.getDefaultToolkit().sync();
} while (f.getBufferStrategy().contentsLost());
}
updateFPSCounter();
//System.out.println("Repaint "+frameCount++);
//try {Thread.sleep(1);} catch (InterruptedException e) {}
waitForNextFrame();
}
}
private void waitForNextFrame() {
long newTime = System.nanoTime();
if (newTime-lastUpdate<TARGET_FRAMETIME) {
long timeRemaining=TARGET_FRAMETIME-(newTime-lastUpdate);
long millis = timeRemaining/1000000l;
int nanos = (int)(timeRemaining-millis*1000000l);
//System.out.println(timeRemaining+"/"+millis+" Nanos:"+nanos);
try {
Thread.sleep(millis,nanos);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
lastUpdate=newTime;
}
private void updateFPSCounter() {
if (window!=null&&System.currentTimeMillis()-lastSecond>=1000) {
window.setTitle(JavaProjectTemplate.PROGRAM_NAME+" - FPS: "+(frameCount));
frameCount=0;
lastSecond=System.currentTimeMillis();
}
frameCount++;
}
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
if (!Key.isKeyHeld(e.getKeyCode())) {
Key.setKeyHeld(e.getKeyCode(), true);
}
//System.out.println("Key List: "+KEYS);
}
@Override
public void keyReleased(KeyEvent e) {
Key.setKeyHeld(e.getKeyCode(), false);
//System.out.println("Key List: "+KEYS);
}
public void Draw_Text(double x, double y, String s, Font f) {
Draw_Text_Ext(x,y,s,f,Color.BLACK);
}
public void Draw_Text_Ext(double x, double y, String s, Font f, Color col) {
java.lang.String finalS = s.toString();
int charCount=0;
int yOffset=0;
int xOffset=0;
Color currentCol = col;
for (int i=0;i<finalS.length();i++) {
if (finalS.charAt(i)=='\n') {
xOffset+=(charCount+1)*f.getGlyphWidth();
yOffset+=f.getGlyphHeight();
charCount=0;
} else {
Draw_Sprite_Partial_Ext(x+i*f.getGlyphWidth()-xOffset, y+yOffset, f.getCharInfo(finalS.charAt(i)).getX(), f.getCharInfo(finalS.charAt(i)).getY(), f.getCharInfo(finalS.charAt(i)).getWidth(), f.getCharInfo(finalS.charAt(i)).getHeight(), f.getSprite(), 0,currentCol,Transform.NONE);
charCount++;
}
}
}
public void Draw_Line(byte[] canvas,int x1,int y1,int x2,int y2,byte col) {
int x,y,dx,dy,dx1,dy1,px,py,xe,ye;
dx=x2-x1;dy=y2-y1;
dx1=Math.abs(dx);dy1=Math.abs(dy);
px=2*dy1-dx1;py=2*dx1-dy1;
if (dy1<=dx1) {
if (dx>=0) {
x=x1;y=y1;xe=x2-1;
} else {
x=x2-1;y=y2-1;xe=x1;
}
Draw(canvas,y*JavaProjectTemplate.WINDOW_WIDTH+x,col);
while (x<xe) {
x=x+1;
if (px<0) {
px=px+2*dy1;
} else {
if ((dx<0&&dy<0)||(dx>0&&dy>0)) {
y=y+1;
} else {
y=y-1;
}
px=px+2*(dy1-dx1);
}
Draw(canvas,y*JavaProjectTemplate.WINDOW_WIDTH+x,col);
}
} else {
if (dy>=0) {
x=x1;y=y1;ye=y2-1;
} else {
x=x2-1;y=y2-1;ye=y1;
}
Draw(canvas,y*JavaProjectTemplate.WINDOW_WIDTH+x,col);
while (y<ye) {
y=y+1;
if (py<=0) {
py=py+2*dx1;
} else {
if ((dx<0&&dy<0)||(dx>0&&dy>0)) {
x=x+1;
} else {
x=x-1;
}
py=py+2*(dx1-dy1);
}
Draw(canvas,y*JavaProjectTemplate.WINDOW_WIDTH+x,col);
}
}
}
public void Fill_Rect(byte[] p,byte col,double x,double y,double w,double h) {
for (int xx=0;xx<w;xx++) {
for (int yy=0;yy<h;yy++) {
if (x+xx>=0&&y+yy>=0&&x+xx<JavaProjectTemplate.WINDOW_WIDTH&&y+yy<JavaProjectTemplate.WINDOW_HEIGHT) {
int index = ((int)y+yy)*JavaProjectTemplate.WINDOW_WIDTH+(int)x+xx;
Draw(p,index,col);
}
}
}
}
public void Draw_Sprite(double x, double y, Sprite sprite){
Draw_Sprite_Partial(x,y,0,0,sprite.getWidth(),sprite.getHeight(),sprite,0,Transform.NONE );
}
public void Draw_Animated_Sprite(double x, double y, AnimatedSprite sprite, double frameIndex){
Rectangle frameRectangle=sprite.getFrame((int)frameIndex);
Draw_Sprite_Partial(x,y,frameRectangle.getX(),frameRectangle.getY(),frameRectangle.getWidth(),frameRectangle.getHeight(),sprite,frameIndex,Transform.NONE);
}
public void Draw_Sprite(double x, double y, Sprite sprite, Transform transform){
Draw_Sprite_Partial(x,y,0,0,sprite.getWidth(),sprite.getHeight(),sprite,0,transform);
}
public void Draw_Animated_Sprite(double x, double y, AnimatedSprite sprite, double frameIndex, Transform transform){
Rectangle frameRectangle=sprite.getFrame((int)frameIndex);
Draw_Sprite_Partial(x,y,frameRectangle.getX(),frameRectangle.getY(),frameRectangle.getWidth(),frameRectangle.getHeight(),sprite,frameIndex, transform);
}
public void Draw_Sprite_Partial(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, double frame_index, Transform transform){
Draw_Sprite_Partial_Ext(x,y,xOffset,yOffset,w,h,sprite,frame_index, Color.WHITE,transform);
}
public void Draw_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, Transform transform){
Draw_Sprite_Partial_Ext(x, y, xOffset, yOffset, w, h, sprite, 0, Color.WHITE, transform);
}
public void Draw_Animated_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, AnimatedSprite sprite, double frameIndex, Transform transform){
Rectangle frameRectangle=sprite.getFrame((int)frameIndex);
Draw_Sprite_Partial_Ext(x, y, frameRectangle.getX(), frameRectangle.getY(), frameRectangle.getWidth(), frameRectangle.getHeight(), sprite, 0, Color.WHITE, transform);
}
public void Draw_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, double frame_index, Color col, Transform transform){
boolean horizontal = transform==Transform.HORIZONTAL||transform==Transform.HORIZ_VERTIC;
boolean vertical = transform==Transform.VERTICAL||transform==Transform.HORIZ_VERTIC;
for(int X=(int)xOffset;X<(int)(w+xOffset);X++){
for(int Y=(int)yOffset;Y<(int)(h+yOffset);Y++){
if (X+x-xOffset<0||Y+y-yOffset<0||X-xOffset+x>=JavaProjectTemplate.WINDOW_WIDTH||Y-yOffset+y>=JavaProjectTemplate.WINDOW_HEIGHT) {
continue;
} else {
int index =
((vertical?
sprite.getHeight()-(Y-(int)yOffset):
(Y-(int)yOffset))
+(int)y)*JavaProjectTemplate.WINDOW_WIDTH+
(horizontal?
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 {
Draw(pixel,index,(col==Color.WHITE)?sprite.getImg().getRGB(X,Y):col.getColor());
}
}
}
}
}
public void Clear(Color col){
for (int y=0;y<JavaProjectTemplate.WINDOW_HEIGHT;y++) {
for (int x=0;x<JavaProjectTemplate.WINDOW_WIDTH;x++) {
Draw(pixel,y*JavaProjectTemplate.WINDOW_WIDTH+x,col.getColor());
}
}
}
public void Draw(int[] canvas,int index, int col) {
canvas[index]=col;
}
}

@ -25,8 +25,16 @@ public class Point {
this.y = y;
}
public void set(int x,int y) {
setX(x);setY(y);
}
public void update(int x,int y) {
set(x,y);
}
@Override
public String toString() {
public java.lang.String toString() {
return "Point(" + x + "," + y + ")";
}
}

@ -0,0 +1,61 @@
package sig.engine;
public class Rectangle {
int x,y,w,h;
public Rectangle(int x, int y, int w, int h) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
}
public int getX() {
return x;
}
public int getX2() {
return x+w;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public int getY2() {
return y+h;
}
public void setY(int y) {
this.y = y;
}
public int getWidth() {
return w;
}
public void setWidth(int w) {
this.w = w;
}
public int getHeight() {
return h;
}
public void setHeight(int h) {
this.h = h;
}
@Override
public java.lang.String toString() {
return new StringBuilder("Rectangle(x=").append(x).append(",")
.append("y=").append(y).append(",")
.append("w=").append(w).append(",")
.append("h=").append(h).append(")").toString();
}
}

@ -0,0 +1,92 @@
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"));
BufferedImage img;
int height;
int width;
Sprite(File filename){
try {
BufferedImage img = ImageIO.read(filename);
this.width=img.getWidth();
this.height=img.getHeight();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Loaded sprite for "+filename+".");
}
public BufferedImage getImg() {
return img;
}
public void setImg(BufferedImage img) {
this.img = img;
}
public int getHeight() {
return height;
}
public int getCanvasHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public int getWidth() {
return width;
}
public int getCanvasWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
}

@ -0,0 +1,187 @@
package sig.engine;
import java.util.regex.Pattern;
public class String{
private StringBuilder sb;
private Point bounds = new Point(0,1);
private int currentLineWidth;
public String() {
this.sb=new StringBuilder();
}
public String(java.lang.String str) {
this.sb=new StringBuilder(str);
updateBounds(str);
}
public String(Object obj) {
this.sb=new StringBuilder(obj.toString());
updateBounds(obj.toString());
}
public String(double d) {
this.sb=new StringBuilder(Double.toString(d));
updateBounds(Double.toString(d));
}
public String append(double d) {
this.sb.append(d);
updateBounds(Double.toString(d));
return this;
}
public String append(char c) {
this.sb.append(c);
updateBounds(Character.toString(c));
return this;
}
public String append(java.lang.Object...obj) {
for (int i=0;i<obj.length;i++) {
java.lang.Object o = obj[i];
this.sb.append(o.toString());
updateBounds(o.toString());
}
return this;
}
public StringBuilder getBuilder() {
return this.sb;
}
/**
* Returns the index within this string of the first occurrence of the
* specified substring.
*
* <p>The returned index is the smallest value {@code k} for which:
* <pre>{@code
* this.toString().startsWith(str, k)
* }</pre>
* If no such value of {@code k} exists, then {@code -1} is returned.
*
* @param str the substring to search for.
* @return the index of the first occurrence of the specified substring,
* or {@code -1} if there is no such occurrence.
*/
public int indexOf(java.lang.String str) {
return this.sb.indexOf(str);
}
public void clear() {
this.sb.setLength(0);
bounds = new Point(0,1);
}
/**
* Returns the index within this string of the first occurrence of the
* specified substring, starting at the specified index.
*
* <p>The returned index is the smallest value {@code k} for which:
* <pre>{@code
* k >= Math.min(fromIndex, this.length()) &&
* this.toString().startsWith(str, k)
* }</pre>
* If no such value of {@code k} exists, then {@code -1} is returned.
*
* @param str the substring to search for.
* @param fromIndex the index from which to start the search.
* @return the index of the first occurrence of the specified substring,
* starting at the specified index,
* or {@code -1} if there is no such occurrence.
*/
public int indexOf(java.lang.String str,int fromIndex) {
return this.sb.indexOf(str,fromIndex);
}
/**
* Replaces the characters in a substring of this sequence
* with characters in the specified {@code String}. The substring
* begins at the specified {@code start} and extends to the character
* at index {@code end - 1} or to the end of the
* sequence if no such character exists. First the
* characters in the substring are removed and then the specified
* {@code String} is inserted at {@code start}. (This
* sequence will be lengthened to accommodate the
* specified String if necessary.)
*
* @param start The beginning index, inclusive.
* @param end The ending index, exclusive.
* @param str String that will replace previous contents.
* @return This object.
* @throws StringIndexOutOfBoundsException if {@code start}
* is negative, greater than {@code length()}, or
* greater than {@code end}.
*/
public String replace(int start,int end,java.lang.String str) {
this.sb.replace(start,end,str);
bounds = new Point(0,1);
updateBounds(this.sb.toString());
return this;
}
/**
* Returns a new {@code String} that contains a subsequence of
* characters currently contained in this character sequence. The
* substring begins at the specified index and extends to the end of
* this sequence.
*
* @param start The beginning index, inclusive.
* @return The new string.
* @throws StringIndexOutOfBoundsException if {@code start} is
* less than zero, or greater than the length of this object.
*/
public String substring(int start) {
java.lang.String cutString = this.sb.substring(start);
clear();
this.sb.append(cutString);
bounds = new Point(0,1);
currentLineWidth=0;
updateBounds(this.sb.toString());
return this;
}
/**
* Returns a new {@code String} that contains a subsequence of
* characters currently contained in this sequence. The
* substring begins at the specified {@code start} and
* extends to the character at index {@code end - 1}.
*
* @param start The beginning index, inclusive.
* @param end The ending index, exclusive.
* @return The new string.
* @throws StringIndexOutOfBoundsException if {@code start}
* or {@code end} are negative or greater than
* {@code length()}, or {@code start} is
* greater than {@code end}.
*/
public String substring(int start,int end) {
java.lang.String cutString = this.sb.substring(start,end);
clear();
this.sb.append(cutString);
bounds = new Point(0,1);
currentLineWidth=0;
updateBounds(this.sb.toString());
return this;
}
public int length() {
return this.sb.length();
}
public java.lang.String toString() {
return this.sb.toString();
}
public Point getBounds(Font f) {
return new Point(bounds.x*f.getGlyphWidth(),length()>0?Math.max(bounds.y*f.getGlyphHeight(),f.getGlyphHeight()):0);
}
private void updateBounds(java.lang.String string) {
for (int i=0;i<string.length();i++) {
if (string.charAt(i)=='\n') {
bounds.x=i+1>bounds.x?i+1:bounds.x;
bounds.y++;
currentLineWidth=0;
} else
if (string.charAt(i)==(char)26&&i<string.length()-1) {
byte nextCol=Byte.parseByte(string.substring(i+1, string.indexOf(' ',i+1)));
string=string.replaceFirst(Pattern.quote(Character.valueOf((char)26)+Byte.toString(nextCol)+" "),"");
i--;
} else {
currentLineWidth++;
bounds.x=currentLineWidth>bounds.x?currentLineWidth:bounds.x;
}
}
}
}

@ -0,0 +1,8 @@
package sig.engine;
public enum Transform {
NONE,
HORIZONTAL,
VERTICAL,
HORIZ_VERTIC
}

@ -1,4 +1,5 @@
Java/
C/
C++/
scripts/
utils/

@ -1,4 +1,4 @@
define.sh:3ecab0dffe2adfb950f3eb7c7061b750 -
main.sh:4e6e9f0650ec790ce2c4364db94f0caa -
search.sh:81d08f5ff48e8a44b5f68387d426da05 -
.updateDirectories:fa5e95db12be22ae8aed7ecbc560e38c -
search.sh:30e1842e9a13452ea883bb6516d28e1c -
.updateDirectories:971afb892e8280cb4c9ad43fb72a46a0 -

Loading…
Cancel
Save