Advertisement
Guest User

Untitled

a guest
Sep 7th, 2011
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.80 KB | None | 0 0
  1. /*
  2.  *  This file is part of the Haven & Hearth game client.
  3.  *  Copyright (C) 2009 Fredrik Tolf <fredrik@dolda2000.com>, and
  4.  *                     Björn Johannessen <johannessen.bjorn@gmail.com>
  5.  *
  6.  *  Redistribution and/or modification of this file is subject to the
  7.  *  terms of the GNU Lesser General Public License, version 3, as
  8.  *  published by the Free Software Foundation.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  Other parts of this source tree adhere to other copying
  16.  *  rights. Please see the file `COPYING' in the root directory of the
  17.  *  source tree for details.
  18.  *
  19.  *  A copy the GNU Lesser General Public License is distributed along
  20.  *  with the source tree of which this file is a part in the file
  21.  *  `doc/LPGL-3'. If it is missing for any reason, please see the Free
  22.  *  Software Foundation's website at <http://www.fsf.org/>, or write
  23.  *  to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  24.  *  Boston, MA 02111-1307 USA
  25.  */
  26.  
  27. package haven;
  28.  
  29. import java.awt.*;
  30. import java.awt.image.BufferedImage;
  31. import javax.media.opengl.GL;
  32.  
  33. public class ILM extends TexRT {
  34.     public final static BufferedImage ljusboll;
  35.     final static int HF = -460100982;
  36.     final static int FIRE = 1104478640;
  37.     final static int TORCHPOST = 168393716;
  38.     final static int CANDLETHINGY = -594851989;
  39.     final static int SPECIAL = 0;
  40.    
  41.     OCache oc;
  42.     TexI lbtex;
  43.     Color amb;
  44.    
  45.     static {
  46.     int sz = 200, min = 50;
  47.     BufferedImage lb = new BufferedImage(sz, sz, BufferedImage.TYPE_INT_ARGB);
  48.     Graphics g = lb.createGraphics();
  49.     for(int y = 0; y < sz; y++) {
  50.         for(int x = 0; x < sz; x++) {
  51.         double dx = sz / 2 - x;
  52.         double dy = sz / 2 - y;
  53.         double d = Math.sqrt(dx * dx + dy * dy);
  54.         int gs;
  55.         if(d > sz / 2)
  56.             gs = 255;
  57.         else if(d < min)
  58.             gs = 0;
  59.         else
  60.             gs = (int)(((d - min) / ((sz / 2) - min)) * 255);
  61.         gs /= 2;
  62.         Color c = new Color(gs, gs, gs, 128 - gs);
  63.         g.setColor(c);
  64.         g.fillRect(x, y, 1, 1);
  65.         }
  66.     }
  67.     ljusboll = lb;
  68.     }
  69.    
  70.     public ILM(Coord sz, OCache oc) {
  71.     super(sz);
  72.     this.oc = oc;
  73.     amb = new Color(0, 0, 0, 0);
  74.     lbtex = new TexI(ljusboll);
  75.     }
  76.  
  77.     public void UpdateSize(Coord sz) {
  78.         dim = sz;
  79.     }
  80.    
  81.     protected Color setenv(GL gl) {
  82.     gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE);
  83.     return(amb);
  84.     }
  85.    
  86.     protected boolean subrend(GOut g) {
  87.     GL gl = g.gl;
  88.     gl.glClearColor(255, 255, 255, 255);
  89.     gl.glClear(GL.GL_COLOR_BUFFER_BIT);
  90.     synchronized(oc) {
  91.         for(Gob gob : oc) {
  92.                 if(gob.sc == null) {
  93.                     /* Might not have been set up by the MapView yet */
  94.                     continue;
  95.                 }
  96.                 Lumin lum = gob.getattr(Lumin.class);
  97.                 switch(gob.GetResName().hashCode()){
  98.                 case HF: gob.setattr((lum = new Lumin(gob,new Coord(0,0),200,96))); break;
  99.                 case FIRE: gob.setattr((lum = new Lumin(gob,new Coord(0,0),200,192))); break;
  100.                 case TORCHPOST: gob.setattr((lum = new Lumin(gob,new Coord(0,-28),300,192))); break;
  101.                 case CANDLETHINGY: gob.setattr((lum = new Lumin(gob,new Coord(0,-28),400,192))); break;
  102.                 case SPECIAL:
  103.                     if(gob.getneg().bc.x == oc.getgob(UI.instance.mainview.playergob).getneg().bc.x &&
  104.                        gob.getneg().bs.x == oc.getgob(UI.instance.mainview.playergob).getneg().bs.x)
  105.                             gob.setattr((lum = new Lumin(gob,new Coord(0,-15),200,192))); break;
  106.                 }
  107.                 if(lum == null)
  108.                     continue;
  109.             Coord sc = gob.sc.add(lum.off).add(-lum.sz, -lum.sz);
  110.             g.image(lbtex, sc, new Coord(lum.sz * 2, lum.sz * 2));
  111.             g.chcolor();
  112.         }
  113.     }
  114.     return(true);
  115.     }
  116.    
  117.     protected byte[] initdata() {
  118.     return(null);
  119.     }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement