Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Game Mechanics / 2D Raycasting and Lighting on: 2014-01-07 22:19:13
Hello, I am wondering how I could implement 2D ray-casting in a Slick2D game, for lighting purposes. I realize that Slick2D is somewhat dead but that is irrelevant to ray-casting, as far as I know.

The "map" would consist of either rectangles or line segments.

I've read the article at http://www.redblobgames.com/articles/visibility/ but I can't seem to figure out how this is implemented in Java.

My best guess is to have a Ray class and a Line class and determine where intersections lie, and then create triangles from those points. Also, on a slightly irrelevant note, I have not learned how to create radial gradients in Slick2D, any help there would be appreciated too. I'm also wondering if efficiency would be an issue in a situation where there are a large number of lines. I hope my question makes sense.  Undecided

One other question: how would I combine the lights from multiple sources? I'm thinking additive blending or perhaps transparency would be the solution.

Any help would be appreciated!
2  Discussions / Miscellaneous Topics / Re: if you are not a programmer, what would you be ? on: 2013-07-01 19:06:17
Easy. Engineer or musician.
3  Discussions / Business and Project Management Discussions / Re: Creating A Game, need a team. on: 2013-06-28 23:25:34
If you are still interested, I can help with music, programming, and code cleanup.
If you are looking for pixel art, I can assist a bit with that as well. Furthermore, I can work for free.
4  Discussions / Business and Project Management Discussions / Re: Any artists on: 2013-06-28 23:23:25
DazKins,
Thank you for posting your message. I would be interested in collaborating on a java game. I am not really much of an artist, although I can do some pixel art, but I tend to focus more on music and coding. I am not sure if you would like assistance with either of these, but if so, I think I can help. I am also young, only 14.
-bcsharp
5  Java Game APIs & Engines / Engines, Libraries and Tools / Slick2D Radial Gradient on: 2013-06-28 23:19:53
Hello,
With apologies, I think that I originally posted this under the wrong section, so I moved my question here. I am having difficulty creating a lighting system for my game. The way I plan to render lighting is like this:
  • Create a lighting map by using additive blending and radial gradients from all of the lightsources
  • Combine the lightmap with the rendered game using multiplicative blending
The issue with my code so far is creating a radial gradient class. I am using Slick2D, which doesn't include a radial gradient class that implements ShapeFill, the interface used to fill shapes. I decided to create one myself, which looks like this:
import org.newdawn.slick.*;
import org.newdawn.slick.geom.*;
import org.newdawn.slick.svg.*;


public class RadialFill implements ShapeFill {
   Color start;
   Color end;
   float centerX;
   float centerY;
   
   public RadialFill(Color s, Color e){
      start = s;
      end = e;
   }

   @Override
   public Color colorAt(Shape shape, float x, float y) {
      float e = (float) (Math.sqrt((x - centerX) * (x - centerX) + (y - centerY) * (y - centerY))) / ((shape.getHeight() > shape.getWidth() ? shape.getHeight() : shape.getWidth()) / 2 );
      float s = 1 - e;
      Color col = new Color(1,1,1,1);
      col.r = (e * end.r) + (s * start.r);
      col.b = (e * end.b) + (s * start.b);
      col.g = (e * end.g) + (s * start.g);
      col.a = (e * end.a) + (s * start.a);
      return col;
   }
   
   public void setCenter(float x, float y){
      centerX = x;
      centerY = y;
   }
   
   public float getCenterX(){
      return centerX;
   }
   
   public float getCenterY(){
      return centerY;
   }
   
   public void setStartColor(Color s){
      start = s;
   }
   
   public Color getStartColor(){
      return start;
   }
   
   public void setEndColor(Color e){
      end = e;
   }
   
   public Color getEndColor(){
      return end;
   }
   
   @Override
   public Vector2f getOffsetAt(Shape shape, float x, float y) {
      // TODO Auto-generated method stub
      return new Vector2f(0,0);
   }

}

Here is the test code that I made:
import org.newdawn.slick.*;
import org.newdawn.slick.fills.*;
import org.newdawn.slick.geom.*;
import org.newdawn.slick.state.*;
import org.newdawn.slick.svg.*;


public class LightTestState extends BasicGameState {
   
   Input input;
   GradientFill grad;
   RadialFill gradFill;
   Ellipse mouseLight;
   int mouseX;
   int mouseY;
   boolean ready = false;

   @Override
   public void init(GameContainer container, StateBasedGame game)
         throws SlickException {
      input = container.getInput();
      grad = new GradientFill(0, 0, Color.yellow, 100, 100, Color.black, false);
      gradFill = new RadialFill(Color.yellow, Color.black);
      ready = true;
   }

   @Override
   public void render(GameContainer container, StateBasedGame game, Graphics g)
         throws SlickException {
      if (ready){
         g.setAntiAlias(true);
         g.setDrawMode(Graphics.MODE_ADD);
         mouseLight = new Ellipse(mouseX, mouseY, 100, 100);
         gradFill.setCenter(mouseX, mouseY);
         g.fill(mouseLight, grad);
      }
   }

   @Override
   public void update(GameContainer container, StateBasedGame game, int delta)
         throws SlickException {
      mouseX = input.getMouseX();
      mouseY = input.getMouseY();
   }

   @Override
   public int getID() {
      // TODO Auto-generated method stub
      return 1;
   }

}

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.tests.*;

public class Noteblock extends StateBasedGame {
   
   public Noteblock(){
      super("Noteblock");
   }

   @Override
   public void initStatesList(GameContainer container) throws SlickException {
      // TODO Auto-generated method stub
      container.setShowFPS(false);
      addState(new LightTestState());
   }

   /**
    * @param args
    */
   public static void main(String[] args) {
      //GradientTest.main(null);
      try {
         AppGameContainer container = new AppGameContainer(new Noteblock());
         container.setDisplayMode(800,600,false);
         container.start();
      } catch (SlickException e) {
         e.printStackTrace();
      }
   }

}

However, when I try to create a radial gradient with this code, it doesn't work. At best, it can only make a fill of one color.  Huh Any ideas? Any help would be appreciated.
6  Game Development / Game Play & Game Design / Re: Just something to think about while you go about your lives. on: 2013-06-28 19:40:34
Am I correct in saying you want to question the player's morals for winning the game? Or make them not want to win the game for their own sake?
7  Game Development / Newbie & Debugging Questions / Re: Beginner-Advanced Developer on: 2013-06-28 19:36:30
scanevero,
I understand what you are saying. I have been there myself, wanting to jump headfirst into a project and never being able to finish it because of lack of experience. What I suggest you do is create a simple game that might be boring, but works. Here are some ideas:
  • A simple physics-based run and jump game
  • A continous game (e.g. no menu, no restarts, no levels, etc.)
  • Look into game examples and modify them
I've actually never tried Android development, so these ideas might not be realistic for that platform, but I hope this helps!
8  Game Development / Newbie & Debugging Questions / Slick2D Radial Gradient on: 2013-06-28 19:29:08
Hello,
I am having difficulty creating a lighting system for my game. The way I plan to render lighting is like this:
  • Create a lighting map by using additive blending and radial gradients from all of the lightsources
  • Combine the lightmap with the rendered game using multiplicative blending
The issue with my code so far is creating a radial gradient class. I am using Slick2D, which doesn't include a radial gradient class that implements ShapeFill, the interface used to fill shapes. I decided to create one myself, which looks like this:
import org.newdawn.slick.*;
import org.newdawn.slick.geom.*;
import org.newdawn.slick.svg.*;


public class RadialFill implements ShapeFill {
   Color start;
   Color end;
   float centerX;
   float centerY;
   
   public RadialFill(Color s, Color e){
      start = s;
      end = e;
   }

   @Override
   public Color colorAt(Shape shape, float x, float y) {
      float e = (float) (Math.sqrt((x - centerX) * (x - centerX) + (y - centerY) * (y - centerY))) / ((shape.getHeight() > shape.getWidth() ? shape.getHeight() : shape.getWidth()) / 2 );
      float s = 1 - e;
      Color col = new Color(1,1,1,1);
      col.r = (e * end.r) + (s * start.r);
      col.b = (e * end.b) + (s * start.b);
      col.g = (e * end.g) + (s * start.g);
      col.a = (e * end.a) + (s * start.a);
      return col;
   }
   
   public void setCenter(float x, float y){
      centerX = x;
      centerY = y;
   }
   
   public float getCenterX(){
      return centerX;
   }
   
   public float getCenterY(){
      return centerY;
   }
   
   public void setStartColor(Color s){
      start = s;
   }
   
   public Color getStartColor(){
      return start;
   }
   
   public void setEndColor(Color e){
      end = e;
   }
   
   public Color getEndColor(){
      return end;
   }
   
   @Override
   public Vector2f getOffsetAt(Shape shape, float x, float y) {
      // TODO Auto-generated method stub
      return new Vector2f(0,0);
   }

}

Here is the test code that I made:
import org.newdawn.slick.*;
import org.newdawn.slick.fills.*;
import org.newdawn.slick.geom.*;
import org.newdawn.slick.state.*;
import org.newdawn.slick.svg.*;


public class LightTestState extends BasicGameState {
   
   Input input;
   GradientFill grad;
   RadialFill gradFill;
   Ellipse mouseLight;
   int mouseX;
   int mouseY;
   boolean ready = false;

   @Override
   public void init(GameContainer container, StateBasedGame game)
         throws SlickException {
      input = container.getInput();
      grad = new GradientFill(0, 0, Color.yellow, 100, 100, Color.black, false);
      gradFill = new RadialFill(Color.yellow, Color.black);
      ready = true;
   }

   @Override
   public void render(GameContainer container, StateBasedGame game, Graphics g)
         throws SlickException {
      if (ready){
         g.setAntiAlias(true);
         g.setDrawMode(Graphics.MODE_ADD);
         mouseLight = new Ellipse(mouseX, mouseY, 100, 100);
         gradFill.setCenter(mouseX, mouseY);
         g.fill(mouseLight, grad);
      }
   }

   @Override
   public void update(GameContainer container, StateBasedGame game, int delta)
         throws SlickException {
      mouseX = input.getMouseX();
      mouseY = input.getMouseY();
   }

   @Override
   public int getID() {
      // TODO Auto-generated method stub
      return 1;
   }

}

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.tests.*;

public class Noteblock extends StateBasedGame {
   
   public Noteblock(){
      super("Noteblock");
   }

   @Override
   public void initStatesList(GameContainer container) throws SlickException {
      // TODO Auto-generated method stub
      container.setShowFPS(false);
      addState(new LightTestState());
   }

   /**
    * @param args
    */
   public static void main(String[] args) {
      //GradientTest.main(null);
      try {
         AppGameContainer container = new AppGameContainer(new Noteblock());
         container.setDisplayMode(800,600,false);
         container.start();
      } catch (SlickException e) {
         e.printStackTrace();
      }
   }

}
{/tt][/spoiler]
However, when I try to create a radial gradient with this code, it doesn't work. At best, it can only make a fill of one color.  Huh Any ideas? Any help would be appreciated.
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (13 views)
2014-08-28 18:26:30

CopyableCougar4 (25 views)
2014-08-22 19:31:30

atombrot (38 views)
2014-08-19 09:29:53

Tekkerue (31 views)
2014-08-16 06:45:27

Tekkerue (30 views)
2014-08-16 06:22:17

Tekkerue (19 views)
2014-08-16 06:20:21

Tekkerue (29 views)
2014-08-16 06:12:11

Rayexar (66 views)
2014-08-11 02:49:23

BurntPizza (42 views)
2014-08-09 21:09:32

BurntPizza (34 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!