Class: GamePlay::Alph_Ruins_Puzzle

Inherits:
Object
  • Object
show all
Defined in:
scripts/01450 Systems/09000 Games/00003 Ruine Alpha/00002 Ruine_Alpha_by_FL0RENT_.rb

Constant Summary collapse

MOVESOUND1 =

Choix des fichiers son SE

"Audio/SE/psn"
MOVESOUND2 =

mouvement sans piece

"Audio/SE/hitlow"
PLACESOUND =

mouvement avec piece

MOVESOUND2
TAKESOUND =

pose de piece

nil
VICTORY_THEME =

BGM

"Audio/ME/ROSA_YourPokemonEvolved.ogg"
GR_CursorB =

Images

"Puzzle_Ruines Curseur_b"
GR_Cursor =
"Puzzle_Ruines Curseur"
GR_Background =
"Puzzle_Ruines Fond"
GR_Background2 =
"Puzzle_Ruines Fond2"
BaseOffsetX =

> Offset

112 - 24
BaseOffsetY =
72 - 24

Instance Method Summary collapse

Constructor Details

#initialize(id, id_switch) ⇒ Alph_Ruins_Puzzle

Returns a new instance of Alph_Ruins_Puzzle.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'scripts/01450 Systems/09000 Games/00003 Ruine Alpha/00002 Ruine_Alpha_by_FL0RENT_.rb', line 28

def initialize(id, id_switch)
  @viewport = Viewport.create(:main, 100)
  @id_switch = id_switch
  @background = Plane.new(@viewport)
  @background.bitmap = RPG::Cache.interface(GR_Background)
  @background2 = Sprite.new(@viewport)
  @background2.bitmap = RPG::Cache.interface(GR_Background2)
  @background2.x = 112
  @background2.y = 72
  @grid = Array.new(6) { Array.new(6) }
  @pieces = []
  @cursor_piece = nil
  @cursor = Sprite.new(@viewport)
  @cursor.bitmap = RPG::Cache.interface(GR_Cursor)
  @cursor.z = 9001
  @cursor_x = 0
  @cursor_y = 0
  @cursor_wait = 0
  #> Génération des images des pièces
  bmp = RPG::Cache.interface("Puzzle_Ruines #{id}")
  @pieces = Array.new(16) do |i|
    img = Sprite.new(@viewport)
    img.bitmap = bmp
    img.src_rect.set(24 * (i / 4), 24 * (i % 4), 24, 24)
    next(img)
  end
  #> Tri aléatoire des pièces
  @pieces.each do |piece|
    verif = false
    until verif
      a = rand(3)
      case a
      when 0
        b = rand(6)
        if @grid[0][b] == nil
          verif = true
          @grid[0][b] = piece
        end
      when 1
        b = rand(6)
        if @grid[5][b] == nil
          verif = true
          @grid[5][b] = piece
        end
      when 2
        b = rand(4)
        if @grid[b + 1][0] == nil
          verif = true
          @grid[b + 1][0] = piece
        end
      end
    end
  end
  pieces_position
  @viewport.sort_z
end

Instance Method Details

#dispose



164
165
166
167
168
169
170
171
# File 'scripts/01450 Systems/09000 Games/00003 Ruine Alpha/00002 Ruine_Alpha_by_FL0RENT_.rb', line 164

def dispose
  @background.dispose
  @background2.dispose
  @cursor.dispose
  @pieces.each do |p|
    p.dispose
  end
end

#main



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'scripts/01450 Systems/09000 Games/00003 Ruine Alpha/00002 Ruine_Alpha_by_FL0RENT_.rb', line 85

def main
  Graphics.transition
  while $scene == self
    Graphics.update
    update
    if victory_check
      $game_switches[@id_switch] = true
      if VICTORY_THEME
        Audio.me_play(VICTORY_THEME)
        wait(80)
        wait_hit
        $scene = Scene_Map.new
      else
        wait(120)
        $scene = Scene_Map.new
      end
    end
  end

  Graphics.freeze
  dispose
end

#move



218
219
220
221
222
223
224
225
226
227
228
# File 'scripts/01450 Systems/09000 Games/00003 Ruine Alpha/00002 Ruine_Alpha_by_FL0RENT_.rb', line 218

def move
  if @cursor_piece == nil
    Audio.se_play(MOVESOUND1, 80) if MOVESOUND1
    wait(5)
    @cursor.opacity = 255
    @cursor_wait = 0
  else
    Audio.se_play(MOVESOUND2, 80) if MOVESOUND2
    wait(5)
  end
end

#pieces_position



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'scripts/01450 Systems/09000 Games/00003 Ruine Alpha/00002 Ruine_Alpha_by_FL0RENT_.rb', line 185

def pieces_position
  @cursor.x = BaseOffsetX + @cursor_x * 24
  @cursor.y = BaseOffsetY + @cursor_y * 24

  for piece in @pieces
    if @cursor_piece == piece
      piece.x = BaseOffsetX + @cursor_x * 24
      piece.y = BaseOffsetY + @cursor_y * 24
      piece.z = 1
    else
      for line in @grid
        if line.include?(piece)
          x = @grid.index(line).to_i
          y = line.index(piece).to_i
          piece.x = BaseOffsetX + x * 24
          piece.y = BaseOffsetY + y * 24
          piece.z = 0
        end
      end
    end
  end
end

#update



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'scripts/01450 Systems/09000 Games/00003 Ruine Alpha/00002 Ruine_Alpha_by_FL0RENT_.rb', line 109

def update
  if @cursor_piece == nil
    @cursor_wait += 1
    @cursor_wait = 0 if @cursor_wait > 40
    @cursor.opacity = 0 if @cursor_wait == 20
    @cursor.opacity = 255 if @cursor_wait == 0
  end
  if Input.trigger?(:B)
    return $scene = Scene_Map.new
  elsif Input.trigger?(:DOWN)
    unless @cursor_y >= 5 or (@cursor_y == 4 and @cursor_x != 0 and @cursor_x != 5)
      @cursor_y += 1
      move
    end
  elsif Input.trigger?(:UP)
    unless @cursor_y == 0
      @cursor_y -= 1
      move
    end
  elsif Input.trigger?(:RIGHT)
    unless @cursor_x >= 5 or @cursor_y == 5
      @cursor_x += 1
      move
    end
  elsif Input.trigger?(:LEFT)
    unless @cursor_x == 0 or @cursor_y == 5
      @cursor_x -= 1
      move
    end
  elsif Input.trigger?(:A)
    if @cursor_piece == nil
      if @grid[@cursor_x][@cursor_y]
        wait 4
        @cursor_piece = @grid[@cursor_x][@cursor_y]
        @grid[@cursor_x][@cursor_y] = nil
        Audio.se_play(TAKESOUND, 80) if TAKESOUND
        @cursor.bitmap = RPG::Cache.interface(GR_CursorB)
        @cursor.opacity = 255
        @cursor_wait = 0
      end
    else
      if @grid[@cursor_x][@cursor_y] == nil
        wait 4
        @grid[@cursor_x][@cursor_y] = @cursor_piece
        @cursor_piece = nil
        Audio.se_play(PLACESOUND) if PLACESOUND
        @cursor.bitmap = RPG::Cache.interface(GR_Cursor)
      end
    end
  else
    return #> Condition évitant le pieces_position quand aucune action est réalisée
  end
  pieces_position
end

#victory_check



174
175
176
177
178
179
180
181
182
183
# File 'scripts/01450 Systems/09000 Games/00003 Ruine Alpha/00002 Ruine_Alpha_by_FL0RENT_.rb', line 174

def victory_check
  4.times do |x|
    4.times do |y|
      if @grid[x + 1][y + 1] != @pieces[y + (4 * x)]
        return false
      end
    end
  end
  return true
end

#wait(x)



208
209
210
# File 'scripts/01450 Systems/09000 Games/00003 Ruine Alpha/00002 Ruine_Alpha_by_FL0RENT_.rb', line 208

def wait(x)
  Graphics.wait(x * 3 / 2)
end

#wait_hit



212
213
214
215
216
# File 'scripts/01450 Systems/09000 Games/00003 Ruine Alpha/00002 Ruine_Alpha_by_FL0RENT_.rb', line 212

def wait_hit
  until Input.trigger?(:A) or Input.trigger?(:B)
    Graphics.update
  end
end