Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Passibility and showing pictures

wlzza

Sponsor

Hi there, just needs some pointers. What I want to achieve is to show a picture on the screen whenever the leftside of the player is non-passable and then disappears when that area becomes passable.

what I've gathered so far is...
Code:
To set correct variables...

case $game_player.direction
when 2
@e1x = $game_player.x + 1
@e1y = $game_player.y
when 4
@e1x = $game_player.x
@e1y = $game_player.y + 1
when 6
@e1x = $game_player.x
@e1y = $game_player.y - 1
when 8
@e1x = $game_player.x + 1
@e1y = $game_player.y
end

Then to check passability (not to sure)...

If $game_map.passable?(@e1x, @e1y) == true
Show picture
else
Erase picture
end

I assume to show a picture is...
@image.bitmap = Cache.picture("w1-E-L_R")
@image.x = 0
@image.y = 0
@image.z = 99
While to erase a picture is...
@image.dispose

Hope you can advise me. Cheers!
 
To check the passability you can use this: $game_player.passable?(x , y)
And lets say you wanted to check if the left side of the player is not passable, then you could store the players x and y
and then check it like this:
Code:
    x = $game_player.x
    y = $game_player.y
    if $game_player.passable?(x - 1, y) == false
      # If it isn't passable, then something happens
    end


What i would do if i wanted to show a picture whenever the left side of the player wasn't passable, is something like this:
Code:
    x = $game_player.x
    y = $game_player.y
    if $game_player.passable?(x - 1,y) == false
      @picture = Sprite.new
      @picture.bitmap = Bitmap.new('Graphics/Pictures/filename')
      @picture.x = 0 # The pictures x-position
      @picture.y = 0 # The pictures y-position
    end

And then replace "filename" with the name of the picture that you wish to show.
I hope that helped! :thumb:

Over and out - Gando
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top