Advertisement

How to create games using Python

Started by January 29, 2014 04:47 PM
7 comments, last by pyirrlicht 11 years ago

I'm creating a game,and I'm new to these Programming stuff.I would like to create an good(or hard)Ai for my game How do I create an Ai that can do these things:

1.When it sees an enemy it will shoot it.

2.When getting shot it will take cover or run away/retreat.

3.Will NOT shoot allies.(If on Team games)

4.When an Ally is near and getting shot the Ai teammate will help.

5.Can camp and/or hide from the enemy or ambush an enemy.

6.Will protect and stay in the base if there are no one guarding it(On Kill the Base mode)

7.Will capture the enemy flag and bring it to back to base.(On capture the flag mode)

I'm planning on creating many game modes,like:

Deathmatch - No teams just kill anyone you see.

Team Deathmatch - Up to 4 teams.

Defend the Base - Defend the base against waves/hordes of zombies.

Kill the Base - Kill/Destroy the enemy base and not letting your get destroyed.

Capture the Flag - Capture the enemies Flag and bring it back to your base.

Elimination - Each player has there set of lives if it gets to 0 you lose,Team or No teams

do you know the language already?

then I would suggest to use pygame (http://www.pygame.org) as base for

your game. IF you not know the language yet, I say go a step back.

Start with some easier topics. Don't try to do something where you lack

to much of programming experience. Start slow and take it step for step.

  • Learn your language
    • train Text Input / Output on the console
    • train File Input/ Output
    • program an calculator first
    • learn about algorhythm
    • wrote a programm which try to organise simple data( e.g. table numbers and names )
  • Learn the API of PyGame
    • learn to initialize a Window
    • try to draw a picture
    • try to move a picture
    • try to clip a picture
    • try to play sound
    • try to handle input
    • try to move a picture with your input
    • try to move a picture with your input and check if it hit something.
    • try to move a picture with your input and check if it hit something and play a sound.
    • try to write something on the screen
    • try to read some user input over the screen and print what the user wrote on the screen

If you have done all this you can take the next step and write and game like tic tac to or an sidescroller, etc

but important is you go step by stepstep by stepstep by step into the topic. Otherwise you will get frustrated and stop.

The clue is if you go small steps you will see progress and progress ends often in success. both progress and success let you

feel very good. belive me, perhaps that takes some time, but that is an relative save way to go. of course is my list above only

a example/suggestion( my example only includes graphical stuff ;) ). which way you will go is up to you.

If you want learn something about AI's use this site there is really a lot stuff you could use: http://aima.cs.berkeley.edu/index.html

Advertisement

Considering you just started, none of those are questions you should be asking. They cannot be answered in a (to you) helpful way either.

Start with something small. Like Guess-a-number. The program creates a random number and asks the user to guess it. The program tells the user "right" or "wrong" after each guess, the program ends when the user guessed right.

If you have never programmed anything before, this is a very significant challenge.

I would suggest reading this free beginners book to programming, that also teaches basic game prigramming [LINK] .

Here is another free, but bit more advanced book to read on Python game creation [LINK] .

If you would like to learn the basics of programming and Python, this free book is great [LINK] !

I cannot remember the books I've read any more than the meals I have eaten; even so, they have made me.

~ Ralph Waldo Emerson

do you know the language already?

then I would suggest to use pygame (http://www.pygame.org) as base for

your game. IF you not know the language yet, I say go a step back.

Start with some easier topics. Don't try to do something where you lack

to much of programming experience. Start slow and take it step for step.

  • Learn your language
    • train Text Input / Output on the console
    • train File Input/ Output
    • program an calculator first
    • learn about algorhythm
    • wrote a programm which try to organise simple data( e.g. table numbers and names )
  • Learn the API of PyGame
    • learn to initialize a Window
    • try to draw a picture
    • try to move a picture
    • try to clip a picture
    • try to play sound
    • try to handle input
    • try to move a picture with your input
    • try to move a picture with your input and check if it hit something.
    • try to move a picture with your input and check if it hit something and play a sound.
    • try to write something on the screen
    • try to read some user input over the screen and print what the user wrote on the screen

If you have done all this you can take the next step and write and game like tic tac to or an sidescroller, etc

but important is you go step by stepstep by stepstep by step into the topic. Otherwise you will get frustrated and stop.

The clue is if you go small steps you will see progress and progress ends often in success. both progress and success let you

feel very good. belive me, perhaps that takes some time, but that is an relative save way to go. of course is my list above only

a example/suggestion( my example only includes graphical stuff ;) ). which way you will go is up to you.

If you want learn something about AI's use this site there is really a lot stuff you could use: http://aima.cs.berkeley.edu/index.html

Considering you just started, none of those are questions you should be asking. They cannot be answered in a (to you) helpful way either.

Start with something small. Like Guess-a-number. The program creates a random number and asks the user to guess it. The program tells the user "right" or "wrong" after each guess, the program ends when the user guessed right.

If you have never programmed anything before, this is a very significant challenge.

I would suggest reading this free beginners book to programming, that also teaches basic game prigramming [LINK] .

Here is another free, but bit more advanced book to read on Python game creation [LINK] .

If you would like to learn the basics of programming and Python, this free book is great [LINK] !

HAHAlaugh.png You people just ruined this guy dreams.. Louie..yea. You must start small. If this will be your first game, learn firstly how to programm and how is structured a game. Don't jump directly to AI!

"Don't gain the world and lose your soul. Wisdom is better than silver or gold." - Bob Marley

1.When it sees an enemy it will shoot it.


class Coord:
 def __init__(self, x = 0, y = 0, have_enemy = False):
  self.x = x; self.y = y; self.have_enemy = have_enemy

# global array Coords, you must set this as all your game cells and change later in game loop
Coords = (Coord(0, 0, False), Coord(0,1,False), Coord(1,1, True))

def shoot(coord):
 pass # change to your code

def collision_with_enemy():
 for coord_item in Coords:
  if coord_item.have_enemy:
   shoot(coord_item)
Advertisement

1.When it sees an enemy it will shoot it.


class Coord:
 def __init__(self, x = 0, y = 0, have_enemy = False):
  self.x = x; self.y = y; self.have_enemy = have_enemy

# global array Coords, you must set this as all your game cells and change later in game loop
Coords = (Coord(0, 0, False), Coord(0,1,False), Coord(1,1, True))

def shoot(coord):
 pass # change to your code

def collision_with_enemy():
 for coord_item in Coords:
  if coord_item.have_enemy:
   shoot(coord_item)

I dont understand this sad.png ohmy.png

its so complicated(for me)

1.When it sees an enemy it will shoot it.


class Coord:
 def __init__(self, x = 0, y = 0, have_enemy = False):
  self.x = x; self.y = y; self.have_enemy = have_enemy

# global array Coords, you must set this as all your game cells and change later in game loop
Coords = (Coord(0, 0, False), Coord(0,1,False), Coord(1,1, True))

def shoot(coord):
 pass # change to your code

def collision_with_enemy():
 for coord_item in Coords:
  if coord_item.have_enemy:
   shoot(coord_item)

I dont understand this sad.png ohmy.png

its so complicated(for me)

Why you jump already to AI? Make a simple game for start. My first game was a tic tac toe clone (without AI) and my first game including artificial intelligence was PONG.

Check my profile to see them.

And here is a book about making games in Python and Pygame. Read It!

http://inventwithpython.com/makinggames.pdf

"Don't gain the world and lose your soul. Wisdom is better than silver or gold." - Bob Marley

I dont understand this

you can learn draw cells example, mainly "live_grid_2d" class - perhaps it helps to understand how to divide the screen into areas for further work with them

This topic is closed to new replies.

Advertisement