FlashTest.java :  » Game » foogamelib » org » newdawn » slick » tests » Java Open Source

Java Open Source » Game » foogamelib 
foogamelib » org » newdawn » slick » tests » FlashTest.java
package org.newdawn.slick.tests;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;

/**
 * A test for image flashes
 *
 * @author kevin
 */
public class FlashTest extends BasicGame {
  /** The TGA image loaded */
  private Image image;
  /** True if the image is rendered flashed */
  private boolean flash;
  /** The container for the test */
  private GameContainer container;
  
  /**
   * Create a new image rendering test
   */
  public FlashTest() {
    super("Flash Test");
  }
  
  /**
   * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
   */
  public void init(GameContainer container) throws SlickException {
    this.container = container;
    
    image = new Image("testdata/logo.tga");
  }

  /**
   * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
   */
  public void render(GameContainer container, Graphics g) {
    g.drawString("Press space to toggle",10,50);
    if (flash) {
      image.draw(100,100);
    } else {
      image.drawFlash(100,100,image.getWidth(), image.getHeight(), new Color(1,0,1f,1f));
    }
  }

  /**
   * @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
   */
  public void update(GameContainer container, int delta) {
  }

  /**
   * Entry point to our test
   * 
   * @param argv The arguments to pass into the test
   */
  public static void main(String[] argv) {
    try {
      AppGameContainer container = new AppGameContainer(new FlashTest());
      container.setDisplayMode(800,600,false);
      container.start();
    } catch (SlickException e) {
      e.printStackTrace();
    }
  }

  /**
   * @see org.newdawn.slick.BasicGame#keyPressed(int, char)
   */
  public void keyPressed(int key, char c) {
    if (key == Input.KEY_SPACE) {
      flash = !flash;
    }
    if (key == Input.KEY_ESCAPE) {
      container.exit();
    }
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.