This site requires JavaScript, please enable it in your browser!
Greenfoot back
SickTrickz832
SickTrickz832 wrote ...

2019/9/30

How to achieve Line Of Sight

1
2
SickTrickz832 SickTrickz832

2019/9/30

#
So for one of my projects I've been trying to get an effect so the player can only see in a certain range around them, like having a light in a dark hallway or maze kind of game. I've looked through tutorials and some scenarios but going into the code and trying understand isn't working. I currently only have player movement at the moment on a blank scenario but hopefully this image shows what I'm trying to achieve: https://www.google.com/search?q=2d+dark+maze+game&safe=strict&rlz=1C1GCEV_enGB867GB867&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjs0pyp5fjkAhWdThUIHfynDfYQ_AUIEigB&biw=1680&bih=939#imgrc=l-21jDx2V9JIxM: Can anyone help?
SushiLlama SushiLlama

2019/9/30

#
Well, basically you are trying to hide everything as black, except a small circle around the player. You can try to achieve this by using some Actor like ImageHider for example. It should be a black image with a transparent circle with the radius you want it to be. I guess transparency works in Greenfoot so the image can be 1000x1000 but the middle is transparent though. Now i need to know if your actor moves in a world or the background moves and the actor is always in the centre of the screen. The second option is easier to work with, becuase you never need to move "ImageHider" around. But probably your player moves in the world which means you should move ImageHider corresponding to Player. Tell me if you have further questions. This is kind of a workaround and im sure there are cleaner solutions but simplicity and creativity are not to be underrated :D
SickTrickz832 SickTrickz832

2019/9/30

#
SushiLlama wrote...
Well, basically you are trying to hide everything as black, except a small circle around the player. You can try to achieve this by using some Actor like ImageHider for example. It should be a black image with a transparent circle with the radius you want it to be. I guess transparency works in Greenfoot so the image can be 1000x1000 but the middle is transparent though. Now i need to know if your actor moves in a world or the background moves and the actor is always in the centre of the screen. The second option is easier to work with, becuase you never need to move "ImageHider" around. But probably your player moves in the world which means you should move ImageHider corresponding to Player. Tell me if you have further questions. This is kind of a workaround and im sure there are cleaner solutions but simplicity and creativity are not to be underrated :D
Thanks for your reply. My world is currently a player moving around the world, I haven't worked with the world moving around the player before. I didn't really thing of having an Image Hider, because all of the tutorials I saw were using raycasting and I've never worked with it in Greenfoot before so I was confused as heck :D
SushiLlama SushiLlama

2019/9/30

#
Wtf is raycasting haha xD You can implement raycasting but i would recommend looking for a way to Code it so that you unterstand what youre doing. I hope somebody does know more than me and helps you out.
SickTrickz832 SickTrickz832

2019/9/30

#
SushiLlama wrote...
Wtf is raycasting haha xD You can implement raycasting but i would recommend looking for a way to Code it so that you understand what youre doing. I hope somebody does know more than me and helps you out.
Well, ray casting in Green foot is sending out a ray from one point to another to find distance or mathematics. In my case it would be sending out many rays in a circular range from the player to decide which objects to show and not. But I will give the image hider a try so thanks. If anyone else has help please reply to this thread.
danpost danpost

2019/9/30

#
Deciding on which objects to show or not would not look good with objects popping into and out of existence. Raycasting is usually used to determine line of sight -- not distance. An image hider actor may be the way to go despite its main drawback, memory usage due to image size. If player moves around world, the image may need to be 4 times the size of the background image of the world (2 time the width and 2 times the height). If world moves around player (scrolling world with centered player), then it would only need be the same size as the world background. The code to create the image of this image hider actor is not trivial -- probably intermediate level code.
SickTrickz832 SickTrickz832

2019/9/30

#
danpost wrote...
Deciding on which objects to show or not would not look good with objects popping into and out of existence. Raycasting is usually used to determine line of sight -- not distance. An image hider actor may be the way to go despite its main drawback, memory usage due to image size. If player moves around world, the image may need to be 4 times the size of the background image of the world (2 time the width and 2 times the height). If world moves around player (scrolling world with centered player), then it would only need be the same size as the world background. The code to create the image of this image hider actor is not trivial -- probably intermediate level code.
Thanks for the reply. I've been using Greenfoot for a while now and have made some stuff, probably the best being a Free for all Tank Deathmatch game. What method would you go with? Because having the Image Hider move seems easier but having a scrolling world with a central actor (the player) seems more beneficial, but I've never done it. And I've never done a scrolling world only static ones with moving players
danpost danpost

2019/9/30

#
SickTrickz832 wrote...
What method would you go with?
That is really a question only you, the designer, can answer. If you are not up to the challenge of a scrolling world, then...so be it. If interested I have a Scroller support class that has a tutorial as well as a demo.
SickTrickz832 SickTrickz832

2019/10/1

#
danpost wrote...
SickTrickz832 wrote...
What method would you go with?
That is really a question only you, the designer, can answer. If you are not up to the challenge of a scrolling world, then...so be it. If interested I have a Scroller support class that has a tutorial as well as a demo.
Thanks for this. Just tried out the demo one and it looks like it will be a better effect than having the image move. Just reading the tutorial now, so thanks for your help.
SickTrickz832 SickTrickz832

2019/10/1

#
danpost wrote...
SickTrickz832 wrote...
What method would you go with?
That is really a question only you, the designer, can answer. If you are not up to the challenge of a scrolling world, then...so be it. If interested I have a Scroller support class that has a tutorial as well as a demo.
How do you keep your character in the centre of the scrolling world? I've got the scrolling part down but my player doesn't stick to the centre
danpost danpost

2019/10/1

#
SickTrickz832 wrote...
How do you keep your character in the centre of the scrolling world? I've got the scrolling part down but my player doesn't stick to the centre
See the Actor follow scrolling code page in the tutorial.
SickTrickz832 SickTrickz832

2019/10/2

#
danpost wrote...
SickTrickz832 wrote...
How do you keep your character in the centre of the scrolling world? I've got the scrolling part down but my player doesn't stick to the centre
See the Actor follow scrolling code page in the tutorial.
Thanks. Just having a look at it, but do both parts of this code go in the ImageScrollWorld class?
danpost danpost

2019/10/2

#
SickTrickz832 wrote...
do both parts of this code go in the ImageScrollWorld class?
The second part is just a replacement scroll method -- to replace the scroll method above it (in the event you do not want your actor to be center-locked).
SickTrickz832 SickTrickz832

2019/10/5

#
danpost wrote...
SickTrickz832 wrote...
do both parts of this code go in the ImageScrollWorld class?
The second part is just a replacement scroll method -- to replace the scroll method above it (in the event you do not want your actor to be center-locked).
Gave this ago, I have the ImageScrollWorld class as my world and I have a scroller class. My player still doesnt stick to the center and the world doesnt scroll. Heres the code for my player:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Player here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Player extends Actor
{
    public void act() 
    {
        if (Greenfoot.isKeyDown("d"))
        {
            move(3);
        }
        
        if (Greenfoot.isKeyDown("a"))
        {
            move(-3);
        }
    }    
}
danpost danpost

2019/10/5

#
SickTrickz832 wrote...
Gave this ago, I have the ImageScrollWorld class as my world and I have a scroller class. My player still doesnt stick to the center and the world doesnt scroll. Heres the code for my player: << Code Omitted >>
Please show your ImageScrollWorld class codes.
There are more replies on the next page.
1
2