Snake Minigame Dying Problem

mylafter

I’m a creep... I’m a weirdo...
Veteran
Joined
Dec 30, 2012
Messages
196
Reaction score
176
First Language
English
Primarily Uses
N/A
I'm using this script for a snake mini game, which can be found here.
For those of you who know how the game snake is like, if the snake touches its own body, it's game over. But for this script in particular, the game ends if the player presses a backward button. So if the snake is moving right and the player accidentally clicks the 'left' button, it's game over. Which, should not happen since the snake did NOT touch its own body. Also, it's just not how the game should be. The same goes for 'up' and 'down' commands as well. It's game over if the player clicks the direction button opposite the way the snake is headed. Is there a way to prevent this from happening?
 

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
2,674
Reaction score
566
First Language
English
Primarily Uses
RMVXA
Place below the snake script.
Code:
class Scene_Snake < Scene_Base
  def get_direction
    
    if Input.press?(Input::DOWN)
      return if @direction == 2
      @direction = 0
    end
    if Input.press?(Input::UP)
      return if @direction == 0
      @direction = 2
    end
    if Input.press?(Input::LEFT)
      return if @direction == 1
      @direction = 3
    end
    if Input.press?(Input::RIGHT)
      return if @direction == 3
      @direction = 1
    end
  end
end
 

mylafter

I’m a creep... I’m a weirdo...
Veteran
Joined
Dec 30, 2012
Messages
196
Reaction score
176
First Language
English
Primarily Uses
N/A
Place below the snake script.
Code:
class Scene_Snake < Scene_Base
  def get_direction
   
    if Input.press?(Input::DOWN)
      return if @direction == 2
      @direction = 0
    end
    if Input.press?(Input::UP)
      return if @direction == 0
      @direction = 2
    end
    if Input.press?(Input::LEFT)
      return if @direction == 1
      @direction = 3
    end
    if Input.press?(Input::RIGHT)
      return if @direction == 3
      @direction = 1
    end
  end
end
Wow that was fast! Thank you so much! It works!
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.

Forum statistics

Threads
106,034
Messages
1,018,447
Members
137,820
Latest member
georg09byron
Top