Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1401678 Posts in 67940 Topics- by 61496 Members - Latest Member: Lankar5

July 07, 2022, 12:15:32 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)A little game I made (advice needed)
Pages: [1]
Print
Author Topic: A little game I made (advice needed)  (Read 2409 times)
Akhel
Level 10
*****



View Profile
« on: April 22, 2008, 01:47:36 PM »

Hello Tigers,

A few weeks ago I started learning Python and PyGame. I don't know much yet, but I did manage to complete a very small game - STORMTANK2, named that way because "storm" and "tank" were the first two words to come into my head when I thought "what game should I make?". Tongue The first STORMTANK did not involve PyGame and sucked too much for me to show it around.

This is not a terribly fun game; I didn't give much thought to its design. I made it just as an exercise.

So what I'm asking for is some feedback on my code. What do you think I did wrong? What can I improve and how? The AI is very rudimentary because I don't know how to make pathfinding and such; any good resources on that? The code is extensively commented, but I'm not sure if it's legible enough. If it isn't, what mistakes did I make and how could I avoid them in order to write more human-readable code in the future?

Python is very simple, so maybe you could give this a shot even if you don't know the language.

I'm more interested in advice about the game logic than Python or PyGame, but these are certainly very very welcome as well. Advice about the game design is not unwelcome, but not my primary goal (that's why I'm posting this in Technical instead of Feedback).

I'm not sure if I'm asking for too much, but I'd be very thankful if someone could help me. Please note I had no prior significant programming experience.

(You'll need Python and PyGame to run the file above; a package containing the source code and a standalone version can be found here.)

Thanks! Smiley
Logged
Zaphos
Guest
« Reply #1 on: April 22, 2008, 03:43:12 PM »

The AI is very rudimentary because I don't know how to make pathfinding and such; any good resources on that?
I haven't looked at the code yet, but for pathfinding in games usually people just use A*.
Logged
Headmade
Level 0
***



View Profile
« Reply #2 on: April 22, 2008, 08:13:30 PM »

I had a look at your code and I have noticed quiet a few things that could be improved.

First you should split up your code into logical blocks and create a separate file for every block and import them as needed. At the moment there are bits of your initialization scattered before and after your classes/procedures (e.g. you initialize your screen before but your clock after your class declaration).

It seems you are using ciphers like 'u' for up and so on. I don't think this is bad, but you really should rethink the way you use it in your code. Imagine you had to change one of those ciphers for some reason. You would have to change those ciphers where ever you use them. In general you should try to centralize such things so if you need to change something, you simply change it in one spot. So you could for example define a global constant UP = 'u' just like you do with BLACK.

In your Tank class' __init__() function you load images. This is not really the best way to do this, because whenever you create a object of that class you automatically load the images. Imagine you would create multiple objects of that class with the same color. Not only does that slow down the creation of those object but also the images you load are redundant since you have loaded them before. I suggest a sort of resource manager that loads all the data once and provides all the images and sounds your tank objects need.
You probably should redesign this class anyway. I suggest you separate the AI form the human tanks. For example you could make 3 classes: Tank, HumanTank, AiTank. Tank has all attributes and methods both human and AI have in common. HumanTank and AiTank both derive from Tank. This is just a suggestion, maybe you can come up with something better.

There is probably more but that should be enough for the moment.

If you really want to improve the quality of your code I recommend you read up on object oriented design, how to write solid code and such. There are a lot of books on that topic. But to be honest with you I don't think you really need too much of this if you want to make rather simple games. This stuff is however really useful for complex projects. 
As for python specific books "Game Programming with Python" seems to be a pretty good (look it up on google books, you can read a rather large portion of it for free). I haven't read it (though I really would like to) but from what I've seen you will get a very solid code design. And it also covers the basics of AI (state machines, A* path finding). However the book is not intended for novices so you should check it out on google first to see if it is suited for you.
Logged
Hideous
That's cool.
Level 10
*****


3D models are the best


View Profile WWW
« Reply #3 on: April 22, 2008, 09:39:50 PM »

That book is exactly the one he's reading already Tongue
Logged

Akhel
Level 10
*****



View Profile
« Reply #4 on: April 23, 2008, 11:11:03 AM »

Thanks a lot for the tips, Tinarg. Kiss

As for the book, yeah, I was reading it, but it's not very good. There are many things the author doesn't explain properly, there are no exercises and everything feels very rushed.
Logged
Headmade
Level 0
***



View Profile
« Reply #5 on: April 23, 2008, 12:25:47 PM »

Thanks a lot for the tips, Tinarg. Kiss
No problem. Let me know as soon as you've a new version and I will have another look at it, if you want.

As for the book, yeah, I was reading it, but it's not very good. There are many things the author doesn't explain properly, there are no exercises and everything feels very rushed.
As I said it's intended for advanced users. I'm sure you will appreciate the book once you hit a certain level.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic