2

So I've been messing with Ruby trying to make a sort of chicken simulator. I have all these instances of class Chicken with @x and @y variables which represent their position. They have methods like step(direction,steps), distance_from(object), take_shortest_path_to(object), etc.

There is a class Nest which places instances of itself on the grid and generates a group of Chickens, setting their starting positions to the Nest's @x and @y values.

I plan to give the Chickens the desire to go out into the "world", maybe in search of grain, with which they'll return to the Nest to stockpile. That actually sounds like SimAnt with chickens. Point is, I feel like a visual interface, even a very, very crude one, would be incredibly helpful at this point.*

But I'm not sure of the simplest way to do that. I feel like there's a lot more work I could do just on the logic before I really worry about how I'm going to actually render everything to the screen (if I even do; I'm really just doing this to learn the general vibe of OOP).

Any suggestions would be greatly appreciated! Thanks.

user2493615
  • 317
  • 1
  • 8
  • +1 for the chickens. But some code or indication of what you have tried would really help you get an answer. For game-like graphics you could check `gosu`, but warning that comes with a steep learning curve. – Neil Slater Sep 24 '13 at 07:34
  • I'm really just trying for sub-Atari level graphics. Gems mystify me at this point, but I thought there might be a way to render very crude graphics with pure Ruby. – user2493615 Sep 24 '13 at 07:43
  • 1
    How much detail do you need? Would a single character per game character suffice? For example, `.` representing an open cell, `C` for chicken, `N` for nest, etc. – sawa Sep 24 '13 at 07:46
  • 1
    @user2493615: Ruby doesn't have graphics support built in, you will need a library of some kind if you want graphics. This is true of nearly all general-purpose languages. – Neil Slater Sep 24 '13 at 07:49
  • Neil: Can you suggest a very lightweight and easy-to-use Ruby graphics library? sawa: That would suffice for much of my needs. Can you suggest a tutorial, etc. that would help me achieve that? – user2493615 Sep 24 '13 at 07:51

1 Answers1

2

Shoes seems to be a pretty popular (and easy to learn) GUI framework.

A sample oval in a (apart from the oval) empty window would look like that:

Shoes.app {
  oval(left:   10,
       top:    10,
       radius: 40)
}

enter image description here

You could then draw your nest with an oval (your chicken with images, etc.)

Inserting images is simple too:

Shoes.app {
  image "https://upload.wikimedia.org/wikipedia/commons/5/5e/Chicken_suit1.jpg"
}

Have a look at their tutorials for details.

tessi
  • 13,313
  • 3
  • 38
  • 50
  • Could an actual game be made with Shoes? It seems to be geared toward Powerpoint-style presentations and such. – user2493615 Sep 24 '13 at 08:43
  • 1
    Technically the answer is yes - shoes relies on ruby, ruby is [turing complete](https://en.wikipedia.org/wiki/Turing_complete) ;) Probably your question is "How much effort is needed to implement a game with shoes?" The answer is: It depends (do you want fancy 3D graphics, or simple ovals bouncing around in a grey window?). – tessi Sep 24 '13 at 09:20