Quote from: p2 on October 31, 2016, 10:32:35 PM
right, maybe we should move these posts to a topic like "simple key stuff in java" ^^
done!
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 31, 2016, 10:32:35 PM
right, maybe we should move these posts to a topic like "simple key stuff in java" ^^
package tiletest;
import javax.swing.JFrame;
import tiletest.TileArea;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
public class TileTestApp implements KeyListener
{
private int m_walriix = 280, m_walriiy = 180;
private boolean m_keyDown = false;
private boolean m_keyUp = false;
private boolean m_keyLeft = false;
private boolean m_keyRight = false;
private int m_bgTile = 0;
public void keyPressed(KeyEvent e)
{
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
m_bgTile++;
if (m_bgTile > 7) {
m_bgTile = 0;
}
}
if (e.getKeyCode() == KeyEvent.VK_LEFT) m_keyLeft = true;
else if (e.getKeyCode() == KeyEvent.VK_RIGHT) m_keyRight = true;
else if (e.getKeyCode() == KeyEvent.VK_UP) m_keyUp = true;
else if (e.getKeyCode() == KeyEvent.VK_DOWN) m_keyDown = true;
}
public void keyReleased(KeyEvent e)
{
if (e.getKeyCode() == KeyEvent.VK_LEFT) m_keyLeft = false;
else if (e.getKeyCode() == KeyEvent.VK_RIGHT) m_keyRight = false;
else if (e.getKeyCode() == KeyEvent.VK_UP) m_keyUp = false;
else if (e.getKeyCode() == KeyEvent.VK_DOWN) m_keyDown = false;
}
public void keyTyped(KeyEvent e)
{
}
TileTestApp()
{
JFrame frame = new JFrame("kotu java demo");
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);
frame.addKeyListener(this);
// load tileset
TileSource tiles = new TileSource("all-3.png", 24);
//----
for (;;)
{
if (m_keyRight) m_walriix += 4;
if (m_keyLeft) m_walriix -= 4;
if (m_keyUp) m_walriiy -= 4;
if (m_keyDown) m_walriiy += 4;
for (int x = 0; x < 25; x++) {
for (int y = 0; y < 17; y++) {
tileArea.drawTile(tiles, m_bgTile, 3, tiles.getTileSize()*x, tiles.getTileSize()*y);
}
}
tileArea.drawTile(tiles, 2, 1, m_walriix, m_walriiy);
frame.repaint();
try { // wait 10ms to avoid any flicker
Thread.sleep(10);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
}
public static void main(String[] args)
{
new TileTestApp();
}
}
package tiletest;
import java.awt.*;
import java.awt.image.*;
public class TileArea extends Component
{
private static final long serialVersionUID = 1L;
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.io.*;
import javax.swing.*;
public class TileSource extends Component
{
private static final long serialVersionUID = 1L;
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: Juju on November 01, 2016, 04:51:26 AM
Oooh, nice DJ deck. Looking to do some dank mixes?
Quote from: DJ Omnimaga on November 01, 2016, 04:53:13 AM
Those look great. How much did they cost?
Quote from: p2 on October 31, 2016, 11:28:39 PMnice quite programmery
Quote from: aeTIos on October 31, 2016, 09:49:07 PMi think he just got lucky, and at the end he was trying his hardest to play the drums correctlyQuote from: kotu on October 31, 2016, 09:38:13 PM(not sure if /s)
why does he stab his drums at the end it doesn't seem very professional. i would say he doesn't know what he's doing
It's Lars, such things are to be expected. I think the very tight drumming during the song serves as a testimony for his drumming.
Quote from: DJ Omnimaga on October 31, 2016, 10:07:48 PM
So did anyone have anything planned for Halloween? I'm years past my trick or treating years, but I went to an Halloween party last night with a Jason Vorhees costume. I am tempted to watch an horror movie with ghosts later but I'm still unsure (it needs to be scary).
Some stuff also changed on the forums for a few hours
Page created in 0.102 seconds with 30 queries.