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

Login with username, password and session length

 
Advanced search

878391 Posts in 32920 Topics- by 24332 Members - Latest Member: IrritumGame

May 21, 2013, 07:25:00 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Doubt about two cods running at the same time
Pages: 1 [2] 3
Print
Author Topic: Doubt about two cods running at the same time  (Read 1053 times)
Dacke
Level 10
*****


I have never been to Woodstock


View Profile
« Reply #15 on: June 04, 2012, 02:21:24 AM »

@SuperDisk
To make use of that you would need a non-blocking input (via Curses). But if we had a non-blocking input, there wouldn't be a need for threads in the first place. The whole multi-threading-thing was just an unlucky guess by Strelok.


You're right. I am just starting as a programmer. I'll keep with only Python. I'm not read to use external libraries, and I'll try to simplify my design until I have something I can program without problems. After finishing it I'll be able to update it as soon as my skills become better.

Thanks guys.

Do this  Hand Thumbs Up Left  Smiley  Hand Thumbs Up Right
Logged

vegan • socialist • atheist • humanist • liberal • FOSSer
programmer • feminist • animal rights activist • pacifist • teetotaller
SuperDisk
Level 1
*



View Profile Email
« Reply #16 on: June 04, 2012, 07:44:26 AM »

Ok, I see what you mean. Then your only option is a turn-based game, which isn't necessarily a bad thing.
Logged
Strelok
Level 0
***


Worldbuilder

matheurge@gmail.com
View Profile WWW Email
« Reply #17 on: June 04, 2012, 11:24:13 AM »

I'm downloading Pygame and I noticed that its version is still 2.7. I'm using Python 3.2.3. Is it going to work? If not, do I need to learn the old Python?
Logged
Dacke
Level 10
*****


I have never been to Woodstock


View Profile
« Reply #18 on: June 04, 2012, 11:30:00 AM »

http://www.pygame.org/wiki/FrequentlyAskedQuestions#Does%20Pygame%20work%20with%20Python%203?

Quote
Does Pygame work with Python 3?

Only the scrap, _movie, surfarray for Numeric, and threads modules have not been ported. The Pygame alternative, pgreloaded (Pygame Reloaded), also supports Python 3.

The installation packages, however, are incompatible with Python 3.x, so you will have to copy - paste files from 2.x to 3.x .

So: yes. May need a little bit of extra setup work, though.
Logged

vegan • socialist • atheist • humanist • liberal • FOSSer
programmer • feminist • animal rights activist • pacifist • teetotaller
J-Snake
Level 10
*****



View Profile WWW Email
« Reply #19 on: June 04, 2012, 11:59:32 AM »

When I started with programming I had the same problem and I approached it the same way like you. But it is not how stuff is usually done. It is much simpler. In games usually (especially the stuff you are trying to achieve) the game-logic is processed sequentially, command after command, but within a short period of time (1/ 60 - 1/30 of a second). That is how you approximate simulaneous happening: Just throw in all the stuff that needs to be processed in the frame. As beginner in game-programming you should make yourself familiar with the so called "game-loops", just google for them. From then on everything will be clear to you.

Have fun.
Logged
Strelok
Level 0
***


Worldbuilder

matheurge@gmail.com
View Profile WWW Email
« Reply #20 on: June 04, 2012, 12:33:01 PM »

Are there any ways of working with graphics without any external library in Python? I mean, knowing the basics(matrix, hashes, functions, etc...). Can I do something like a tilemap code with it.

Or I really need an library if I plan on doing a 2d minigame in the future. Because of multithreading and for easy graphic manipulation?

@J-Snake: I'll do it.
Logged
Dacke
Level 10
*****


I have never been to Woodstock


View Profile
« Reply #21 on: June 04, 2012, 12:39:04 PM »

If it's enough to have something turn-based and text-based you can do it with print and input in the terminal. That is easier and lets you practice basic concepts.

Pygame is the easiest way to making simple games with graphics. Grab a sample-game from the pygame-site and try to understand it and make changes to it. If you can't get it to run with Python 3, then you can probably switch to Python 2 (they are very similar)

Do note that you should (almost) never use multi-threading, unless you know exactly what you are doing. Just get any thoughts of multi-threading out of your head Smiley
Logged

vegan • socialist • atheist • humanist • liberal • FOSSer
programmer • feminist • animal rights activist • pacifist • teetotaller
rivon
Level 10
*****



View Profile
« Reply #22 on: June 04, 2012, 12:48:12 PM »

Do note that you should (almost) never use multi-threading, unless you know exactly what you are doing. Just get any thoughts of multi-threading out of your head Smiley
Exactly. You will almost surely never need any kind of multi-threading in games unless you are making an AAA game.
Logged
Strelok
Level 0
***


Worldbuilder

matheurge@gmail.com
View Profile WWW Email
« Reply #23 on: June 04, 2012, 12:54:59 PM »

What I meant by multi-thread was to make to parts of the same code run at the same time. At least it is that way how two monsters move individualy at the same time as the player in a 2d RPG isn't it? That's what I meant.
Logged
Dacke
Level 10
*****


I have never been to Woodstock


View Profile
« Reply #24 on: June 04, 2012, 01:16:17 PM »

No, that's not multi-threading.

As several people have said:
You use a gameloop that updates everything many times every second.

So you just have something like this:

Code:
def gameloop():
   moveMonsterA()
   moveMonsterB()
   movePlayer()

You move the monsters and the player a tiny, tiny bit. Maybe one pixel or something. Since you run the gameloop over and over it will look as if they move at the same time*. But in fact they just take turns:
MonsterA-MonsterB-Player-A-B-P-A-B-P... over and over a million times.

Look at some pygame-example and you'll find out how it works Smiley

* You don't update the screen until they all have moved, so they actually do move at the same time on the screen. But in the game logic they take turns.
« Last Edit: June 04, 2012, 01:27:42 PM by Dacke » Logged

vegan • socialist • atheist • humanist • liberal • FOSSer
programmer • feminist • animal rights activist • pacifist • teetotaller
Strelok
Level 0
***


Worldbuilder

matheurge@gmail.com
View Profile WWW Email
« Reply #25 on: June 04, 2012, 01:39:53 PM »

Got it! Finally.

I'll stop bottering you guys with my questions, but first. I've downloaded Pygame and installed it. How do I check if it was installed correctly?

Thanks for all the light guys!  Smiley
Logged
rivon
Level 10
*****



View Profile
« Reply #26 on: June 04, 2012, 01:40:35 PM »

Code:
while (true):
    handle_input()
    update_all_entities()
    draw_everything()
All this runs tens to hundreds of times every second.
Logged
Dacke
Level 10
*****


I have never been to Woodstock


View Profile
« Reply #27 on: June 04, 2012, 01:45:36 PM »

..or at least 60 times per second if you are running at 60 FPS

I have never actually used Pygame, so I can't answer that question directly. But most tutorials have a getting-started-section that tells you how to set things up. Maybe this one?
http://rene.f0o.com/mywiki/PythonGameProgramming

Feel free to keep asking questions!
Logged

vegan • socialist • atheist • humanist • liberal • FOSSer
programmer • feminist • animal rights activist • pacifist • teetotaller
Strelok
Level 0
***


Worldbuilder

matheurge@gmail.com
View Profile WWW Email
« Reply #28 on: June 04, 2012, 08:42:10 PM »

Code:
while (true):
    handle_input()
    update_all_entities()
    draw_everything()
All this runs tens to hundreds of times every second.

Those codes inside the while are all call to functions? Do I put a "if gameOver: break()" at the end of it so if the player dies or finishes the game the loop will be break?
Logged
SuperDisk
Level 1
*



View Profile Email
« Reply #29 on: June 05, 2012, 06:37:34 PM »

I suggest that if you want to use Python 3 and still use Pygame, take a gander at Christoph Gohlke's Python Extensions page. He has ported many Python libraries to Python 3. Pygame is already ported to Python 3.3 alpha! Gentleman
Logged
Pages: 1 [2] 3
Print
Jump to:  

Theme orange-lt created by panic