The Campaign Builder's Guild

The Archives => The Crossroads (Archived) => Topic started by: SDragon on May 06, 2009, 11:26:02 AM

Title: Just what this site needs...
Post by: SDragon on May 06, 2009, 11:26:02 AM
It's own computer game. I decided I wanted to try writing my own video game, and somehow ended up getting inspiration from... cabbage.

The basic premise of this game is fairly simple. You, the player, are running around a cabbage patch grabbing cabbages. The more cabbage you get, the higher your score. The catch is that The Fiend is also running around this patch, so you have to avoid being caught by him... Or Else! Another element I'm thinking of is having something else growing in the cabbage patch; carrots, for example.

Since I'm such a novice at programming, and since I've already established that this game would be for the site, I figured this would be as good of a place for development as any. Python is the language of choice, since it's the only one I know so far. Here's the stripped down basics of what I have so far:

[spoiler=Game outline so far]
class map(object):
row_a = [a1, a2, a3, a4, a5, a6, a7, a8, a9]# blank space = "^"
row_b = [b1, b2, b3, b4, b5, b6, b7, b8, b9]# inert things = "Y", active things = "@"
row_c = [c1, c2, c3, c4, c5, c6, c7, c8, c9]# player = "P", enemy = "F"
map = [row_a, row_b, row_c]
for i in map:
print i


class thing(object):
def position():
class activething(thing):
def active():
def deactive():
wait = #random time to wait
waited = #number of turns waited
if waited = wait: #change to active

class people(object):
def position():
class player(people):
def move():#user input
def deactivate():
def die():#endgame
class enemy(people):
def move():#AI
def kill():#trigger endgame

def mainloop():

mainloop()
[/spoiler]

Does anyone feel like helping this little project along?
Title: Just what this site needs...
Post by: Ghostman on May 06, 2009, 02:17:14 PM
Just an idea: maybe the fiend is also turning fresh cabbages into rotten cabbages, and you have to avoid grabbing those. Good luck with the project!
Title: Just what this site needs...
Post by: sparkletwist on May 06, 2009, 05:19:27 PM
I don't know anything about Python, so I can't really comment on anything specific. Most development I've done has been in C or C++.

I do have some general thoughts:

How is the game going to be presented? It looks like you're doing something with just straight ASCII art, is that correct? Or are you using PyGame?

Even if it's just ASCII art, I'd have some separation between the presentation of your tilemap and how it's stored internally. That is, I would have an array of "Tile" classes, rather than simple characters. This is more complex at first, but allows room for expansion, and will ultimately save your sanity. ;)
Title: Just what this site needs...
Post by: SDragon on May 06, 2009, 08:54:34 PM
At this point in development, I want it ASCII, but I do eventually want it to have graphics.

What I was thinking for the elements was that each class had a character/sprite in the class, and it wouldn't be saved in the map itself. I'm not sure if that's what you mean or not, but if it is, that's what I'm thinking.

Also, it might not matter too much if you know Python or not. I mean, obviously it helps, but I think there's a few members on here who know the language, anyway. If you write in other languages, you can still try to give some general programming ideas :)
Title: Just what this site needs...
Post by: Nomadic on May 06, 2009, 08:56:32 PM
So it's like pacman, but with demons and fresh farm-grown vegtable?
Title: Just what this site needs...
Post by: Loch Belthadd on May 06, 2009, 09:31:54 PM
Quote from: NomadicSo it's like pacman, but with demons and fresh farm-grown vegtable?
no demons, just the fiend of the 9th cabbage.

also, I am saddened by the lack of turtles in this game.
Title: Just what this site needs...
Post by: SDragon on May 06, 2009, 09:43:09 PM
Quote from: NomadicSo it's like pacman, but with demons and fresh farm-grown vegtable?

Yes, only it's a field instead of a maze. There's a few other noticeable differences, but yes, Pac-Man is the closest equivalent.


Loch, why can't we say the player is a turtle?
Title: Just what this site needs...
Post by: Loch Belthadd on May 06, 2009, 09:57:53 PM
that works, but if there weren't any turtles...
Title: Just what this site needs...
Post by: Nomadic on May 07, 2009, 01:00:14 AM
Quote from: Rorschach Fritos
Quote from: NomadicSo it's like pacman, but with demons and fresh farm-grown vegtable?

Yes, only it's a field instead of a maze. There's a few other noticeable differences, but yes, Pac-Man is the closest equivalent.


Loch, why can't we say the player is a turtle?

But that would imply that turtles can die... and that is of course impossible.
Title: Just what this site needs...
Post by: SDragon on May 14, 2009, 10:33:42 AM
Certainly, "die" in this case is just shorthand for "allows self to be captured indefinitely as part of an elaborate supersecret plan to bring benevolence to the world". It's easier to type.

Anyway, we're definitely going to need to import Random for the Fiend's AI, and probably for the placement of the cabbages. I think we might eventually need to import the Time module (that sounds so sci-fi), but I just want to deal with the basic mechanics first.
Title: Just what this site needs...
Post by: sparkletwist on May 14, 2009, 09:04:10 PM
You'll also need the time for seeding the random number generator. This process is pretty trivial in C++:
srand(time(NULL));

I'd be surprised if Python was more complicated.

How are you timing the game?
Title: Just what this site needs...
Post by: SDragon on May 15, 2009, 11:53:44 AM
The Random module has a few options for number generators, but I think randrange might be best. Probably something like:

random.randrage(1, 8)

For the AI movement, with each number being a different direction on the grid. You could use that with the range going up to however many cells the map has, and have it for the random placement of the elements (characters, vegetables). For the AI, there will also have to be a variable that saves the last move made, to prevent the Fiend from simply moving back and forth between two cells. Here's what I just thought up:

The direction of movement has a design that's something like:

512
6F3
784


and the AI would have something roughly along the lines of:

while fiendlastmove + fiendcurrentmove == 9:
fiendcurrentmove = random.randrange(1, 8)


Hm. Apparently I can't show the randrange method ending at 8. That's odd.

Timing, at this point in development, is turn-based, but I do want it to eventually be realtime.
Title: Just what this site needs...
Post by: brainface on May 15, 2009, 02:28:43 PM
Quote from: random numbersimport random
random.seed() # you only need to call this once inside a program.
random.randint(1,8 ) # call however many times as needed.
[/code]
randint(1,8 ) is equal to randrange(1,8,1)

Python random numbers are Mersenne Twister generated--this is good enough unless you're actually the CIA or trying to encrypt files. Don't let anyone ever tell you different, they will be wrong and much suffering will ensue. (People are very good at detecting patterns, and will detect patterns in even random numbers, then tell you that your numbers aren't random. trust me on this.)
Title: Just what this site needs...
Post by: SDragon on May 15, 2009, 03:05:03 PM
Don't the steps in randrange default to 1, though? So, in that case, there really isn't any difference between randint and randrange unless you specify the steps. Wouldn't that make randint obsolete?

Edit-- looking in one of my books (Python in a Nutshell), I don't even see the randint method. Maybe it's been phased out or something? Anyway, I have enough experience with the random module to know that it's Good Enough for this project. I don't really expect powergaming CIA agents to play this ;)
Title: Just what this site needs...
Post by: brainface on May 15, 2009, 06:02:36 PM
ah, here's the deal:
Randrange does not include the upper bound, whereas randint does, so:

randint(1,6)
randrange(1,7)

both give a number between 1 & 6 inclusive.
Title: Just what this site needs...
Post by: SDragon on May 15, 2009, 07:52:48 PM
Ah, ok. So just make the upper bound +1 with randrange, then.
Title: Just what this site needs...
Post by: Captain Obvious on May 16, 2009, 05:33:23 AM
So, I don't know the programming, but here's some thoughts.
You run around the field grabbing cabbages.
The Cabbages gradually respawn.
Occasionally a tainted cabbage appears and if you grab one you die/get stunned.
The tainted cabbages stay as obstacles.
The fiend of the ninth cabbage follow you and you have to avoid him.
The fiend can't move through healthy cabbages and so can only follow your trail.
There are more and more turtles in higher levels.
They initially start trapped by the cabbage but if there are empty spaces adjacent, they move randomly around as obstacles.
The fiend can't move through turtles either.
Title: Just what this site needs...
Post by: Superfluous Crow on May 16, 2009, 06:20:37 AM
How would you control more than one turtle? Or did you mean Cabbage-fiends? Also, if it just follows your tracks why would it ever catch up with you? Unless it's faster in which case how do you avoid it?
Title: Just what this site needs...
Post by: sparkletwist on May 16, 2009, 08:24:21 PM
You might want to look into Pygame. It has a lot of features for game development. I've never used it, but I know people who have, and they seem to like it. Because it's optimized for game development it might actually even be easier than trying to shoehorn things into Python's normal capabilities.

As for movement, I'm not sure why you're using such a strange directional map. Is there some programming trick that makes it efficient to do it that way? I'd just do something where you picked a direction and decided it was 0, and then they simply increased clockwise or counterclockwise.

That said, the game might be simpler and more interesting if you just disallowed diagonal movement. You wouldn't have to worry about some weird collision situations that way (moving between two solid objects) and it would make the fiend's pathfinding a bit easier.
Title: Just what this site needs...
Post by: SDragon on May 16, 2009, 09:22:03 PM
Any two opposing directions add up to 9. That way, to prevent the Fiend from jumping back and forth between two cells, I just have to say if lastmove + currentmove =! 9. I don't have to work out every possible combination of opposing moves.

I suppose I could eliminate diagonal movement, but I'm not sure why I would have to. with this pattern, by the way, elliminating diagonals would look like:

X1X
2F3
X4X

while lastmove + currentmove =! 5:
    currentmove = random.randrange(1, 5)


Pygame might be good, yes, but I'm not convinced yet that it's necessary. I haven't really learned much about it yet (I'm still learning about classes), but when I get to that, I'll try to see what this can do with it.
Title: Just what this site needs...
Post by: sparkletwist on May 17, 2009, 01:16:24 PM
Quote from: Rorschach FritosI suppose I could eliminate diagonal movement, but I'm not sure why I would have to.
There's no reason you'd "have" to, but there are a few reasons why you might want to:
- It simplifies your control scheme
- It makes the fiend's pathfinding easier
- It completely avoids the problem that a diagonal move actually covers more ground
- It prevents some weird collision situations with moving between two blocking objects

I guess I'm a bit biased, personally, too, because a lack of diagonal movement is how I would do it. ;)
Title: Just what this site needs...
Post by: SDragon on May 18, 2009, 10:32:15 PM
We'll see. This is for the guild, so maybe if other people give input, we can come to a decision.
Title: Just what this site needs...
Post by: SDragon on December 02, 2009, 09:55:53 PM
Looked a bit into pygame, and it looks usable. If that's how I'm doing it, I think it should be tile-based graphics; I'm thinking a 500x500 screen with 25x25 tiles, which would give a 20x20 playing field. Thoughts?