Sprites... I suck at them....(rubygame)

okay here is my little sprite file with rubygame

require “rubygame”
$stdout.sync = true
Rubygame.init()

class Chr
include Rubygame::Sprites::Sprite
@@chrforward = Rubygame::Image.load(“forward.png”)
@@chrleft = Rubygame::Image.load(“left.png”)
@@chrright = Rubygame::Image.load(“right.png”)
@@chrbackword = Rubygame::Image.load(“backwords.png”)
@@chrforward.set_colorkey(@@chrforward.get_at([0,0]))
@@chrleft.set_colorkey(@@chrleft.get_at([0,0]))
@@chrright.set_colorkey(@@chrright.get_at([0,0]))
@@chrbackword.set_colorkey(@@chrbackword.get_at([0,0]))

def load_image_for(dir)
if dir == “back” || dir == “backword”
return @@chrbackword
elsif dir == “left”
return @@chrleft
elsif dir == “right”
return @@chrright
elsif dir == “forward” || dir == “up”
return @@chrforward
end
end

def initalize(x,y,starter=“forward”)
@image = load_image_for starter
@rect = Rubygame::Rect.new(x,y,*@@chrforward.size)
end

def update_image(dir)
load_image_for dir
end

def update(dir)
self.update_image(dir)
@rect = @image.size
end

end

class MyNPC
include Rubygame::Sprites::Sprite
@@npcforward = Rubygame::Image.load(“npcforward.png”)
@@npcleft = Rubygame::Image.load(“npcleft.png”)
@@npcright = Rubygame::Image.load(“npcright.png”)
@@npcbackword = Rubygame::Image.load(“npcbackwords.png”)
@@npcforward.set_colorkey(@@npcforward.get_at([0,0]))
@@npcleft.set_colorkey(@@npcleft.get_at([0,0]))
@@npcright.set_colorkey(@@npcright.get_at([0,0]))
@@npcbackword.set_colorkey(@@npcbackword.get_at([0,0]))

def load_image_for(dir)
if dir == “back” || dir == “backword”
return @@npcbackword
elsif dir == “left”
return @@npcleft
elsif dir == “right”
return @@npcright
elsif dir == “forward” || dir == “up”
return @@npcforward
end
end

def initalize(x,y,starter=“forward”)
@image = load_image_for starter
@rect = Rubygame::Rect.new(x,y,*@@npcforward.size)
end

def update_image(dir)
load_image_for dir
end

def update(dir)
self.update_image(dir)
@rect = @image.size
end

end

class ChrGroup < Rubygame::Sprites::Group
include Rubygame::Sprites::UpdateGroup
end

screen = Rubygame::Screen.set_mode([320,240])
screen.set_caption(“Sprite test”,“SPRITE TEST”)
background = Rubygame::Surface.new(screen.size)

mainchr = Chr.new
npc = MyNPC.new
mainchr.initalize(0,0)
npc.initalize(50,50)

chrs = ChrGroup.new
chrs.push(mainchr,npc)
chrs.draw(screen)

catch(:rubygame_quit) do
loop do
chrs.undraw(screen,background)
chrs.update(“left”)
puts “left”
sleep 2
chrs.update(“up”)
puts “up”
sleep 2
chrs.update(“right”)
puts “right”
sleep 2
chrs.update(“down”)
puts “down”
sleep 2
chrs.draw(screen)
screen.update()
end
end

Very messey I know! Well two problems with it…
one:
chrs.update doesn’t seem to be drawing them
two:
one the secound loop it crashes because then it dosn’t like
chrs.undraw

is there a better placce for me to post these also does anyone know a
good tut. on rubygame?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs