Here is footage of what my game looks like so far:
">
As you can see in the footage there are some collision issues.I've recently fixed them but now I'm facing a problem that i cannot solve by myself. I want to know how to go about giving my game dynamic 2D lighting. I think they call it "ray casting" or something of that nature. I've seen 3D demonstrations of raycasting and i didnt really understand the source code but from what i've seen I think it is also possible to implement this into a 2d game aswell.
Any suggestions?
Update:
Here is updated footage of what my game looks like so far:
">
Ok well I read an article on here that really helped me out with this but now my game runs SLOW.
This is what my Light class looks like(dont look at it if you dont want to its pretty messy):
import java.awt.Color;import java.awt.GradientPaint;import java.awt.Graphics2D;import java.awt.RenderingHints;import java.awt.Shape;import java.util.ArrayList; public class Light extends Sprite{ public static GradientPaint Shade; public static Color RayColor; public static int red = 255; public static int green = 255; public static int blue = 255; public static int Opacity = 255; public static double Degree; public static double CurrentX2; public static double CurrentY2; public static double SlopeX; public static double SlopeY; public static boolean ChangeAngle = false; public Graphics2D RenderLight (Graphics2D g , double PlayerX ,double PlayerY ,ArrayList <FloorTile> TileList ,int MaxTiles){ double PIE = 3.14; double RADIUS = 1000; //Degree = Degree + 1; for (Degree = 0 ; Degree < 360 ; Degree+=2){ double CurrentX1 = PlayerX; double CurrentY1 = PlayerY; double Rad1 = (PIE / 180) * Degree; CurrentX2 = (Math.sin(Rad1) * (RADIUS)*2) + CurrentX1; CurrentY2 = (Math.cos(Rad1) * (RADIUS)*2) + CurrentY1; SlopeX = (CurrentX2 - CurrentX1) /500; SlopeY = (CurrentY2 - CurrentY1) /500; //Opacity = 255; while(true){ red = 255; green = 255; blue = 255; double distance ; distance= Math.sqrt(Math.pow(CurrentX2-this.getX(), 2) + Math.pow(CurrentY2-this.getY(), 2)); //min 1962 if(distance > 1962 ){ if (Opacity >= 255){ }else{ Opacity +=5; RefreshPixel(red,green,blue,Opacity); } } if (CurrentX1 > launchApp.FrameWidth){ Opacity = 0; break; } if(CurrentX1 < 0){ Opacity = 0; break; } if (CurrentY1 > launchApp.FrameHeight){ Opacity = 0; break; } if (CurrentY1 < 0){ Opacity = 0; break; } CurrentX1 += SlopeX; CurrentY1 += SlopeY; this.setX(CurrentX1); this.setY(CurrentY1); for(int J= 0; J <MaxTiles;J++){ if(TileList.get(J).getWidth() <=0){ }else{ double PixelX = this.getX(); double PixelY = this.getY(); double NextBottomLeftX = TileList.get(J).getBottomLeftX(); double NextBottomLeftY = TileList.get(J).getBottomLeftY(); double NextBottomRightX = TileList.get(J).getBottomRightX(); double NextTopLeftY = TileList.get(J).getTopLeftY(); if (PixelX > NextBottomLeftX && PixelX < NextBottomRightX&&PixelY > NextBottomLeftY&&PixelY > NextTopLeftY){ ChangeAngle = true; RefreshPixel(red,green,blue,Opacity); Opacity = 0; break; } } } if (ChangeAngle){ ChangeAngle = false; break; } g.setPaint(RayColor); g.fillRect((int)this.getX() + 10,(int) this.getY() + 10,(int) this.getWidth(), (int)this.getHeight()); } } return g; } public void RefreshPixel( int red, int green,int blue, int opacity){ RayColor = new Color(red,green,blue,opacity); }}
The idea of my method is that you calculate the slope of X2 and Y2 divide the slope by an Xamount and then add the slope to the pixel's position. If you constantly draw the pixel's movement it creates a line. I did this because doing it this way would make it easier to check collision between tiles.
The FPS of the game jumps to 25FPS if I don't modify the Opacity variable of the Color object,However, i need to modify Opacity in order to create the effect of shading. Is there an alternative to Opacity?
[Edited by - thecoast47 on December 12, 2010 8:58:17 PM]