Code:
class Game_Memory
# hier kommen alle Attribute rein die dein Spiel so hat
# filenames of the pictures of your cards
attr_accessor :figure_names
def initialize
@figure_names = ["Spinne1.png", "Spinne1.png",
"Spinne2.png", "Spinne2.png",
"Spinne3.png", "Spinne3.png",
"Spinne4.png", "Spinne4.png",
"Spinne5.png", "Spinne5.png",
"Spinne6.png", "Spinne6.png",
"Spinne7.png", "Spinne7.png",
"Spinne8.png", "Spinne8.png",
"Spinne9.png", "Spinne9.png",
"Spinne10.png", "Spinne10.png",
"Spinne11.png", "Spinne11.png",
"Spinne12.png", "Spinne12.png",
"Spinne13.png", "Spinne13.png",
"Spinne14.png", "Spinne14.png",
"Spinne15.png", "Spinne15.png",
"Spinne16.png", "Spinne16.png"
]
@positions = [
0, 0,
136, 0,
272, 0,
408, 0,
#
0, 104,
136, 104,
272, 104,
408, 104,
#
0, 208,
136, 208,
272, 208,
408, 208,
#
0, 312,
136, 312,
272, 312,
408, 312
]
# number of cards horizontal
@max_number_of_cols = 3
# size of cards
@card_width = 136
@card_height = 104
# distance between cards
@margin = 0
p @figure_names
p @positions
end
# returns x, y coordinates as well as the image name of
# the card with the given index
def get_card index
p "get_card index"
[card_x(index), card_y(index), card_image(index)]
p card_x(index)
p card_y(index)
p card_image(index)
end
# return all cards
def get_cards
p "get_cards"
# create a new array with elements
# for all indizes from 0 upto @positions.size
(0...@positions.size).map do |index|
# each element contains the result value of
# get_card
get_card index
end
end
# x coordinate for a given card index
def card_x index
p "card_x index"
col_num = index % @max_number_of_cols
col_num * (@card_width + @margin)
end
# y coordinate for a given card index
def card_y index
p "card_y index"
row_num = index / @max_number_of_cols
row_num * (@card_height+@margin)
end
# filename of card image
def card_image index
p "card_image index"
@figure_names[index]
#@figure_names[@positions[index]]
end
# number of different figures/cards
def number_of_pictures
p "number_of_pictures"
@figure_names.size
end
# add 2 cards for each figure into the field
# shuffle the positions of all cards
def shuffle_cards
p "shuffle_cards"
@positions.clear
# this loop is invoked as often as the number
# of different cards
number_of_pictures.times do |picture_id|
# for each invocation, two cards are added
# into the array
@positions << picture_id << picture_id
end
# shuffle the array at the end
@positions.shuffle!
end
end
class Game_System
p "Game_system"
# füge Memory als Attribut hinzu
attr_accessor :memory
end
# Erbebt von Scene_Base
class Scene_Memory < Scene_Base
p "Scene_Memory"
#class << self
#-------------------------------------------------------------------------------
# Überschreibt start von Scene_Base
#-------------------------------------------------------------------------------
def initialize_graphics
p "initialize_graphics"
# for each card in the game
@card_sprites = $game_system.memory.get_cards.map do |x, y, image|
# create a new sprite
sprite = Sprite.new
# set its graphic and coordinates
sprite.bitmap = Cache.picture(image)
sprite.x, sprite.y = x, y
# and "return" the sprite into the array
sprite
end
end
def update_graphics
p "update_graphics"
# update attributes of all sprites
@card_sprites.each_with_index do |sprite, index|
x, y, image = $game_system.memory.get_card(index)
sprite.bitmap = Cache.picture(image)
sprite.x, sprite.y = x,y
end
end
def dispose_graphics
p "dispose_grapics"
@card_sprites.each do |sprite|
sprite.dispose
end
end
#-------------------------------------------------------------------------------
# überschreibt terminate Scene_Base
#-------------------------------------------------------------------------------
def terminate
p "terminate"
super
dispose_graphics
end
#-------------------------------------------------------------------------------
# überschreibt update Scene_Base
#-------------------------------------------------------------------------------
def update
p "update"
super
update_graphics
end
def start #(start)
p "start"
super
initialize_graphics
update
end
end
#end
Eine tollkühne Vermutung meinerseits ist, dass er mosert das die Koordinaten aus @positions momentan einfach nicht zu den Werten aus @card_width und @card_height passen... wobei ich da momentan wirklich keinen Grund für sehe.