Jump to content


Photo

GML Minecraft-like lightning system


  • This topic is locked This topic is locked
3 replies to this topic

#1 Benxamix2

Benxamix2

    GMC Member

  • New Member
  • 278 posts
  • Version:GM8

Posted 16 February 2012 - 03:34 PM

Well, I've made this system for a 2D game, and it's working fine, but a bit unrealistic...

This is the whole thing, it's in the draw event of an "shadow manager" object.
    for ( i = 0; i < instance_number( worldBlock ); i += 1 ) {
        object = instance_find( worldBlock, i )
        if instance_exists( object ) {
            if !position_meeting( object.x + 16, object.y - 16, worldBlock ) {
                draw_set_alpha( 0.1 )
                draw_rectangle( object.x, object.y, object.x + 31, view_yview + view_hview, 0 )
            }
        }
    }


For example, look at this
Posted Image

It does work, but in some cases the shadows aren't very good processed and look weird.
How can I improve this?

(hope this doesn't belong to N&I, since I don't think it does)

Edited by Benxamix2, 16 February 2012 - 03:41 PM.

  • 0

#2 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9314 posts
  • Version:Unknown

Posted 16 February 2012 - 09:47 PM

I don't really understand your code, specifically this part:

if !position_meeting( object.x + 16, object.y - 16, worldBlock ) {

Isn't "object" an instance of worldBlock? So you're simply checking if there's no worldBlock at 16px to the right and above each block?

So what this code says to me is this (assuming 32x32 top-left origins):

"For each worldBlock, if there is no worldBlock above me and to the right, then draw a shadow in my column from my height down to the bottom of the view."

Which would simply make a shadow below all the grounds, no? Which is what your image shows. If you want something else, please explain what you want for those of us who haven't played Minecraft.

-IMP
  • 0

#3 Benxamix2

Benxamix2

    GMC Member

  • New Member
  • 278 posts
  • Version:GM8

Posted 17 February 2012 - 01:18 PM

Nvm, I think I just figured out how to make this; I'll use a global array to store information about the darkness in every grid block. That way I'll be able to interact with it and make it better. It will take more CPU but it's worth it (also the game can disable those shadows so there is no problem :D).

The problem I had was related to some unrealistic generated shadows like this

Posted Image

Edited by Benxamix2, 17 February 2012 - 01:50 PM.

  • 0

#4 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9314 posts
  • Version:Unknown

Posted 17 February 2012 - 09:39 PM

The extra shadowing is because you have the block on the top, and the block underneath that, both drawing shadows atop each other. Just for future reference.

-IMP
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users