From 4c9bb76af0b299cc4d0e471fc0dfca17bf8107c5 Mon Sep 17 00:00:00 2001 From: Yelik Date: Fri, 9 May 2014 20:47:56 -0400 Subject: [PATCH] TONS OF STUFF --- .../.safetable/org.eclipse.core.resources | Bin 1368 -> 1664 bytes .../.settings/org.eclipse.jdt.ui.prefs | 2 +- .../externalLibsTimeStamps | Bin 767 -> 822 bytes .../org.eclipse.jdt.core/savedIndexNames.txt | 4 +- .../variablesAndContainers.dat | Bin 26001 -> 27643 bytes AStar/src/Game.java | 2 +- AStar/src/Map.java | 2 +- Cube/.classpath | 6 + Cube/.project | 17 ++ Cube/.settings/org.eclipse.jdt.core.prefs | 11 ++ Cube/src/Array2D.java | 53 ++++++ Cube/src/KeyReader.java | 47 ++++++ Cube/src/Main.java | 159 ++++++++++++++++++ Cube/src/MouseReader.java | 77 +++++++++ Cube/src/Screen.java | 37 ++++ Cube/src/com/mrizen/cube/d2/Point2d.java | 19 +++ Cube/src/com/mrizen/cube/d2/Shape2d.java | 19 +++ Cube/src/com/mrizen/cube/d3/Point3d.java | 7 + Darkness/.classpath | 7 + Darkness/.project | 17 ++ Darkness/.settings/org.eclipse.jdt.core.prefs | 11 ++ Darkness/src/com/mrizen/darkness/Game.java | 34 ++++ Darkness/src/com/mrizen/darkness/Map.java | 79 +++++++++ Darkness2/.classpath | 7 + Darkness2/.project | 17 ++ .../.settings/org.eclipse.jdt.core.prefs | 11 ++ Darkness2/src/Game.java | 32 ++++ Darkness2/src/Map.java | 53 ++++++ Dunegon Gen/.classpath | 7 + Dunegon Gen/.project | 17 ++ .../.settings/org.eclipse.jdt.core.prefs | 11 ++ Dunegon Gen/src/Game.java | 28 +++ Dunegon Gen/src/Map.java | 80 +++++++++ Dunegon Gen/src/Sprites.java | 7 + Dunegon Gen/src/Tile.java | 30 ++++ DungeonCrawler/.classpath | 8 + DungeonCrawler/.project | 17 ++ .../.settings/org.eclipse.jdt.core.prefs | 11 ++ DungeonCrawler/res/tiles.png | Bin 0 -> 2128 bytes .../src/com/mrizen/dungeoncrawler/Entity.java | 80 +++++++++ .../src/com/mrizen/dungeoncrawler/Game.java | 34 ++++ .../src/com/mrizen/dungeoncrawler/Level.java | 29 ++++ .../src/com/mrizen/dungeoncrawler/Map.java | 55 ++++++ .../com/mrizen/dungeoncrawler/Sprites.java | 13 ++ .../src/com/mrizen/dungeoncrawler/Tile.java | 39 +++++ Energy/.classpath | 7 + Energy/.project | 17 ++ Energy/.settings/org.eclipse.jdt.core.prefs | 11 ++ Energy/src/com/mrizen/energy/Game.java | 47 ++++++ Energy/src/com/mrizen/energy/Map.java | 56 ++++++ Energy/src/com/mrizen/energy/Sprites.java | 9 + Energy/src/com/mrizen/energy/Tile.java | 32 ++++ Energy/src/com/mrizen/energy/TileNode.java | 12 ++ Energy/src/com/mrizen/energy/TileWall.java | 14 ++ Hills3/.classpath | 6 + Hills3/.project | 17 ++ Hills3/.settings/org.eclipse.jdt.core.prefs | 11 ++ Hills3/src/Game.java | 130 ++++++++++++++ Hills3/src/Screen.java | 7 + .../src/com/mrizen/gaming/Array2D.java | 70 ++++++++ .../src/com/mrizen/gaming/Array2DColor.java | 59 +++++++ MrizenGaming/src/com/mrizen/gaming/Main.java | 48 +++--- MrizenGaming/src/com/mrizen/gaming/Map.java | 53 ++++++ .../src/com/mrizen/gaming/MouseReader.java | 17 +- .../src/com/mrizen/gaming/Point2D.java | 27 +++ .../src/com/mrizen/gaming/Screen.java | 63 +++++-- .../src/com/mrizen/gaming/Sprite.java | 32 ++-- .../src/com/mrizen/gaming/Spritesheet.java | 18 +- MrizenGaming/src/com/mrizen/gaming/Tile.java | 26 +++ Scrolling Shooter 1/.classpath | 7 + Scrolling Shooter 1/.project | 17 ++ .../.settings/org.eclipse.jdt.core.prefs | 11 ++ Scrolling Shooter 1/src/Entity.java | 7 + Scrolling Shooter 1/src/Game.java | 21 +++ Scrolling Shooter 1/src/Level.java | 16 ++ TerrainGen/.classpath | 7 + TerrainGen/.project | 17 ++ .../.settings/org.eclipse.jdt.core.prefs | 11 ++ TerrainGen/src/Game.java | 24 +++ TerrainGen/src/Sprites.java | 13 ++ TerrainGen/src/TerrainMap.java | 100 +++++++++++ TerrainGen/src/Tiles.java | 13 ++ 82 files changed, 2171 insertions(+), 78 deletions(-) create mode 100644 Cube/.classpath create mode 100644 Cube/.project create mode 100644 Cube/.settings/org.eclipse.jdt.core.prefs create mode 100644 Cube/src/Array2D.java create mode 100644 Cube/src/KeyReader.java create mode 100644 Cube/src/Main.java create mode 100644 Cube/src/MouseReader.java create mode 100644 Cube/src/Screen.java create mode 100644 Cube/src/com/mrizen/cube/d2/Point2d.java create mode 100644 Cube/src/com/mrizen/cube/d2/Shape2d.java create mode 100644 Cube/src/com/mrizen/cube/d3/Point3d.java create mode 100644 Darkness/.classpath create mode 100644 Darkness/.project create mode 100644 Darkness/.settings/org.eclipse.jdt.core.prefs create mode 100644 Darkness/src/com/mrizen/darkness/Game.java create mode 100644 Darkness/src/com/mrizen/darkness/Map.java create mode 100644 Darkness2/.classpath create mode 100644 Darkness2/.project create mode 100644 Darkness2/.settings/org.eclipse.jdt.core.prefs create mode 100644 Darkness2/src/Game.java create mode 100644 Darkness2/src/Map.java create mode 100644 Dunegon Gen/.classpath create mode 100644 Dunegon Gen/.project create mode 100644 Dunegon Gen/.settings/org.eclipse.jdt.core.prefs create mode 100644 Dunegon Gen/src/Game.java create mode 100644 Dunegon Gen/src/Map.java create mode 100644 Dunegon Gen/src/Sprites.java create mode 100644 Dunegon Gen/src/Tile.java create mode 100644 DungeonCrawler/.classpath create mode 100644 DungeonCrawler/.project create mode 100644 DungeonCrawler/.settings/org.eclipse.jdt.core.prefs create mode 100644 DungeonCrawler/res/tiles.png create mode 100644 DungeonCrawler/src/com/mrizen/dungeoncrawler/Entity.java create mode 100644 DungeonCrawler/src/com/mrizen/dungeoncrawler/Game.java create mode 100644 DungeonCrawler/src/com/mrizen/dungeoncrawler/Level.java create mode 100644 DungeonCrawler/src/com/mrizen/dungeoncrawler/Map.java create mode 100644 DungeonCrawler/src/com/mrizen/dungeoncrawler/Sprites.java create mode 100644 DungeonCrawler/src/com/mrizen/dungeoncrawler/Tile.java create mode 100644 Energy/.classpath create mode 100644 Energy/.project create mode 100644 Energy/.settings/org.eclipse.jdt.core.prefs create mode 100644 Energy/src/com/mrizen/energy/Game.java create mode 100644 Energy/src/com/mrizen/energy/Map.java create mode 100644 Energy/src/com/mrizen/energy/Sprites.java create mode 100644 Energy/src/com/mrizen/energy/Tile.java create mode 100644 Energy/src/com/mrizen/energy/TileNode.java create mode 100644 Energy/src/com/mrizen/energy/TileWall.java create mode 100644 Hills3/.classpath create mode 100644 Hills3/.project create mode 100644 Hills3/.settings/org.eclipse.jdt.core.prefs create mode 100644 Hills3/src/Game.java create mode 100644 Hills3/src/Screen.java create mode 100644 MrizenGaming/src/com/mrizen/gaming/Array2D.java create mode 100644 MrizenGaming/src/com/mrizen/gaming/Array2DColor.java create mode 100644 MrizenGaming/src/com/mrizen/gaming/Map.java create mode 100644 MrizenGaming/src/com/mrizen/gaming/Point2D.java create mode 100644 MrizenGaming/src/com/mrizen/gaming/Tile.java create mode 100644 Scrolling Shooter 1/.classpath create mode 100644 Scrolling Shooter 1/.project create mode 100644 Scrolling Shooter 1/.settings/org.eclipse.jdt.core.prefs create mode 100644 Scrolling Shooter 1/src/Entity.java create mode 100644 Scrolling Shooter 1/src/Game.java create mode 100644 Scrolling Shooter 1/src/Level.java create mode 100644 TerrainGen/.classpath create mode 100644 TerrainGen/.project create mode 100644 TerrainGen/.settings/org.eclipse.jdt.core.prefs create mode 100644 TerrainGen/src/Game.java create mode 100644 TerrainGen/src/Sprites.java create mode 100644 TerrainGen/src/TerrainMap.java create mode 100644 TerrainGen/src/Tiles.java diff --git a/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources b/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources index 0579db6bb5f827245cbce0a3f7d3f06567d4d266..b026f60fe058ba810923e9d7f4b8bdfc9e2c94d3 100644 GIT binary patch literal 1664 zcmeHHu}%U(5VakNxZe}xNuc1K^TPwsJH=CgxK~<4!IF~B0k#g1z(e|+w z1vZrmcP@a3ChsqfT_0!MNTrRmgDM zGl)z7$EZd#jabs)f^74yeoRp9rppv)CdCX@6LdFUE*D(Kb4tZR(e!qP+=prLqzbAd zFie;+mw6k8mv~U@r%WN$r4-?3b)9=AhFGqui+t=Rb?ovNv?USW`%&A-IXL9x9 JWB#XpegKQ8EdKxi delta 335 zcmZqRy}>m>K_<8~Pr)~_NWsWh!N}0c(89{VP{GwDM8U|w&}8xgMtP3p{GwFblA_Yd z^BJWk_Hl{>nW?;7`py}t$=Rtz#rk?BMX9N_MnJWalOHg0@`2QX6oe<1q!t-ZVvL?# z&8WZ(F+dqgO955#g4rJ#wUtcGjEpTT42>)df!d-{b5atahJyHDVM|P>^wh*`XGXY-Cq9sx%*_}8bml_ho#Hk5 KC6gGE-Kqeelww2x diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs index 4b88e50..679f3ae 100644 --- a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs @@ -1,4 +1,4 @@ -content_assist_lru_history= +content_assist_lru_history= content_assist_number_of_computers=13 content_assist_proposals_background=255,255,255 content_assist_proposals_foreground=0,0,0 diff --git a/.metadata/.plugins/org.eclipse.jdt.core/externalLibsTimeStamps b/.metadata/.plugins/org.eclipse.jdt.core/externalLibsTimeStamps index c4f4e5ac1c893877ddce901d23036ae099d03074..3396515c2b7276d980e6250f4228477f83cf0611 100644 GIT binary patch delta 77 zcmey*x{ZyEfq{Xa!EEwJMzx7L?TorWhO$UXUU7VJie6S?5d#CGk?a}QqYT<|<}(ggStqaY;orQ$?GGy-H_!}_X^bGlHcnn>rMmgP&t+CV z9%S)Nn-2sru}wY`$G`bv#BWwUK4i%)U`_wyF0;yPW#I8G%B)Jwb5G38%u5HV0vih= z_$R+hv6cgA+{VBal3G-hn3)H3GKP{IkPg?kg5bPT7;qU7TGGhk=yH}8F wd~lF6h_{o0%PZ8+GXyTZi-8*|9pvvH0#dRYqQS@03B=pOzz5L)GytLr05^wIKL7v# delta 242 zcmex;opIu6Mqvg91|}$GU|@9&E=eq!C|SkGw{eP;1Eb#L33~FIue#l2oxIGApV1J^ zz3X#_b@DnNenuS-ck;Uk_Ra5uF0fAC8N|LxZA9g&&NSE zZ01P4&dRuD@`EfXM!w0vv#c}Nfc9@?;Bj^K@eBxdjrZ{Pb!7w!ZDU~f3UZAP4sr(Z rwli>fh5C7hz@>LEa6_eo{QW~fN_Ijt_;@;jc)J+*AR2%MKr{gWzi3E@ diff --git a/AStar/src/Game.java b/AStar/src/Game.java index 470571f..6fe12ed 100644 --- a/AStar/src/Game.java +++ b/AStar/src/Game.java @@ -6,7 +6,7 @@ public class Game extends Main { private Map map; public Game(String title, int width, int height, double scale, double updatesPerSecond) { - super(title, width, height, scale, updatesPerSecond); + super(title, width, height, scale, scale, updatesPerSecond); map = new Map(width / Tile.EMPTY.getSprite().getSize(), height / Tile.EMPTY.getSprite().getSize()); showCursor(false); Sprites.makeSprites(); diff --git a/AStar/src/Map.java b/AStar/src/Map.java index 7079550..6f44cde 100644 --- a/AStar/src/Map.java +++ b/AStar/src/Map.java @@ -97,7 +97,7 @@ private void pathfind() { while (n.getFrom() != null) { int i = n.getPosY() * getWidth() + n.getPosX(), i2 = n.getFromY() * getWidth() + n.getFromX(); if (i < 0 || i >= tiles.length || i2 < 0 || i2 >= tiles.length) { - continue; + break; } paths[i] = n.getCount(); n = nodes[n.getFromY() * getWidth() + n.getFromX()]; diff --git a/Cube/.classpath b/Cube/.classpath new file mode 100644 index 0000000..fb565a5 --- /dev/null +++ b/Cube/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Cube/.project b/Cube/.project new file mode 100644 index 0000000..18c451d --- /dev/null +++ b/Cube/.project @@ -0,0 +1,17 @@ + + + Cube + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Cube/.settings/org.eclipse.jdt.core.prefs b/Cube/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..7341ab1 --- /dev/null +++ b/Cube/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/Cube/src/Array2D.java b/Cube/src/Array2D.java new file mode 100644 index 0000000..6010d10 --- /dev/null +++ b/Cube/src/Array2D.java @@ -0,0 +1,53 @@ + + +public class Array2D { + int[] array; + private int width; + + public Array2D(int width, int height) { + this.width = width; + array = new int[width * height]; + } + + public boolean set(int x, int y, int value) { + if (x < 0 || y < 0 || x >= getWidth() || y >= getHeight()) + return false; + array[y * getWidth() + x] = value; + return true; + } + + public int get(int x, int y) { + if (y < 0 || x < 0 || y >= getHeight() || x >= getWidth()) + return -1; + return array[y * getWidth() + x]; + } + + public int getI(int i) { + if (i >= array.length || i < 0) + return -1; + return array[i]; + } + + public boolean setI(int i, int value) { + if (i >= array.length || i < 0) + return false; + array[i] = value; + return true; + } + + public int getWidth() { + return width; + } + + public int getHeight() { + return array.length / getWidth(); + } + + public int getLength() { + return array.length; + } + + public int[] getArray() { + return array; + } +} diff --git a/Cube/src/KeyReader.java b/Cube/src/KeyReader.java new file mode 100644 index 0000000..f85e0e4 --- /dev/null +++ b/Cube/src/KeyReader.java @@ -0,0 +1,47 @@ + + +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; + +public class KeyReader implements KeyListener { + private boolean[] keys; + + public KeyReader() { + keys = new boolean[120]; + } + + public boolean getUp() { + return keys[KeyEvent.VK_UP]; + } + + public boolean getDown() { + return keys[KeyEvent.VK_DOWN]; + } + + public boolean getLeft() { + return keys[KeyEvent.VK_LEFT]; + } + + public boolean getRight() { + return keys[KeyEvent.VK_RIGHT]; + } + + public boolean getSpace() { + return keys[KeyEvent.VK_SPACE]; + } + + @Override + public void keyPressed(KeyEvent e) { + keys[e.getKeyCode()] = true; + } + + @Override + public void keyReleased(KeyEvent e) { + keys[e.getKeyCode()] = false; + } + + @Override + public void keyTyped(KeyEvent e) { + + } +} diff --git a/Cube/src/Main.java b/Cube/src/Main.java new file mode 100644 index 0000000..bcc22e4 --- /dev/null +++ b/Cube/src/Main.java @@ -0,0 +1,159 @@ +import java.awt.Canvas; +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Point; +import java.awt.Toolkit; +import java.awt.image.BufferStrategy; +import java.awt.image.BufferedImage; +import java.awt.image.DataBufferInt; + +import javax.swing.JFrame; + +import com.mrizen.cube.d2.Point2d; + +public class Main extends Canvas implements Runnable { + private static final long serialVersionUID = 4648172894076113183L; + + private boolean running; + private String title; + private Screen screen; + private BufferedImage image; + private int[] pixels; + private JFrame frame; + private Thread thread; + private double updatesPerSecond; + private KeyReader keys; + private MouseReader mouse; + + public Main(String title, int width, int height, double scale, double updatesPerSecond) { + this.title = title; + this.updatesPerSecond = updatesPerSecond; + + frame = new JFrame(); + frame.setResizable(false); + frame.setTitle(title); + frame.add(this); + setDimension(width, height, scale); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + + screen = new Screen(width, height); + + keys = new KeyReader(); + addKeyListener(keys); + + mouse = new MouseReader(scale); + addMouseMotionListener(mouse); + addMouseListener(mouse); + + image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData(); + + running = false; + } + + public KeyReader getKeys() { + return keys; + } + + public MouseReader getMouse() { + return mouse; + } + + protected void setDimension(int width, int height, double scale) { + setPreferredSize(new Dimension((int) (width * scale), (int) (height * scale))); + frame.pack(); + } + + protected void update() { + + } + + protected void render() { + screen.drawLine2d(new Point2d(1, 1), new Point2d(1, 1), 0); + } + + private void renderPrivate() { + BufferStrategy bs = getBufferStrategy(); + if (bs == null) { + createBufferStrategy(3); + return; + } + screen.clear(); + render(); + for (int i = 0; i < screen.getPixels().getLength(); i++) { + pixels[i] = screen.getPixels().getI(i); + } + Graphics g = bs.getDrawGraphics(); + g.drawImage(image, 0, 0, getWidth(), getHeight(), null); + g.dispose(); + bs.show(); + } + + @Override + public void run() { + long lastTime = System.nanoTime(); + long timer = System.currentTimeMillis(); + final double ns = 1000000000.0 / updatesPerSecond; + double delta = 0; + int frames = 0; + int updates = 0; + requestFocus(); + while (running) { + long now = System.nanoTime(); + delta += (now - lastTime) / ns; + lastTime = now; + while (delta > 1) { + update(); + updates++; + delta--; + } + renderPrivate(); + frames++; + if (System.currentTimeMillis() - timer > 1000) { + timer += 1000; + frame.setTitle(title + " | " + updates + " ups, " + frames + " fps"); + updates = 0; + frames = 0; + } + } + } + + protected synchronized void start() { + running = true; + thread = new Thread(this, "Display"); + thread.start(); + } + + protected synchronized void stop() { + running = false; + try { + thread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + public static void main(String[] args) { + String title = "Test"; + int width = 300; + int height = width / 16 * 9; + int scale = 6; + double updatesPerSecond = 60; + + Main main = new Main(title, width, height, scale, updatesPerSecond); + main.start(); + } + + public Screen getScreen() { + return screen; + } + + protected void showCursor(boolean show) { + BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB); + Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0), "blank cursor"); + frame.getContentPane().setCursor(blankCursor); + } +} diff --git a/Cube/src/MouseReader.java b/Cube/src/MouseReader.java new file mode 100644 index 0000000..03ff1b3 --- /dev/null +++ b/Cube/src/MouseReader.java @@ -0,0 +1,77 @@ + + +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; + +public class MouseReader implements MouseListener, MouseMotionListener { + + private int mouseX; + private int mouseY; + private int mouseB; + private double scale; + + public MouseReader(double scale) { + this.scale = scale; + mouseX = -1; + mouseY = -1; + mouseB = -1; + } + + public int getX() { + return mouseX; + } + + public int getScaledX() { + return (int) Math.round(mouseX / scale); + } + + public int getScaledY() { + return (int) Math.round(mouseY / scale); + } + + public int getY() { + return mouseY; + } + + public int getButton() { + return mouseB; + } + + @Override + public void mouseClicked(MouseEvent e) { + + } + + @Override + public void mouseEntered(MouseEvent e) { + + } + + @Override + public void mouseExited(MouseEvent e) { + + } + + @Override + public void mousePressed(MouseEvent e) { + mouseB = e.getButton(); + } + + @Override + public void mouseReleased(MouseEvent e) { + mouseB = -1; + } + + @Override + public void mouseDragged(MouseEvent e) { + mouseX = e.getX(); + mouseY = e.getY(); + } + + @Override + public void mouseMoved(MouseEvent e) { + mouseX = e.getX(); + mouseY = e.getY(); + } +} diff --git a/Cube/src/Screen.java b/Cube/src/Screen.java new file mode 100644 index 0000000..6247a6a --- /dev/null +++ b/Cube/src/Screen.java @@ -0,0 +1,37 @@ +import com.mrizen.cube.d2.Point2d; +import com.mrizen.cube.d2.Shape2d; + +public class Screen { + private Array2D pixels; + + public Screen(int width, int height) { + pixels = new Array2D(width, height); + } + + public void clear() { + for (int i = 0; i < pixels.getLength(); i++) { + pixels.setI(i, 0); + } + } + + public void drawShape2d(Shape2d shape) { + Point2d[] points = shape.getPoints(); + drawLine2d(points[0], points[1], shape.getColor()); + } + + public void drawLine2d(Point2d pointA, Point2d pointB, int color) { + float deltaY = pointB.getY() - pointA.getY(); + float deltaX = pointB.getX() - pointA.getX(); + float m; + if (deltaX == 0) + m = ; + else + m = deltaY / deltaX; + float b = pointA.getY() - m * pointA.getX(); + System.out.println(m + " " + b); + } + + public Array2D getPixels() { + return pixels; + } +} \ No newline at end of file diff --git a/Cube/src/com/mrizen/cube/d2/Point2d.java b/Cube/src/com/mrizen/cube/d2/Point2d.java new file mode 100644 index 0000000..86c16e8 --- /dev/null +++ b/Cube/src/com/mrizen/cube/d2/Point2d.java @@ -0,0 +1,19 @@ +package com.mrizen.cube.d2; + +public class Point2d { + private int x; + private int y; + + public Point2d(int x, int y) { + this.x = x; + this.y = y; + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } +} diff --git a/Cube/src/com/mrizen/cube/d2/Shape2d.java b/Cube/src/com/mrizen/cube/d2/Shape2d.java new file mode 100644 index 0000000..ba87d80 --- /dev/null +++ b/Cube/src/com/mrizen/cube/d2/Shape2d.java @@ -0,0 +1,19 @@ +package com.mrizen.cube.d2; + +public class Shape2d { + private Point2d[] points; + private int color; + + public Shape2d(Point2d[] points, int color) { + this.points = points; + this.color = color; + } + + public Point2d[] getPoints() { + return points; + } + + public int getColor() { + return color; + } +} diff --git a/Cube/src/com/mrizen/cube/d3/Point3d.java b/Cube/src/com/mrizen/cube/d3/Point3d.java new file mode 100644 index 0000000..f7fbeba --- /dev/null +++ b/Cube/src/com/mrizen/cube/d3/Point3d.java @@ -0,0 +1,7 @@ +package com.mrizen.cube.d3; + +public class Point3d { + public Point3d() { + + } +} diff --git a/Darkness/.classpath b/Darkness/.classpath new file mode 100644 index 0000000..cd1fc48 --- /dev/null +++ b/Darkness/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Darkness/.project b/Darkness/.project new file mode 100644 index 0000000..307a8c3 --- /dev/null +++ b/Darkness/.project @@ -0,0 +1,17 @@ + + + Darkness + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Darkness/.settings/org.eclipse.jdt.core.prefs b/Darkness/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..7341ab1 --- /dev/null +++ b/Darkness/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/Darkness/src/com/mrizen/darkness/Game.java b/Darkness/src/com/mrizen/darkness/Game.java new file mode 100644 index 0000000..5e4fd75 --- /dev/null +++ b/Darkness/src/com/mrizen/darkness/Game.java @@ -0,0 +1,34 @@ +package com.mrizen.darkness; + +import com.mrizen.gaming.Main; + +public class Game extends Main { + private static final long serialVersionUID = -7301747131889422012L; + + private Map map; + + public Game(String title, int width, int height, double hScale, double vScale, double updatesPerSecond) { + super(title, width, height, hScale, vScale, updatesPerSecond); + map = new Map(64, 64); + } + + protected void render() { + map.render(getScreen()); + } + + protected void update() { + map.update(); + } + + public static void main(String[] args) { + String title = "Darkness"; + int width = 256; + int height = width / 16 * 9; + double updatesPerSecond = 60; + double hScale = 3; + double vScale = 3; + + Game game = new Game(title, width, height, hScale, vScale, updatesPerSecond); + game.start(); + } +} diff --git a/Darkness/src/com/mrizen/darkness/Map.java b/Darkness/src/com/mrizen/darkness/Map.java new file mode 100644 index 0000000..d2e6477 --- /dev/null +++ b/Darkness/src/com/mrizen/darkness/Map.java @@ -0,0 +1,79 @@ +package com.mrizen.darkness; + +import java.util.ArrayList; +import java.util.Random; + +import com.mrizen.gaming.Array2D; +import com.mrizen.gaming.Screen; + +public class Map { + private Array2D darkness; + private Array2D terrain; + private int darknessSize; + private int darknessMax; + + public Map(int width, int height) { + darknessSize = 1; + darknessMax = 0xFF; + darkness = new Array2D(width, height); + terrain = new Array2D(width, height); + } + + public void renderTile(Screen screen, int xTile, int yTile) { + int i = 0xFFFFFF; + i -= darkness.get(xTile, yTile) * 0xFFFFFF / darknessMax; + screen.drawColor(i, xTile * darknessSize, yTile * darknessSize, darknessSize, darknessSize); + } + + public void render(Screen screen) { + screen.setOffset(0, 0); + for (int yTile = 0; yTile < terrain.getHeight(); yTile++) { + for (int xTile = 0; xTile < terrain.getWidth(); xTile++) { + renderTile(screen, xTile, yTile); + } + } + } + + public void update() { + Random rand = new Random(); + int addin = 5; + /*for (int y = 0; y < darkness.getHeight(); y++) { + for (int x = 0; x < darkness.getWidth(); x++) { + if (rand.nextInt(10) == 0) + if (darkness.get(x, y) < darknessMax) + darkness.add(x, y, addin); + } + }*/ + darkness.set(0, 0, darknessMax); + //darkness.set(rand.nextInt(darkness.getWidth()), rand.nextInt(darkness.getHeight()), darknessMax); + Array2D darkness2 = new Array2D(darkness.getWidth(), darkness.getHeight()); + for (int y = 0; y < darkness.getHeight(); y++) { + for (int x = 0; x < darkness.getWidth(); x++) { + ArrayList darks = new ArrayList(); + darks.add(darkness.get(x, y)); + if (darkness.get(x - 1, y) != -1) + darks.add(darkness.get(x - 1, y)); + if (darkness.get(x + 1, y) != -1) + darks.add(darkness.get(x + 1, y)); + if (darkness.get(x, y + 1) != -1) + darks.add(darkness.get(x, y + 1)); + if (darkness.get(x, y - 1) != -1) + darks.add(darkness.get(x, y - 1)); + float darkTotal = 0; + for (int i = 0; i < darks.size(); i++) { + darkTotal += darks.get(i); + } + if (darkTotal > darks.size()) + darkness2.set(x, y, (int) (darkTotal / darks.size())); + else if (darkTotal != 0) { + darkness2.set(x, y, 1); + } + } + } + for (int y = 0; y < darkness.getHeight(); y++) { + for (int x = 0; x < darkness.getWidth(); x++) { + darkness.set(x, y, darkness2.get(x, y)); + } + } + } +} diff --git a/Darkness2/.classpath b/Darkness2/.classpath new file mode 100644 index 0000000..cd1fc48 --- /dev/null +++ b/Darkness2/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Darkness2/.project b/Darkness2/.project new file mode 100644 index 0000000..8850941 --- /dev/null +++ b/Darkness2/.project @@ -0,0 +1,17 @@ + + + Darkness2 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Darkness2/.settings/org.eclipse.jdt.core.prefs b/Darkness2/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..7341ab1 --- /dev/null +++ b/Darkness2/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/Darkness2/src/Game.java b/Darkness2/src/Game.java new file mode 100644 index 0000000..80169de --- /dev/null +++ b/Darkness2/src/Game.java @@ -0,0 +1,32 @@ +import com.mrizen.gaming.Main; + +public class Game extends Main { + private static final long serialVersionUID = -7301747131889422012L; + + private Map map; + + public Game(String title, int width, int height, double hScale, double vScale, double updatesPerSecond) { + super(title, width, height, hScale, vScale, updatesPerSecond); + map = new Map(64, 64); + } + + protected void render() { + map.render(getScreen()); + } + + protected void update() { + map.update(); + } + + public static void main(String[] args) { + String title = "Darkness"; + int width = 256; + int height = width / 16 * 9; + double updatesPerSecond = 60; + double hScale = 3; + double vScale = 3; + + Game game = new Game(title, width, height, hScale, vScale, updatesPerSecond); + game.start(); + } +} diff --git a/Darkness2/src/Map.java b/Darkness2/src/Map.java new file mode 100644 index 0000000..cd0d090 --- /dev/null +++ b/Darkness2/src/Map.java @@ -0,0 +1,53 @@ +import com.mrizen.gaming.Array2D; +import com.mrizen.gaming.Screen; + +public class Map { + private Array2D dark; + private int darkMax; + private int darkSize; + + public Map(int width, int height) { + dark = new Array2D(width, height); + darkMax = 255; + } + + public void renderTile(Screen screen, int xTile, int yTile) { + int i = 0xFFFFFF; + i -= dark.get(xTile, yTile) * 0xFFFFFF / darkMax; + screen.drawColor(i, xTile * darkSize, yTile * darkSize, darkSize, darkSize); + } + + public void render(Screen screen) { + screen.setOffset(0, 0); + for (int yTile = 0; yTile < dark.getHeight(); yTile++) { + for (int xTile = 0; xTile < dark.getWidth(); xTile++) { + renderTile(screen, xTile, yTile); + } + } + } + + public void update() { + Array2D dark2 = new Array2D(dark.getWidth(), dark.getHeight()); + for (int y = 0; y < dark.getHeight(); y++) { + for (int x = 0; x < dark.getWidth(); x++) { + Array2D darkSlice = dark.getSlice(x - 1, y - 1, x + 1, y + 1); + int darkTotal = 0; + int darkCount = 0; + darkCount++; + darkTotal += darkSlice.get(x, y); + darkCount++; + darkTotal += darkSlice.get(x + 1, y); + darkCount++; + darkTotal += darkSlice.get(x - 1, y - 1); + darkCount++; + darkTotal += darkSlice.get(x - 1, y + 1); + dark2.set(x, y, darkTotal / darkCount); + } + } + for (int y = 0; y < dark.getHeight(); y++) { + for (int x = 0; x < dark.getWidth(); x++) { + dark.set(x, y, dark2.get(x, y)); + } + } + } +} diff --git a/Dunegon Gen/.classpath b/Dunegon Gen/.classpath new file mode 100644 index 0000000..cd1fc48 --- /dev/null +++ b/Dunegon Gen/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Dunegon Gen/.project b/Dunegon Gen/.project new file mode 100644 index 0000000..8e8dac6 --- /dev/null +++ b/Dunegon Gen/.project @@ -0,0 +1,17 @@ + + + Dunegon Gen + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Dunegon Gen/.settings/org.eclipse.jdt.core.prefs b/Dunegon Gen/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..7341ab1 --- /dev/null +++ b/Dunegon Gen/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/Dunegon Gen/src/Game.java b/Dunegon Gen/src/Game.java new file mode 100644 index 0000000..a9ca10a --- /dev/null +++ b/Dunegon Gen/src/Game.java @@ -0,0 +1,28 @@ +import com.mrizen.gaming.Main; + +public class Game extends Main { + private static final long serialVersionUID = -7803629994015778818L; + + private Map map; + private int anim; + + public Game() { + super("Dunegon Gen", 256, 256 / 16 * 9, 3, 3, 60); + map = new Map(32, 32); + anim = 0; + } + + public void update() { + anim++; + map.update(getKeys(), anim); + } + + public void render() { + map.render(getScreen()); + } + + public static void main(String[] args) { + Game game = new Game(); + game.start(); + } +} diff --git a/Dunegon Gen/src/Map.java b/Dunegon Gen/src/Map.java new file mode 100644 index 0000000..420f1ed --- /dev/null +++ b/Dunegon Gen/src/Map.java @@ -0,0 +1,80 @@ +import com.mrizen.gaming.Array2D; +import com.mrizen.gaming.KeyReader; +import com.mrizen.gaming.Point2D; +import com.mrizen.gaming.Screen; + +public class Map { + private Array2D tiles; + private Point2D offset; + private int lastMoveAnim; + + public Map(int width, int height) { + tiles = new Array2D(width, height); + offset = new Point2D(0, 0); + generateDungeon(2, 2, 2); + } + + private void generateDungeon(int cellsWidth, int cellsHeight, int roomChance) { + Array2D rooms = new Array2D(cellsWidth, cellsHeight); + for (int y = 0; y < rooms.getHeight(); y++) { + for (int x = 0; x < rooms.getWidth(); x++) { + if (Math.floor(Math.random() * roomChance) == 0) { + rooms.set(x, y, 1); + } + } + } + + } + + public void render(Screen screen) { + screen.setOffset(offset.getX(), offset.getY()); + for (int yTile = 0; yTile < tiles.getHeight(); yTile++) { + for (int xTile = 0; xTile < tiles.getWidth(); xTile++) { + screen.drawSprite(getTile(xTile, yTile).getSprite(), xTile * Tile.SIZE, yTile * Tile.SIZE); + } + } + } + + public void update(KeyReader keys, int anim) { + if (anim - lastMoveAnim >= 10) { + if (keys.getRight()) { + offset.setX(offset.getX() - Tile.SIZE); + lastMoveAnim = anim; + } + if (keys.getLeft()) { + offset.setX(offset.getX() + Tile.SIZE); + lastMoveAnim = anim; + } + if (keys.getUp()) { + offset.setY(offset.getY() + Tile.SIZE); + lastMoveAnim = anim; + } + if (keys.getDown()) { + offset.setY(offset.getY() - Tile.SIZE); + lastMoveAnim = anim; + } + } + } + + protected void scrollTo(int offsetX, int offsetY, int anim) { + offset.setX(offsetX); + offset.setY(offsetY); + lastMoveAnim = anim; + } + + private Tile getTileById(int id) { + if (id == Tile.WALL.getId()) { + return Tile.WALL; + } else if (id == Tile.FLOOR.getId()) + return Tile.FLOOR; + return Tile.EMPTY; + } + + private Tile getTile(int x, int y) { + return getTileById(tiles.get(x, y)); + } + + public Array2D getTiles() { + return tiles; + } +} diff --git a/Dunegon Gen/src/Sprites.java b/Dunegon Gen/src/Sprites.java new file mode 100644 index 0000000..c4d4b5a --- /dev/null +++ b/Dunegon Gen/src/Sprites.java @@ -0,0 +1,7 @@ +import com.mrizen.gaming.Sprite; + +public class Sprites { + public static final Sprite WALL = new Sprite(Tile.SIZE).drawFill(Sprite.BLACK); + public static final Sprite FLOOR = new Sprite(Tile.SIZE).drawFill(Sprite.GRAY); + public static final Sprite EMPTY = new Sprite(Tile.SIZE).drawFill(Sprite.BLUE); +} diff --git a/Dunegon Gen/src/Tile.java b/Dunegon Gen/src/Tile.java new file mode 100644 index 0000000..13bae77 --- /dev/null +++ b/Dunegon Gen/src/Tile.java @@ -0,0 +1,30 @@ +import com.mrizen.gaming.Sprite; + +public class Tile { + + public static final Tile WALL = new Tile(Sprites.WALL, nextId()); + public static final Tile EMPTY = new Tile(Sprites.EMPTY, nextId()); + public static final Tile FLOOR = new Tile(Sprites.FLOOR, nextId()); + public static final int SIZE = 16; + private static int idCount = 0; + + private Sprite sprite; + private int id; + + public Tile(Sprite sprite, int id) { + this.sprite = sprite; + this.id = id; + } + + public int getId() { + return id; + } + + public Sprite getSprite() { + return sprite; + } + + public static int nextId() { + return idCount++; + } +} diff --git a/DungeonCrawler/.classpath b/DungeonCrawler/.classpath new file mode 100644 index 0000000..dc0e591 --- /dev/null +++ b/DungeonCrawler/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/DungeonCrawler/.project b/DungeonCrawler/.project new file mode 100644 index 0000000..0dac40f --- /dev/null +++ b/DungeonCrawler/.project @@ -0,0 +1,17 @@ + + + DungeonCrawler + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/DungeonCrawler/.settings/org.eclipse.jdt.core.prefs b/DungeonCrawler/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..7341ab1 --- /dev/null +++ b/DungeonCrawler/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/DungeonCrawler/res/tiles.png b/DungeonCrawler/res/tiles.png new file mode 100644 index 0000000000000000000000000000000000000000..e1dab0570f89b6b2f33a3aadd0a19d8b82b0b4b0 GIT binary patch literal 2128 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G$6&2?&#~tz_78O`%fY(kk47* z5n0T@z*GdnjH+`}Vu6BEC9V-A!TD(=<%vb93;~Imc_n&&t|1C##(JiDhKBB+oy-{+ z*w1*nIEGZjy}cdXb%#yF^`hLY_GdG#MI5&nyqf;K-7hfvuxjdM?n9bOo-Ds#_xIP= z<#%r1o?ZMd^8H7F|Ns8}p8u|baZ1I$BkuKej57a2|G(P9aPRTYOK<;GEI7~qqx>BA zgZ~x#N_N}ZpE>^g{JTHJ{q?_?ehAfX#xC%AzWuM?k2mW#=zlc-{rPZBjotsBi}%~x z{YK~^LJ1*z>@D>h{zDu&qyCeS#s57}3z`33{>=2?r~3Ef^;iFYtzoR`+Qts|78zD#lMq##Tnus z&A&50o}vHzeV|LfgTn9s@5X=UDjD}2|Gf0}-=B^DURE-G_%pd$pJCq-`RfB{qyGNY^N>i|U$tVr+`r?of7d_)Xf^v^_2=9Vy#Jj2_iEw4lRv?+vj5lpUqFe% zaQoLVseM&HpO-S`9}qe}oox@Jw@tj%2R0p$0_hD@keI$-`OTc_-p_2hR5KFOb$_0|=dgYr z_jr#ZwVjV_SN%`xL+5s0x5&Rho1lW&75@(uEvBQ}YNwtti@c{r}I; a@`n}geYmzZAq80bGkCiCxvX entities; + + public Map(int width, int height) { + tiles = new Array2D(width, height); + entities = new ArrayList(); + } + + public void render(Screen screen) { + for (int y = 0; y < tiles.getHeight(); y++) { + for (int x = 0; x < tiles.getWidth(); x++) { + getTile(x, y).renderTile(screen, x, y); + } + } + for (int i = 0; i < entities.size(); i++) { + entities.get(i).render(screen); + } + } + + protected Tile getTile(int x, int y) { + return getTileById(tiles.get(x, y)); + } + + protected Tile getTileById(int id) { + if (id == Tile.floor1.getId()) + return Tile.floor1; + if (id == Tile.floor2.getId()) + return Tile.floor2; + if (id == Tile.floor3.getId()) + return Tile.floor3; + return Tile.nullTile; + } + + public void update(KeyReader keyReader, long anim) { + } + + public void addEntity(Entity entity) { + entities.add(entity); + } + + public void removeEntity(Entity entity) { + entities.remove(entity); + } + + protected Array2D getTiles() { + return tiles; + } +} diff --git a/DungeonCrawler/src/com/mrizen/dungeoncrawler/Sprites.java b/DungeonCrawler/src/com/mrizen/dungeoncrawler/Sprites.java new file mode 100644 index 0000000..dc656a5 --- /dev/null +++ b/DungeonCrawler/src/com/mrizen/dungeoncrawler/Sprites.java @@ -0,0 +1,13 @@ +package com.mrizen.dungeoncrawler; + +import com.mrizen.gaming.Sprite; +import com.mrizen.gaming.Spritesheet; + +public class Sprites { + public static final Spritesheet tiles = new Spritesheet("/tiles.png"); + + public static final Sprite floor1 = new Sprite(16).drawLoad(0, 0, tiles); + public static final Sprite floor2 = new Sprite(16).drawLoad(0, 1, tiles); + public static final Sprite floor3 = new Sprite(16).drawLoad(0, 2, tiles); + public static final Sprite nullTile = new Sprite(16).drawFill(0xFF0066FF); +} diff --git a/DungeonCrawler/src/com/mrizen/dungeoncrawler/Tile.java b/DungeonCrawler/src/com/mrizen/dungeoncrawler/Tile.java new file mode 100644 index 0000000..c7dfa62 --- /dev/null +++ b/DungeonCrawler/src/com/mrizen/dungeoncrawler/Tile.java @@ -0,0 +1,39 @@ +package com.mrizen.dungeoncrawler; + +import com.mrizen.gaming.*; + +public class Tile { + private Sprite sprite; + private int id; + + public static final Tile nullTile = new Tile(Sprites.nullTile, 0); + public static final Tile floor1 = new Tile(Sprites.floor1, 1); + public static final Tile floor2 = new Tile(Sprites.floor2, 1); + public static final Tile floor3 = new Tile(Sprites.floor3, 1); + + public Tile(Sprite sprite, int id) { + this.sprite = sprite; + this.id = id; + } + + public void renderPos(Screen screen, int xPos, int yPos) { + screen.drawSprite(sprite, xPos, yPos); + } + + public void update(long anim) { + + } + + public void renderTile(Screen screen, int xTile, int yTile) { + int size = getSprite().getSize(); + renderPos(screen, xTile * size, yTile * size); + } + + public int getId() { + return id; + } + + public Sprite getSprite() { + return sprite; + } +} diff --git a/Energy/.classpath b/Energy/.classpath new file mode 100644 index 0000000..cd1fc48 --- /dev/null +++ b/Energy/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Energy/.project b/Energy/.project new file mode 100644 index 0000000..95cf8d2 --- /dev/null +++ b/Energy/.project @@ -0,0 +1,17 @@ + + + Energy + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Energy/.settings/org.eclipse.jdt.core.prefs b/Energy/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..7341ab1 --- /dev/null +++ b/Energy/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/Energy/src/com/mrizen/energy/Game.java b/Energy/src/com/mrizen/energy/Game.java new file mode 100644 index 0000000..f32170f --- /dev/null +++ b/Energy/src/com/mrizen/energy/Game.java @@ -0,0 +1,47 @@ +package com.mrizen.energy; + +import com.mrizen.gaming.KeyReader; +import com.mrizen.gaming.Main; + +public class Game extends Main { + private static final long serialVersionUID = 507915546143071520L; + + private Map map; + private int[] view; + + public Game(String title, int width, int height, double hScale, double vScale, double updatesPerSecond) { + super(title, width, height, updatesPerSecond); + setDimension(width, height, hScale, vScale); + view = new int[2]; + map = new Map(16, 16); + } + + protected void render() { + getScreen().setOffset(-view[0], -view[1]); + map.render(getScreen()); + } + + protected void update() { + KeyReader keys = getKeys(); + if (keys.getLeft()) + view[0]--; + if (keys.getRight()) + view[0]++; + if (keys.getUp()) + view[1]--; + if (keys.getDown()) + view[1]++; + map.update(keys, getMouse()); + } + + public static void main(String[] args) { + String title = "Energy"; + int width = 256; + int height = width / 16 * 9; + double hScale = 3; + double vScale = 3; + double updatesPerSecond = 60; + Game game = new Game(title, width, height, hScale, vScale, updatesPerSecond); + game.start(); + } +} diff --git a/Energy/src/com/mrizen/energy/Map.java b/Energy/src/com/mrizen/energy/Map.java new file mode 100644 index 0000000..df39c97 --- /dev/null +++ b/Energy/src/com/mrizen/energy/Map.java @@ -0,0 +1,56 @@ +package com.mrizen.energy; + +import com.mrizen.gaming.Array2D; +import com.mrizen.gaming.KeyReader; +import com.mrizen.gaming.MouseReader; +import com.mrizen.gaming.Screen; + +public class Map { + private Array2D tiles; + + public Map(int width, int height) { + tiles = new Array2D(width, height); + generateMap(); + } + + public void render(Screen screen) { + for (int yTile = 0; yTile < tiles.getHeight(); yTile++) { + for (int xTile = 0; xTile < tiles.getWidth(); xTile++) { + getTile(xTile, yTile).render(screen, xTile, yTile); + } + } + } + + public void update(KeyReader keys, MouseReader mouse) { + for (int y = 0; y < tiles.getHeight(); y++) { + for (int x = 0; x < tiles.getWidth(); x++) { + + } + } + } + + public void generateMap() { + for (int y = 0; y < tiles.getHeight(); y++) { + for (int x = 0; x < tiles.getWidth(); x++) { + if (x % 3 == 1 && y % 3 == 1) + tiles.set(x, y, Tile.NODE.getId()); + else + tiles.set(x, y, Tile.FLAT.getId()); + } + } + } + + public Tile getTile(int x, int y) { + return getTile(tiles.get(x, y)); + } + + public Tile getTile(int id) { + if (id == Tile.FLAT.getId()) + return Tile.FLAT; + else if (id == Tile.WALL.getId()) + return Tile.WALL; + else if (id == Tile.NODE.getId()) + return Tile.NODE; + return Tile.FLAT; + } +} diff --git a/Energy/src/com/mrizen/energy/Sprites.java b/Energy/src/com/mrizen/energy/Sprites.java new file mode 100644 index 0000000..f79c414 --- /dev/null +++ b/Energy/src/com/mrizen/energy/Sprites.java @@ -0,0 +1,9 @@ +package com.mrizen.energy; + +import com.mrizen.gaming.Sprite; + +public class Sprites { + public static final Sprite FLAT = new Sprite(16).drawFill(Sprite.GRAY); + public static final Sprite NODE = new Sprite(16).drawFill(Sprite.GREEN); + public static final Sprite WALL = new Sprite(16).drawFill(Sprite.BLACK); +} diff --git a/Energy/src/com/mrizen/energy/Tile.java b/Energy/src/com/mrizen/energy/Tile.java new file mode 100644 index 0000000..9acecf0 --- /dev/null +++ b/Energy/src/com/mrizen/energy/Tile.java @@ -0,0 +1,32 @@ +package com.mrizen.energy; + +import com.mrizen.gaming.Screen; +import com.mrizen.gaming.Sprite; + +public class Tile { + public static final Tile FLAT = new Tile(0, Sprites.FLAT); + public static final Tile WALL = new TileWall(1, Sprites.WALL); + public static final Tile NODE = new TileNode(2); + + private int id; + private Sprite sprite; + + public Tile(int id, Sprite sprite) { + this.id = id; + this.sprite = sprite; + + } + + public boolean getSolid() { + return false; + } + + public int getId() { + return id; + } + + public void render(Screen screen, int xTile, int yTile) { + int size = sprite.getSize(); + screen.drawSprite(sprite, xTile * size, yTile * size); + } +} diff --git a/Energy/src/com/mrizen/energy/TileNode.java b/Energy/src/com/mrizen/energy/TileNode.java new file mode 100644 index 0000000..a1d5a56 --- /dev/null +++ b/Energy/src/com/mrizen/energy/TileNode.java @@ -0,0 +1,12 @@ +package com.mrizen.energy; + +public class TileNode extends Tile { + + public TileNode(int id) { + super(id, Sprites.NODE); + } + + public void update(Map tiles, int xTile, int yTile) { + + } +} diff --git a/Energy/src/com/mrizen/energy/TileWall.java b/Energy/src/com/mrizen/energy/TileWall.java new file mode 100644 index 0000000..da8861f --- /dev/null +++ b/Energy/src/com/mrizen/energy/TileWall.java @@ -0,0 +1,14 @@ +package com.mrizen.energy; + +import com.mrizen.gaming.Sprite; + +public class TileWall extends Tile { + + public TileWall(int id, Sprite sprite) { + super(id, sprite); + } + + public boolean getSolid() { + return true; + } +} diff --git a/Hills3/.classpath b/Hills3/.classpath new file mode 100644 index 0000000..fb565a5 --- /dev/null +++ b/Hills3/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Hills3/.project b/Hills3/.project new file mode 100644 index 0000000..15861b7 --- /dev/null +++ b/Hills3/.project @@ -0,0 +1,17 @@ + + + Hills3 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Hills3/.settings/org.eclipse.jdt.core.prefs b/Hills3/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..7341ab1 --- /dev/null +++ b/Hills3/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/Hills3/src/Game.java b/Hills3/src/Game.java new file mode 100644 index 0000000..63f6289 --- /dev/null +++ b/Hills3/src/Game.java @@ -0,0 +1,130 @@ +package com.mrizen.test; + +import java.awt.Canvas; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.image.BufferStrategy; +import java.awt.image.BufferedImage; +import java.awt.image.DataBufferInt; + +import javax.swing.JFrame; + +public class Game extends Canvas implements Runnable { + private static final long serialVersionUID = 1L; + + public static int width = 300; + public static int height = width / 16 * 9; + public static int scale = 3; + + private static String title = "Test"; + + private Thread thread; + private JFrame frame; + private boolean running = false; + private Screen screen; + private BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + private int[] pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData(); + private Keyboard key; + private Level level; + private EntityPlayer player; + private Mouse mouse; + + public Game() { + Dimension size = new Dimension(width * scale, height * scale); + setPreferredSize(size); + + frame = new JFrame(); + frame.setResizable(false); + frame.setTitle(title); + frame.add(game); + frame.pack(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + screen = new Screen(width, height); + key = new Keyboard(); + level = new SpawnLevel("/textures/level.png"); + player = new EntityPlayer(key); + + addKeyListener(key); + addMouseListener(mouse); + addMouseMotionListener(mouse); + } + + public synchronized void start() { + running = true; + thread = new Thread(this, "Display"); + thread.start(); + } + + public synchronized void stop() { + running = false; + try { + thread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + public void run() { + long lastTime = System.nanoTime(); + long timer = System.currentTimeMillis(); + final double ns = 1000000000.0 / 60.0; + double delta = 0; + int frames = 0; + int updates = 0; + requestFocus(); + while (running) { + long now = System.nanoTime(); + delta += (now - lastTime) / ns; + lastTime = now; + while (delta > 1) { + update(); + updates++; + delta--; + } + render(); + frames++; + if (System.currentTimeMillis() - timer > 1000) { + timer += 1000; + frame.setTitle(title + " | " + updates + " ups, " + frames + " fps"); + updates = 0; + frames = 0; + } + } + stop(); + } + + public void update() { + key.update(); + player.update(); + } + + public void render() { + BufferStrategy bs = getBufferStrategy(); + if (bs == null) { + createBufferStrategy(3); + return; + } + + screen.clear(); + int xScroll = player.x - screen.width / 2; + int yScroll = player.y - screen.height / 2; + level.render(xScroll, yScroll, screen); + player.render(screen); + + for (int i = 0; i < pixels.length; i++) { + pixels[i] = screen.pixels[i]; + } + + Graphics g = bs.getDrawGraphics(); + g.drawImage(image, 0, 0, getWidth(), getHeight(), null); + g.dispose(); + bs.show(); + } + + public static void main(String[] args) { + Game game = new Game(); + game.start(); + } +} \ No newline at end of file diff --git a/Hills3/src/Screen.java b/Hills3/src/Screen.java new file mode 100644 index 0000000..c45021f --- /dev/null +++ b/Hills3/src/Screen.java @@ -0,0 +1,7 @@ +public class Screen { + + public Screen() { + // TODO Auto-generated constructor stub + } + +} diff --git a/MrizenGaming/src/com/mrizen/gaming/Array2D.java b/MrizenGaming/src/com/mrizen/gaming/Array2D.java new file mode 100644 index 0000000..6811aa6 --- /dev/null +++ b/MrizenGaming/src/com/mrizen/gaming/Array2D.java @@ -0,0 +1,70 @@ +package com.mrizen.gaming; + +public class Array2D { + int[] array; + private int width; + + public Array2D(int width, int height) { + this.width = width; + array = new int[width * height]; + } + + public boolean set(int x, int y, int value) { + if (x < 0 || y < 0 || x >= getWidth() || y >= getHeight()) + return false; + array[y * getWidth() + x] = value; + return true; + } + + public int get(int x, int y) { + if (y < 0 || x < 0 || y >= getHeight() || x >= getWidth()) + return -1; + return array[y * getWidth() + x]; + } + + public int getI(int i) { + if (i >= array.length || i < 0) + return -1; + return array[i]; + } + + public boolean setI(int i, int value) { + if (i >= array.length || i < 0) + return false; + array[i] = value; + return true; + } + + public boolean add(int x, int y, int value) { + return set(x, y, get(x, y) + value); + } + + public int getWidth() { + return width; + } + + public int getHeight() { + return array.length / getWidth(); + } + + public int getLength() { + return array.length; + } + + public int[] getArray() { + return array; + } + + public Array2D getSlice(int x0, int y0, int x1, int y1) { + Array2D temp = new Array2D(x1 - x0, y1 - y0); + for (int y = 0; y < temp.getHeight(); y++) { + for (int x = 0; x < temp.getWidth(); x++) { + if (x + x0 < 0 || y + y0 < 0) + temp.set(x, y, -1); + else + temp.set(x, y, this.get(x + x0, y + y0)); + } + } + return temp; + } +} diff --git a/MrizenGaming/src/com/mrizen/gaming/Array2DColor.java b/MrizenGaming/src/com/mrizen/gaming/Array2DColor.java new file mode 100644 index 0000000..95c0c08 --- /dev/null +++ b/MrizenGaming/src/com/mrizen/gaming/Array2DColor.java @@ -0,0 +1,59 @@ +package com.mrizen.gaming; + +import java.awt.Color; + +public class Array2DColor { + Color[] array; + private int width; + + public Array2DColor(int width, int height) { + this.width = width; + array = new Color[width * height]; + } + + public boolean set(int x, int y, Color value) { + if (x < 0 || y < 0 || x >= getWidth() || y >= getHeight()) + return false; + array[y * getWidth() + x] = value; + return true; + } + + public Color get(int x, int y) { + if (y < 0 || x < 0 || y >= getHeight() || x >= getWidth()) + return null; + return array[y * getWidth() + x]; + } + + public Color getI(int i) { + if (i >= array.length || i < 0) + return null; + return array[i]; + } + + public boolean setI(int i, Color value) { + if (i >= array.length || i < 0) + return false; + array[i] = value; + return true; + } + + public boolean add(int x, int y, Color value) { + return set(x, y, new Color(get(x, y).getRGB() + value.getRGB())); + } + + public int getWidth() { + return width; + } + + public int getHeight() { + return array.length / getWidth(); + } + + public int getLength() { + return array.length; + } + + public Color[] getArray() { + return array; + } +} diff --git a/MrizenGaming/src/com/mrizen/gaming/Main.java b/MrizenGaming/src/com/mrizen/gaming/Main.java index 128231e..7db2a43 100644 --- a/MrizenGaming/src/com/mrizen/gaming/Main.java +++ b/MrizenGaming/src/com/mrizen/gaming/Main.java @@ -25,16 +25,22 @@ public class Main extends Canvas implements Runnable { private double updatesPerSecond; private KeyReader keys; private MouseReader mouse; + private int anim; - public Main(String title, int width, int height, double scale, double updatesPerSecond) { + public Main(String title, int width, int height, double hScale, double vScale, double updatesPerSecond) { this.title = title; this.updatesPerSecond = updatesPerSecond; + anim = 0; + + mouse = new MouseReader(); + addMouseMotionListener(mouse); + addMouseListener(mouse); frame = new JFrame(); frame.setResizable(false); frame.setTitle(title); frame.add(this); - setDimension(width, height, scale); + setDimension(width, height, hScale, vScale); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); frame.setVisible(true); @@ -44,10 +50,6 @@ public Main(String title, int width, int height, double scale, double updatesPer keys = new KeyReader(); addKeyListener(keys); - mouse = new MouseReader(scale); - addMouseMotionListener(mouse); - addMouseListener(mouse); - image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData(); @@ -62,8 +64,9 @@ public MouseReader getMouse() { return mouse; } - protected void setDimension(int width, int height, double scale) { - setPreferredSize(new Dimension((int) (width * scale), (int) (height * scale))); + protected void setDimension(int width, int height, double hScale, double vScale) { + setPreferredSize(new Dimension((int) (width * hScale), (int) (height * vScale))); + mouse.setScale(hScale, vScale); frame.pack(); } @@ -75,20 +78,22 @@ protected void render() { } + private void updatePrivate() { + anim++; + update(); + } + private void renderPrivate() { BufferStrategy bs = getBufferStrategy(); if (bs == null) { createBufferStrategy(3); return; } - screen.clear(); render(); - - for (int i = 0; i < pixels.length; i++) { - pixels[i] = screen.pixels[i]; + for (int i = 0; i < screen.getPixels().getLength(); i++) { + pixels[i] = screen.getPixels().getI(i); } - Graphics g = bs.getDrawGraphics(); g.drawImage(image, 0, 0, getWidth(), getHeight(), null); g.dispose(); @@ -109,7 +114,7 @@ public void run() { delta += (now - lastTime) / ns; lastTime = now; while (delta > 1) { - update(); + updatePrivate(); updates++; delta--; } @@ -139,17 +144,6 @@ protected synchronized void stop() { } } - public static void main(String[] args) { - String title = "Test"; - int width = 300; - int height = width / 16 * 9; - int scale = 6; - double updatesPerSecond = 60; - - Main main = new Main(title, width, height, scale, updatesPerSecond); - main.start(); - } - public Screen getScreen() { return screen; } @@ -159,4 +153,8 @@ protected void showCursor(boolean show) { Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0), "blank cursor"); frame.getContentPane().setCursor(blankCursor); } + + public int getAnim() { + return anim; + } } diff --git a/MrizenGaming/src/com/mrizen/gaming/Map.java b/MrizenGaming/src/com/mrizen/gaming/Map.java new file mode 100644 index 0000000..991b741 --- /dev/null +++ b/MrizenGaming/src/com/mrizen/gaming/Map.java @@ -0,0 +1,53 @@ +package com.mrizen.gaming; + +public class Map { + private Array2D tiles; + private Point2D offset; + + public Map(int width, int height) { + tiles = new Array2D(width, height); + offset = new Point2D(0, 0); + } + + public void render(Screen screen) { + screen.setOffset(offset.getX(), offset.getY()); + for (int yTile = 0; yTile < tiles.getHeight(); yTile++) { + for (int xTile = 0; xTile < tiles.getWidth(); xTile++) { + screen.drawSprite(getTile(xTile, yTile).getSprite(), xTile * Tile.SIZE, yTile * Tile.SIZE); + } + } + } + + public void update(KeyReader keys, int anim) { + + } + + protected void scrollTo(int offsetX, int offsetY) { + offset.setX(offsetX); + offset.setY(offsetY); + } + + protected Tile getTileById(int id) { + return null; + } + + protected Tile getTile(int x, int y) { + return getTileById(tiles.get(x, y)); + } + + protected Array2D getTiles() { + return tiles; + } + + public Point2D getOffset() { + return offset; + } + + public int getXOffset() { + return offset.getX(); + } + + public int getYOffset() { + return offset.getY(); + } +} \ No newline at end of file diff --git a/MrizenGaming/src/com/mrizen/gaming/MouseReader.java b/MrizenGaming/src/com/mrizen/gaming/MouseReader.java index 98577b3..0e513dc 100644 --- a/MrizenGaming/src/com/mrizen/gaming/MouseReader.java +++ b/MrizenGaming/src/com/mrizen/gaming/MouseReader.java @@ -9,25 +9,32 @@ public class MouseReader implements MouseListener, MouseMotionListener { private int mouseX; private int mouseY; private int mouseB; - private double scale; + private double hScale; + private double vScale; - public MouseReader(double scale) { - this.scale = scale; + public MouseReader() { + hScale = 1; + vScale = 1; mouseX = -1; mouseY = -1; mouseB = -1; } + public void setScale(double hScale, double vScale) { + this.hScale = hScale; + this.vScale = vScale; + } + public int getX() { return mouseX; } public int getScaledX() { - return (int) Math.round(mouseX / scale); + return (int) Math.round(mouseX / hScale); } public int getScaledY() { - return (int) Math.round(mouseY / scale); + return (int) Math.round(mouseY / vScale); } public int getY() { diff --git a/MrizenGaming/src/com/mrizen/gaming/Point2D.java b/MrizenGaming/src/com/mrizen/gaming/Point2D.java new file mode 100644 index 0000000..55fd7e9 --- /dev/null +++ b/MrizenGaming/src/com/mrizen/gaming/Point2D.java @@ -0,0 +1,27 @@ +package com.mrizen.gaming; + +public class Point2D { + private int x; + private int y; + + public Point2D(int x, int y) { + setX(x); + setY(y); + } + + public void setX(int x) { + this.x = x; + } + + public void setY(int y) { + this.y = y; + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } +} diff --git a/MrizenGaming/src/com/mrizen/gaming/Screen.java b/MrizenGaming/src/com/mrizen/gaming/Screen.java index 6b0de88..225d83a 100644 --- a/MrizenGaming/src/com/mrizen/gaming/Screen.java +++ b/MrizenGaming/src/com/mrizen/gaming/Screen.java @@ -1,33 +1,66 @@ package com.mrizen.gaming; -public class Screen { - public int[] pixels; - private int width; +public class Screen { + private Array2D pixels; + private int xOffset; + private int yOffset; public Screen(int width, int height) { - this.width = width; - pixels = new int[width * height]; + pixels = new Array2D(width, height); } public void clear() { - for (int i = 0; i < pixels.length; i++) { - pixels[i] = 0; + for (int i = 0; i < pixels.getLength(); i++) { + pixels.setI(i, 0); } + setOffset(0, 0); } - public void drawSprite(int xa, int ya, Sprite sprite) { + public void setOffset(int xOffset, int yOffset) { + setXOffset(xOffset); + setYOffset(yOffset); + } + + public void drawSprite(Sprite sprite, int xPos, int yPos) { for (int y = 0; y < sprite.getSize(); y++) { - int yp = y + ya; + int yp = y + yOffset + yPos; for (int x = 0; x < sprite.getSize(); x++) { - int xp = x + xa; - int ip = yp * width + xp; - int i = y * sprite.getSize() + x; - if (ip >= pixels.length || ip < 0 || i < 0 || i > sprite.getPixels().length) { + int xp = x + xOffset + xPos; + if (xp < 0 || yp < 0 || xp >= pixels.getWidth() || yp >= pixels.getHeight()) continue; + int pixel = sprite.getPixels().get(x, y); + if (pixel != Sprite.PINK) { + pixels.set(xp, yp, pixel); } - if (sprite.getPixels()[i] != Sprite.PINK) - pixels[ip] = sprite.getPixels()[i]; } } } + + public void drawColor(int color, int xPos, int yPos, int width, int height) { + for (int y = 0; y < height; y++) { + int yp = y + yOffset + yPos; + for (int x = 0; x < width; x++) { + int xp = x + xOffset + xPos; + if (xp < 0 || yp < 0 || xp >= pixels.getWidth() || yp >= pixels.getHeight()) + continue; + int pixel = color; + if (pixel != Sprite.PINK) { + pixels.set(xp, yp, pixel); + } + } + } + } + + public Array2D getPixels() { + return pixels; + } + + public void setXOffset(int xOffset) { + this.xOffset = xOffset; + } + + public void setYOffset(int yOffset) { + this.yOffset = yOffset; + } + } diff --git a/MrizenGaming/src/com/mrizen/gaming/Sprite.java b/MrizenGaming/src/com/mrizen/gaming/Sprite.java index afc97c2..601cea0 100644 --- a/MrizenGaming/src/com/mrizen/gaming/Sprite.java +++ b/MrizenGaming/src/com/mrizen/gaming/Sprite.java @@ -9,42 +9,38 @@ public class Sprite { public static final int BLUE = 0xFF0000FF; public static final int GRAY = 0xC0C0C0; - private final int SIZE; + private Array2D pixels; - private int[] pixels; - - public Sprite(int SIZE) { - this.SIZE = SIZE; - pixels = new int[SIZE * SIZE]; + public Sprite(int size) { + pixels = new Array2D(size, size); } public Sprite drawFill(int color) { - for (int i = 0; i < pixels.length; i++) { - pixels[i] = color; + for (int i = 0; i < pixels.getLength(); i++) { + pixels.setI(i, color); } return this; } public Sprite drawLoad(int xa, int ya, Spritesheet sheet) { - for (int y = 0; y < SIZE; y++) { - int yp = ya * SIZE + y; - for (int x = 0; x < SIZE; x++) { - int xp = xa * SIZE + x; - int ip = yp * sheet.getWidth() + xp, i = y * SIZE + x; - if (ip < 0 || ip >= sheet.pixels.length || i < 0 || i >= SIZE) { + for (int y = 0; y < getSize(); y++) { + int yp = ya * getSize() + y; + for (int x = 0; x < getSize(); x++) { + int xp = xa * getSize() + x; + if (xp < 0 || yp < 0 || xp >= sheet.getPixels().getWidth() || yp >= sheet.getPixels().getHeight()) { continue; } - pixels[i] = sheet.pixels[ip]; + pixels.set(x, y, sheet.getPixels().get(xp, yp)); } } return this; } public int getSize() { - return SIZE; + return pixels.getWidth(); } - public int[] getPixels() { + public Array2D getPixels() { return pixels; } -} +} \ No newline at end of file diff --git a/MrizenGaming/src/com/mrizen/gaming/Spritesheet.java b/MrizenGaming/src/com/mrizen/gaming/Spritesheet.java index 6451960..8aa2c35 100644 --- a/MrizenGaming/src/com/mrizen/gaming/Spritesheet.java +++ b/MrizenGaming/src/com/mrizen/gaming/Spritesheet.java @@ -1,4 +1,5 @@ package com.mrizen.gaming; + import java.awt.image.BufferedImage; import java.io.IOException; @@ -6,26 +7,21 @@ public class Spritesheet { - public int[] pixels; - private int width; + private Array2D pixels; public Spritesheet(String path) { try { BufferedImage image = ImageIO.read(Spritesheet.class.getResource(path)); - width = image.getWidth(); + int width = image.getWidth(); int height = image.getHeight(); - pixels = new int[width * height]; - image.getRGB(0, 0, width, height, pixels, 0, width); + pixels = new Array2D(width, height); + image.getRGB(0, 0, width, height, pixels.getArray(), 0, width); } catch (IOException e) { e.printStackTrace(); } } - public int getWidth() { - return width; - } - - public int getHeight() { - return pixels.length / getWidth(); + public Array2D getPixels() { + return pixels; } } diff --git a/MrizenGaming/src/com/mrizen/gaming/Tile.java b/MrizenGaming/src/com/mrizen/gaming/Tile.java new file mode 100644 index 0000000..8be8cfe --- /dev/null +++ b/MrizenGaming/src/com/mrizen/gaming/Tile.java @@ -0,0 +1,26 @@ +package com.mrizen.gaming; + +public class Tile { + public static final int SIZE = 16; + protected int id; + protected Sprite sprite; + + private static int nextId = 0; + + public Tile(int id, Sprite sprite) { + this.id = id; + this.sprite = sprite; + } + + public static int getNextId() { + return nextId++; + } + + public Sprite getSprite() { + return sprite; + } + + public int getId() { + return id; + } +} diff --git a/Scrolling Shooter 1/.classpath b/Scrolling Shooter 1/.classpath new file mode 100644 index 0000000..cd1fc48 --- /dev/null +++ b/Scrolling Shooter 1/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Scrolling Shooter 1/.project b/Scrolling Shooter 1/.project new file mode 100644 index 0000000..071389f --- /dev/null +++ b/Scrolling Shooter 1/.project @@ -0,0 +1,17 @@ + + + Scrolling Shooter 1 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Scrolling Shooter 1/.settings/org.eclipse.jdt.core.prefs b/Scrolling Shooter 1/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..7341ab1 --- /dev/null +++ b/Scrolling Shooter 1/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/Scrolling Shooter 1/src/Entity.java b/Scrolling Shooter 1/src/Entity.java new file mode 100644 index 0000000..064eb4f --- /dev/null +++ b/Scrolling Shooter 1/src/Entity.java @@ -0,0 +1,7 @@ +public class Entity { + private int type; + + public Entity(int type) { + this.type = type; + } +} diff --git a/Scrolling Shooter 1/src/Game.java b/Scrolling Shooter 1/src/Game.java new file mode 100644 index 0000000..6c7f30f --- /dev/null +++ b/Scrolling Shooter 1/src/Game.java @@ -0,0 +1,21 @@ +import com.mrizen.gaming.Main; + +public class Game extends Main { + private Level level; + + public Game(String title, int width, int height, double hScale, double vScale, double updatesPerSecond) { + super(title, width, height, hScale, vScale, updatesPerSecond); + level = Level.LEVEL_ONE; + } + + public static void main(String[] args) { + String title = "Scrolling Shooter"; + int width = 256; + int height = width / 16 * 9; + double hScale = 3; + double vScale = 3; + double updatesPerSecond = 60; + Game game = new Game(title, width, height, hScale, vScale, updatesPerSecond); + game.start(); + } +} diff --git a/Scrolling Shooter 1/src/Level.java b/Scrolling Shooter 1/src/Level.java new file mode 100644 index 0000000..7f7012a --- /dev/null +++ b/Scrolling Shooter 1/src/Level.java @@ -0,0 +1,16 @@ +import java.util.ArrayList; + +public class Level { + public ArrayList spawns; + + public static final Level LEVEL_ONE = new Level(); + + public Level() { + spawns = new ArrayList(); + + } + + public Level addSpawn(int time, int type) { + return this; + } +} diff --git a/TerrainGen/.classpath b/TerrainGen/.classpath new file mode 100644 index 0000000..cd1fc48 --- /dev/null +++ b/TerrainGen/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/TerrainGen/.project b/TerrainGen/.project new file mode 100644 index 0000000..c5565a5 --- /dev/null +++ b/TerrainGen/.project @@ -0,0 +1,17 @@ + + + TerrainGen + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/TerrainGen/.settings/org.eclipse.jdt.core.prefs b/TerrainGen/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..7341ab1 --- /dev/null +++ b/TerrainGen/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/TerrainGen/src/Game.java b/TerrainGen/src/Game.java new file mode 100644 index 0000000..8ebe2d9 --- /dev/null +++ b/TerrainGen/src/Game.java @@ -0,0 +1,24 @@ +import com.mrizen.gaming.Main; + +public class Game extends Main { + private static final long serialVersionUID = -7803629994015778818L; + private TerrainMap map; + + public Game() { + super("Dunegon Gen", 256, 256 / 16 * 9, 3, 3, 60); + map = new TerrainMap(5); + } + + public void update() { + map.update(getKeys(), getAnim()); + } + + public void render() { + map.render(getScreen()); + } + + public static void main(String[] args) { + Game game = new Game(); + game.start(); + } +} diff --git a/TerrainGen/src/Sprites.java b/TerrainGen/src/Sprites.java new file mode 100644 index 0000000..07579f5 --- /dev/null +++ b/TerrainGen/src/Sprites.java @@ -0,0 +1,13 @@ +import com.mrizen.gaming.Sprite; + +public class Sprites { + public static final Sprite BLUE = new Sprite(16).drawFill(Sprite.BLUE); + public static final Sprite ZERO = new Sprite(16).drawFill(Sprite.BLACK / 8 * 1); + public static final Sprite ONE = new Sprite(16).drawFill(Sprite.BLACK / 8 * 2); + public static final Sprite TWO = new Sprite(16).drawFill(Sprite.BLACK / 8 * 3); + public static final Sprite THREE = new Sprite(16).drawFill(Sprite.BLACK / 8 * 4); + public static final Sprite FOUR = new Sprite(16).drawFill(Sprite.BLACK / 8 * 5); + public static final Sprite FIVE = new Sprite(16).drawFill(Sprite.BLACK / 8 * 6); + public static final Sprite SIX = new Sprite(16).drawFill(Sprite.BLACK / 8 * 7); + public static final Sprite SEVEN = new Sprite(16).drawFill(Sprite.BLACK / 8 * 8); +} diff --git a/TerrainGen/src/TerrainMap.java b/TerrainGen/src/TerrainMap.java new file mode 100644 index 0000000..41f1cc2 --- /dev/null +++ b/TerrainGen/src/TerrainMap.java @@ -0,0 +1,100 @@ +import java.util.Random; + +import com.mrizen.gaming.Array2D; +import com.mrizen.gaming.KeyReader; +import com.mrizen.gaming.Map; +import com.mrizen.gaming.Tile; + +public class TerrainMap extends Map { + private int lastMoveAnim; + + public TerrainMap(int degree) { + super((int) Math.pow(2, degree), (int) Math.pow(2, degree)); + lastMoveAnim = 0; + generateMap(0); + } + + public void update(KeyReader keys, int anim) { + if (anim - lastMoveAnim > 15) { + if (keys.getLeft()) { + scrollTo(getXOffset() + Tile.SIZE, getYOffset()); + lastMoveAnim = anim; + } else if (keys.getRight()) { + scrollTo(getXOffset() - Tile.SIZE, getYOffset()); + lastMoveAnim = anim; + } else if (keys.getUp()) { + scrollTo(getXOffset(), getYOffset() + Tile.SIZE); + lastMoveAnim = anim; + } else if (keys.getDown()) { + scrollTo(getXOffset(), getYOffset() - Tile.SIZE); + lastMoveAnim = anim; + } + } + } + + private void generateMap(int seed) { + Random rand = new Random(seed); + int count = exponify(getTiles().getWidth()); + Array2D first = new Array2D(2, 2); + for (int i = 0; i < first.getLength(); i++) { + first.setI(i, rand.nextInt(8)); + } + Array2D working = null; + while (count > 0) { + working = spilt(first); + working = wiggle(working, rand, 1); + count--; + } + for (int i = 0; i < getTiles().getLength(); i++) + getTiles().setI(i, working.getI(i)); + } + + private int exponify(int i) { + int count = 0; + while (i > 1) { + count++; + i /= 2; + } + return count; + } + + private Array2D wiggle(Array2D array1, Random rand, int changeRate) { + Array2D array2 = new Array2D(array1.getWidth(), array1.getHeight()); + for (int y = 0; y < array2.getHeight(); y++) { + for (int x = 0; x < array2.getWidth(); x++) { + array2.set(x, y, array1.get(x, y) + rand.nextInt(changeRate * 2) - rand.nextInt(changeRate)); + } + } + return array2; + } + + private Array2D spilt(Array2D array1) { + Array2D array2 = new Array2D(array1.getWidth() * 2, array1.getHeight() * 2); + for (int y = 0; y < array2.getHeight(); y++) { + for (int x = 0; x < array2.getWidth(); x++) { + array2.set(x, y, array1.get((int) Math.floor(x / 2.0), (int) Math.floor(y / 2.0))); + } + } + return array2; + } + + public Tile getTileById(int id) { + if (id == Tiles.EMPTY.getId()) + return Tiles.EMPTY; + if (id == Tiles.ONE.getId()) + return Tiles.ONE; + if (id == Tiles.TWO.getId()) + return Tiles.TWO; + if (id == Tiles.THREE.getId()) + return Tiles.THREE; + if (id == Tiles.FOUR.getId()) + return Tiles.FOUR; + if (id == Tiles.FIVE.getId()) + return Tiles.FIVE; + if (id == Tiles.SIX.getId()) + return Tiles.SIX; + if (id == Tiles.SEVEN.getId()) + return Tiles.SEVEN; + return Tiles.EMPTY; + } +} diff --git a/TerrainGen/src/Tiles.java b/TerrainGen/src/Tiles.java new file mode 100644 index 0000000..8f987ee --- /dev/null +++ b/TerrainGen/src/Tiles.java @@ -0,0 +1,13 @@ +import com.mrizen.gaming.Tile; + +public class Tiles { + public static final Tile EMPTY = new Tile(Tile.getNextId(), Sprites.BLUE); + public static final Tile ZERO = new Tile(Tile.getNextId(), Sprites.ZERO); + public static final Tile ONE = new Tile(Tile.getNextId(), Sprites.ONE); + public static final Tile TWO = new Tile(Tile.getNextId(), Sprites.TWO); + public static final Tile THREE = new Tile(Tile.getNextId(), Sprites.THREE); + public static final Tile FOUR = new Tile(Tile.getNextId(), Sprites.FOUR); + public static final Tile FIVE = new Tile(Tile.getNextId(), Sprites.FIVE); + public static final Tile SIX = new Tile(Tile.getNextId(), Sprites.SIX); + public static final Tile SEVEN = new Tile(Tile.getNextId(), Sprites.SEVEN); +}