设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 144|回复: 0

[转载发布] Snake Minigame V1.0

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    2026-7-12 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    9071

    主题

    864

    回帖

    6万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    58883
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    68848

    灌水之王

    发表于 2026-7-31 14:14:55 | 显示全部楼层 |阅读模式
    Snake Minigame+V1.0
        Zarby


         
        Introduction
        This is a little classic Snake Minigame
         
        Features
        - Customizable graphics,text,actions
        - Can give the score to a variable
         
        Screenshots
       

    Spoiler



         
        How to Use
        Paste the script just before Main and call the scene from an event call script :SceneManager.call(Scene_Snake)    set the 3 graphics variable at the top of the script to use no graphics
        if you want to use graphic it should look like that :
        head :
        
        body :
        
         
        Demo
        http://www.mediafire.com/?66cv3yzpsgggvz4
         
        Script
       
         
       

    Spoiler                Code:       
    1. #==============================================================================# ** General Configuration#------------------------------------------------------------------------------#  You can set Parameters here#==============================================================================$snake_speed = 1$speed_acceleration = 0.1#return score to variable [Let it to 0 if you don't want to return score to a variable] :$score_variable_id = 20#text if we lose :$lose_text = "Game Over"#if we press Cancel key (escape) :#0 = Leave to map instantly#1 = Pause game and ask player if he want to leave$cancel_action = 1#Score Management :#every time snake move it decrease by 1 the value of the score the food give$everytime_snake_move = 1$everytime_snake_eat = 100#Graphics Settings#if you don't want graphics set all to : nil#(image must be 32x16 pixel in picture folder first 16 pixel = looking to right side, last 16 pixel = looking to down side)$head_graphics = "head"$body_graphics = "body"$food_graphics = nil#==============================================================================# ** Window_PauseCommand#------------------------------------------------------------------------------#  This command window appears when escape is pressed while playing#==============================================================================class Window_PauseCommand < Window_Command  def initialize(x,y)    super(x, y)  end  def make_command_list    add_command("Continue",   :continue,   true)    add_command("Leave",   :leave,   true)  end end#===============================================================================# ** Score_Window#-------------------------------------------------------------------------------#  This window display the score                                           #===============================================================================class Window_Score < Window_Base  def initialize(x, y)    super(x, y, 160, line_height + 32)    @score = 0    refresh    self.opacity = 0    self.back_opacity = 0  end  def update_score(score)    @score = score  end   def refresh    self.contents.clear    self.contents.draw_text(0, 0, 200, line_height, @score)  endend#===============================================================================# ** Snake_Body#-------------------------------------------------------------------------------#  This class is the snake head and body                                           #===============================================================================class Snake_Body    attr_accessor :x    attr_accessor :y    attr_accessor :direction  def initialize(x,y,direction)    @sprite = Sprite.new    @x = x    @y = y    @sprite.x = x*16    @sprite.y = y*16    @lastx = @x    @lasty = @y    @graphicx = 0    @graphicy = 0    @sprite.bitmap = Bitmap.new(16,16)    @bmp = nil        if (direction != -1)#body      if ($body_graphics != nil)        @bmp = Cache.picture($body_graphics)        @sprite.bitmap.blt(0,0,@bmp,Rect.new(16,0,16,16))      else        @sprite.bitmap.fill_rect(Rect.new(0,0,16,16),Color.new(0,200,0))      end    else#head      if ($body_graphics != nil)        @bmp = Cache.picture($head_graphics)        @sprite.bitmap.blt(0,0,@bmp,Rect.new(16,0,16,16))      else        @sprite.bitmap.fill_rect(Rect.new(0,0,16,16),Color.new(0,250,0))      end      @direction = 0    end    @speed = 0  end   def updatelastpos()    @lastx = @x    @lasty = @y    @graphicx = 0    @graphicy = 0  end   def dispose()    @bmp.dispose    @sprite.dispose  end      def updatepos(speed)    @speed = speed    if (@x> @lastx)      @graphicx = (@graphicx+@speed)    end    if (@y > @lasty)      @graphicy = (@graphicy+@speed)    end    if (@x< @lastx)      @graphicx = (@graphicx-@speed)    end    if (@y < @lasty)      @graphicy = (@graphicy-@speed)    end    @sprite.x = (@lastx*16)+@graphicx    @sprite.y = (@lasty*16)+@graphicy      if @bmp != nil    if @lastdirection != @direction      @sprite.bitmap.clear      case @direction      when 0        @sprite.bitmap.blt(0,0,@bmp,Rect.new(16,0,16,16))      when 1        @sprite.bitmap.blt(0,0,@bmp,Rect.new(0,0,16,16))      when 2        @sprite.bitmap.blt(0,0,@bmp,Rect.new(16,16,16,-16))      when 3        @sprite.bitmap.blt(0,0,@bmp,Rect.new(16,0,-16,16))      end    end  end     @lastdirection = @direction  end  end   class Scene_Snake < Scene_Base   def initialize    super    create_window_score    create_window_command    create_sprites    create_settings    create_object_array    generate_food(rand(34),rand(26))  end  def update    super    if Input.trigger?(:      pause    end    if @pause == false      get_direction      if (@direction != -1)        @timer += @snake_speed        every_tick        update_snake              end    end   end   def terminate    super      end    def every_tick        if (@timer >= 16)      if @food_score > 0        @food_score = @food_score - 1      end      (@snakebody.size-1).downto(1){ |i|      @snakebody[i].direction = @snakebody[i-1].direction      @snakebody[i].updatelastpos()      @snakebody[i].x = @snakebody[i-1].x      @snakebody[i].y = @snakebody[i-1].y      }      @snakebody[0].direction = @direction      @snakebody[0].updatelastpos()              if (@direction == 0)#Down        @snakebody[0].y = @snakebody[0].y+1      end      if (@direction == 1)#Right        @snakebody[0].x = @snakebody[0].x+1      end      if (@direction == 2)#Up        @snakebody[0].y = @snakebody[0].y-1      end      if (@direction == 3)#Left        @snakebody[0].x= @snakebody[0].x-1      end             @window_score.update_score(@score)      @window_score.refresh            if (@snakebody[0].x > 33)        @snakebody[0].x = 0      end      if (@snakebody[0].x < 0)        @snakebody[0].x = 33      end      if (@snakebody[0].y > 25)        @snakebody[0].y = 0      end      if (@snakebody[0].y < 0)        @snakebody[0].y = 25      end              @timer = 0    end      end    def get_direction        if Input.press?(Input::DOWN)      @direction = 0    end    if Input.press?(Input::UP)      @direction = 2    end    if Input.press?(Input::LEFT)      @direction = 3    end    if Input.press?(Input::RIGHT)      @direction = 1    end  end   def update_snake    (@snakebody.size-1).downto(0){ |i|                if (i != 0)        if ((@snakebody[0].x == @snakebody[i].x) and (@snakebody[0].y == @snakebody[i].y))                                  $game_message.texts.push($lose_text)          command_leave          if $score_variable_id  != 0            $game_variables[$score_variable_id] = @score          end                               break;        end      end      @snakebody[i].updatepos(@snake_speed)}                 if ((@snakebody[0].x == @food_x) and (@snakebody[0].y == @food_y))      @snakebody.push(Snake_Body.new(@snakebody[@snakebody.size-1].x,@snakebody[@snakebody.size-1].y,@snakebody[@snakebody.size-1].direction))      @snake_speed = @snake_speed + @speed_acceleration      @score =  @score + @food_score      @window_score.update_score(@score)      @food_score = $everytime_snake_eat      generate_food(rand(34),rand(26))    end         end    def pause    if @pause == false      @window_command.activate      @window_command.visible = true      @pause = true    else      unpause    end  end   def unpause    @window_command.visible = false    @pause = false  end   def create_window_score    @window_score = Window_Score.new(0,0)  end   def create_window_command    @window_command = Window_PauseCommand.new(192,160)    @window_command.set_handler(:continue,      method(:command_continue))    @window_command.set_handler(:leave,      method(:command_leave))    @window_command.visible = false    @window_command.deactivate  end   def create_sprites    @food_sprite = Sprite.new    @food_sprite.bitmap = Bitmap.new(16,16)    if $food_graphics != nil      @food_sprite.bitmap = Cache.picture($food_graphics)    else      @food_sprite.bitmap.fill_rect(Rect.new(0,0,16,16),Color.new(250,230,130))    end  end   def create_object_array  @snakebody = []    @snakebody.push(Snake_Body.new(17,13,-1))    @snakebody.push(Snake_Body.new(17,13,0))    @snakebody.push(Snake_Body.new(17,13,0))  end   def create_settings    @snake_speed = $snake_speed    @speed_acceleration = $speed_acceleration    @direction = -1    @score = 0    @food_score = $everytime_snake_eat    @timer = 25    generate_food(rand(34),rand(26))    @food_x = 0    @food_y = 0    @leaving = false    @pause = false  end   def generate_food(x,y)    @food_x = x    @food_y = y    @food_sprite.x = x * 16    @food_sprite.y = y * 16  end   def command_continue    @window_command.visible = false    @pause = false  end   def command_leave    @window_command.dispose    SceneManager.call(Scene_Map)  end end
    复制代码






        FAQ
         
        Q: You get a error : Unable to find file :
        A: Save the 2 picture in How to use at the top of the post and import it in game as head.png / body.png
        A2: turn the 3 variable _graphics to nil at the top of the script

     


    本贴来自国际rpgmaker官方论坛作者:Zarby处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/snake-minigame-v1-0.16770/

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    x
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-8-17 19:07 , Processed in 0.121435 second(s), 55 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表