sometimes i make lentil dhal
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts MenuQuote from: p2 on October 20, 2016, 08:35:17 PM
all we need is one super-bored over-motivated guy for every language xD
German one here
package tiletest;
import javax.swing.JFrame;
import javax.swing.JPanel;
import tiletest.TileArea;
public class TileTestApp
{
public static void main(String[] args)
{
JFrame frame = new JFrame("TileTest");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// add TileArea to the JFrame here
TileArea tileArea = new TileArea(600, 408);
frame.add("Center", tileArea);
frame.pack();
frame.setVisible(true);
// load tileset
TileSource tiles = new TileSource("all-3.png", 24);
//----
int r = 1;
for (;;) {
for (int x = 0; x < 25; x++) {
for (int y = 0; y < 17; y++) {
tileArea.drawTile(tiles, 0, 3, tiles.getTileSize()*x, tiles.getTileSize()*y);
tileArea.drawTile(tiles, r, 1, tiles.getTileSize()*x, tiles.getTileSize()*y);
}
}
frame.repaint();
r++;
if (r==3) r = 1;
try { // wait 10ms to avoid any flicker
Thread.sleep(10);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
}
}
package tiletest;
import java.awt.*;
import java.awt.image.*;
public class TileArea extends Component
{
private BufferedImage m_image;
private int m_width, m_height;
public TileArea(int width, int height)
{
m_width = width;
m_height = height;
m_image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
}
public Dimension getPreferredSize()
{
return new Dimension(m_width, m_height);
}
public void paint(Graphics g)
{
g.drawImage(m_image, 0, 0, null);
}
public void drawTile(TileSource tileSource, int tilex, int tiley, int x, int y)
{
Graphics2D g = m_image.createGraphics();
g.drawImage(tileSource.getTile(tilex, tiley), x, y, null);
}
}
package tiletest;
import java.awt.*;
import java.awt.image.*;
import javax.imageio.*;
import java.lang.*;
import java.io.*;
import javax.swing.*;
public class TileSource extends Component
{
private BufferedImage m_tiles;
private int m_tileSize;
public TileSource(String filename, int tileSize)
{
m_tileSize = tileSize;
try {
m_tiles = ImageIO.read(new File(filename));
}
catch (IOException e) { // no need to do anything here
} // m_tiles will be null anyway
if (m_tiles == null) {
JOptionPane.showMessageDialog(null, "p2, no! could not load tileset.");
return;
}
}
public int getTileSize()
{
return m_tileSize;
}
public BufferedImage getTile(int tilex, int tiley)
{
if (m_tiles == null) {
return null;
}
return m_tiles.getSubimage(tilex*(m_tileSize+1)+1, tiley*(m_tileSize+1)+1, m_tileSize, m_tileSize);
}
}
Quote from: p2 on October 20, 2016, 08:02:56 AM
@kotu: As you were a vegetarian, what do you think about vegan guys? (those refusing to eat eggs and milk, too)
Quote from: Juju on October 19, 2016, 07:11:32 PM
This ad speaks to me on unimaginable levels o.o
Page created in 0.090 seconds with 30 queries.