is there a way to make a flashlight that cannot go through solid objects in game maker - game-maker

I am making a 2D (top-down) horror game in game maker. Each player has a flash light which drains overtime. The flashlight uses surfaces to draw light and the cone gets smaller overtime.I would like for the flashlight to act like a real flashlight instead of going through walls. Is there anyway to do this?Picture of what I want it to look like

how are you currently drawing your flashlight?
I would recommend not drawing a flashlight sprite and instead filling a surface with black (to act as darkness) and cutting your lights out of that.
Then You can use the collision_line function to sweep in an arc from your player and get either where it hits an object or whether the line extends past your flashlight range. Then store all those vertices and draw a primitive with blending to act as flashlight.
Hope that makes sense, otherwise I swear I've seen some posts on the gamemaker forums on this, good luck!

Related

What device/instrument/technology should I use for detecting object’s lying on a given surface?

First of: Thanks for taking the time to help me with my problem. It is much appreciated :)
I am building a natural user interface. I’d like the interface to detect several (up to 40) objects lying on it. The interface should detect if the objects are moved on it’s the canvas. It is not important what the actual object on surface is
e.x. “bottle”
or what color it has – only the shape and the placement of the object is of interest
e.x. “circle” .
So far I’m using a webcam connected to my computer and Processing’s blob functionality to detect the objects on the surface of the interface (see picture 1). This has some major disadvantages to what I am trying to accomplish:
I do not want the user to see the camera or any alternative device because this is detracting the user’s attention. Actually the surface should be completely dark.
Whenever I am reaching with my hand to rearrange the objects on the interface, the blob detection gets very busy and is recognizing objects (my hand) which are not touching the canvas directly. This problem can hardly be tackled using a Kinect, because the depth functionality is not working through glass/acrylic glass – correct me if I am wrong.
It would be nice to install a few LEDs on the canvas controlled by an Arduino. Unfortunately, the light of the LEDs would disturb the blob detection.
Because of the camera’s focal length, the table needs to be unnecessarily high (60 cm / 23 inch).
Do you have any idea on an alternative device/technology to detect the objects? Would be nice if the device would work well with Processing and Arduino.
Thanks in advance! :)
Possibilities:
Use Reflective tinted glass so that the surface would dark or reflective
Illuminate the area, where you place the webcam with array of IR LED's.
I would suggest colour based detection and contouring of the objects.
If you are using colour based detection convert frames to HSV and CrCb colour space. These are much better for segmentation of required area while using colour based detection.
I do recommend you to check out https://github.com/atduskgreg/opencv-processing. This interfaces Open-CV with processing, you will be getting lot functionalities of Open-CV in processing .
One possibility:
Use a webcam with infrared capability (such as a security camera with built-in IR illumination). Apparently some normal webcams can be converted to IR use by removing a filter, I have no idea how common that is.
Make the tabletop out of some material that is IR-transparent, but opaque or nearly so to visible light. (Look at the lens on most any IR remote control for an example.)
This doesn't help much with #2, unfortunately. Perhaps you can be a bit pickier about the size/shape of the blobs you recognize as being your objects?
If you only need a few distinct points of illumination for #3, you could put laser diodes under the table, out of the path of the camera - that should make a visible spot on top, if the tabletop material isn't completely opaque. If you need arbitrary positioning of the lights - perhaps a projector on the ceiling, pointing down?
Look into OpenCV. It's an open source computer vision project.
In addition to existing ideas (which are great), I'd like to suggest trying TUIO Processing.
Once you have the camera setup (with the right field of view/lens/etc. based on your physical constraints) you could probably get away with sticking TUIO markers to the bottom of your objects.
The software will pickup detect the markers and you'll differentiate the objects by ID, but also be able to get position/rotation/etc. and your hands will not be part of that.

Handle traffic in 2D city builder

I´m creating a 2D isometric city building simulation and today I have kind of a "best practice" question without asking for specific code.
As in all city building games you are able to place building, roads and so on. The player is able to place building everywhere, no matter if it´s connected to a road or not. In addition to that there is one building (call it center building) all the buildings need to be connected with (by road).
I need to handle that without doing too many calculations which, breaks the FPS.
Right now I have a timer job for each building which checks if one of the surrounded tiles of a building is a road. That works fine, also for a lot of buildings since the check is simple.
But now I would like to check the connection to the center building. To check that it is necessary (in my opinion) to use something like a pathfinder, which checks if one of the surrounded tiles has a road connection to one of the surrounded tiles of the center building.
I can not check that frequently because this completely smashes the FPS down to 30 or lower. My idea was to fire an event if a road has been built or destroyed to "recalulate" the road connection. But there comes another problem...the player might destoy a road in the middle of the map and the buildings are really far away from each other so I need to find the involved buildings which also might take too much time.
My last idea is creating something like a timer queue and work through these items gradually, but before I keep using the trial and error method I would like to ask you for ideas.
Really looking forward to your ideas!
Yheeky
You could have each building store a list of tiles (a path) that connects it to the center building. Then when a tile is randomly destroyed by the player, you can have each building tested to see if it pathed through that road tile or not.
Alternatively you could have each road tile store which buildings require it, so when the tile is destroyed you have the buildings immediately throw flags. This could get quite messy though, but lends itself decently to background speed cleanup calls.
Both methods are quite messy. Perhaps you can make it a rule that the player can't place roads except next to other roads or next to the center building. Then when the player deletes a road tile, do a paint-style fill that destroys all of the disconnected roads. You can also periodically do a random check on tiles to see if they are illegally placed or not, but that should be unnecessary if you're careful.

How to achieve realistic reflection with threejs

I am trying to render as realistically as possible a scene in which a point light hits an object and bounces off with the same angle wrt the normal of the face (angle of incidence = angle of reflection) and illuminates the scene elsewhere.
Now, I know reflection in threejs is normally dealt with CubeCamera-material as per the examples I found online, but it doesn't quite apply to my case, for I may be observing the scene from a point in which I might not be able to observe the reflection of the object on the mirror-like surface of another one.
Consider this example prototype I'm working on: if the box that is protruding from the wall in the scene had a mirror-like material (accomplished with a CubeCamera), I wouldn't be able to see the green cube's reflection on the bottom face unless the camera was at a specific position; in real life, however, if an object illuminated by a light source passes in the vicinity of another one, it will in part light it as if it were a light source itself (depending on the object's index of reflectivity, of course) and such phenomenon should be visible from any point of view the object receiving indirect lighting is visible from.
Hence I came up with the idea of adding a PointLight to the cube, but this of course produces undesirable effects on the surroundings.
I will try to illustrate my goal with the following sequence:
1) Here, the far side of what I will henceforth refer to as balcony is correctly dark, while the areas marked with a red 'x' are the consequence of the cube having a child PointLight which shines in all directions.
2) Here, the balcony's far face is still dark and the bottom one is receiving even more light as the cube passes by, which is desirable, but the wall behind the cube should actually be dark (I haven't added shadows yet, I first want to get the lighting right), as well as the ground beneath it and the lamp post.
3) Finally, when the cube has passed the balcony, it's just plain wrong for the balcony's side and bottom face to be illuminated, for we all now that a reflected ray does not bounce back the way it came from. Same applies to the lamp post.
Now I realize that all the mistakes that occur are due to the fact that the cube emits light itself, what I'm hoping you can help me with is determining a way to produce physically accurate reflected rays.
I would like to avoid using ambient light or other hacks to simulate real-life scenarios and stick to physics as much as possible; I suspect what I want to achieve is very computationally heavy to render, let alone animate in a real-time use case, but that's not an issue for I'm merely trying to develop a proof-of-concept, not something that should necessarily perform fast.
From what I gather, I should probably be writing custom vertex and fragment shaders for the materials receiving indirect illumination, right? Unfortunately I wouldn't know where to begin, can anyone point me in the right direction? Cheers.
If you do not want to go to the Volumetric rendering then you have 3 options (I know of)
ray-tracing
you have to use ray-trace rendering (back ray-trace) to achieve this. This will also cover shadows,transparent materials,reflected illumination and much more if coded properly. Unless you want to do also precise atmospheric scattering then this is the way.
back raytracing is one (or 3) ray(s) per each screen pixel. It is much faster but not that precise.. (still precise enough)
raytracing is one ray per each 3D angular unit (steradian) of space per each light source. It is slow but precise (if ray density is high enough).
If the casted ray hits any obstacle then its color is changed (due to obstacle property) and new ray is casted as reflected light ray. If material is transparent then also refracted ray is casted ... Each hit or refraction affect light intensity so you stop when intensity is lower then some treshold or on some layer of recursion (limit max number of refractions per ray) to avoid infinite loops and you can manipulate performance/quality ...
standard polygon rendering
With this approach (I think you are using it right now) you have to improvise. The reflection and illumination effects can be done similar to shadowing techniques. For each surface you have to render the scene in reflected direction. The same can be done with shadows but then you just rendering to the light direction or use shadow map instead. If you have insane number of reflective surfaces then this approach is not the way also to achieve reflection of refraction you have to render recursively making it multiple rendering pass per polygon which is also insane.
cubemap
You can use cube map per each object. It is similar to bullet 2 but the insanity is done just once while generating cubemaps instead of per frame ... If you have too much objects then this is also not the way. You can use cube map only for objects with reflective surfaces to make it manageable. Also if the objects are moving then you have to re-generate cubemaps once in a while ...

Scrollable and Endless map - libgdx

I want to create a simple game with a space ship that needs to dodge asteroids and stuff along the way.
Now, I can think of several ways to spawn the obstacles in the map. My only problem is, how do I implement the idea of an endless map/scrollable map?
For instance, in Flappy Bird there is an endless map.
I just want to know what is the best approach to implement this kind of thing.
Like Alon said, for the background you can use several horizontally "tileable" textures, just load them behind the current one when it's edge is almost visible. You can actually make multiple layers to create depth, for instance you can create a foreground layer with some clouds/nebula's the player travels behind, then some space dust behind the player traveling slower and some planets traveling very slowly in the distance.
Simply create a array for each layer of tileable background textures. Make these textures a bit (or a lot) wider then the actual screen. Keep adding textures to the right side, pick them randomly from your array, and let them scroll. Of course you delete textures when they traversed the screen and not shown anymore.
For your objects you just spawn the asteroids off screen and let them travel across the screen. You maintain a asteroid list and each time you need an asteroid you generate it with a random Y axis and add it to the list. When you need to draw or calculate collision you traverse this list and do your stuff on each asteroid.
There are many ways to do it. I recommend this one:
Move your character in needed direction and respawn obstacles on global position. Camera should follow the character. For moving background you have two options: ParallaxBackground which already knows how to move backgrounds or you can just create two backgrounds and when character will be in the end of first one you will move second background to the end.

N Game character Physics

For my 2d platform game am following 2 articles from creator of N N+ game. Two article covers how the collision is handled and a broad phase collision detection by storing all the AABB shapes info in to tile map along with some other potential information required for collision.No where on the Internet how the player character movement handling is explained.
http://www.madgravityradio.com/ngame.html
I tried with small rectangular piece in the place of player , the result I got is rectangle is very responsive as far as the collision concern but not realistic though (I have no idea how to tilt the player rectangle to some angle when stepping down or up on Slope edges.).
What type of object the player is comprised of? Is the player kept inside a box shape and the box is translated? Please shed some light on how the character is controlled , concept behid this virtual player? I read somewhere Rag doll is used.
I have few more general questions
In SAT how to handle/apply the minimum translation vector to make the movement more realistic?
I haven't started creating tile map for this iphone game , I do have some experience in title map creation for flash games. No idea how to handle iphone memory efficiently - any recommendations please?
The term you are looking for is collision response - ie now that you have detected a collision and have the collision data, what do you do with it to produce a meaningful response. This is a pretty big topic so maybe investigate it and come back with some more specific questions. Here's a basic primer and google/wikipedia will take you much farther.

Resources