Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 23 Dec 2011
Offline Last Active Mar 21 2016 01:50 AM

#5070846 Developing a cloud service/server for your app?

Posted by on 18 June 2013 - 08:04 AM

I just want to chime in here quickly and point out something very important: If you're stil in the process of learning, do not concern yourself with Amazon EC2 or "scaling". First you need to make things work. Trying to wrap your head around concepts like elastic cloud computing, scaling, and optimization are just noise to a beginner.


Scaling problems will arise if and when you have enough users. When that happens, you'll need to figure out the bottlenecks. At this early stage, you should resist the temptation to guess how your application needs to scale and just focus on building it.

#5063838 Online multiplayer Game programming

Posted by on 22 May 2013 - 07:43 AM

Hi people ! I have a game making project in my college, and I wanted a little help about how to go on about it. So let me first describe the project.
I have made a box filling game using python and pygame, so i know how to make UI, and the game programming. Apart from it, I know C language. I don't know JAVA and other stuff as yet, but if needed i can try that.

Phase 1: Make a GUI game, LUDO in which, 2 or 4 people can play against each other, through net login. If possible, do something so that these players can play this game through their browser, like online games are done. I saw one of my classmates implemented a version where the game would ask the ip of the computer to play against, and then these two people can play together online, but this idiot won't tell me how she did it.

If you want the game to run in the browser, Python/pygame aren't going to work. Python doesn't run in the browser.

You're better off with HTML5/JavaScript.

I posted some links in the following thread that will help you get started: http://www.gamedev.net/topic/643107-new-to-coding-strategy-game/#entry5062232

Phase 2: Add another mode to the game, to play against computer. If chosen to play against the computer, the game should behave as an artificially intelligent player to play against a human.

I need help regarding this. First of all, as yet, i have decided to use python and pygame for it. But i really don't have any idea whether it's a good choice or not, how i'm going to implement these things, etc. Please suggest an approach to complete the game. Eg:- You should use this "blah blah" language, because it has "blah blah" feature, which will help you. Then you can implement it online using "blah blah" thing. also this language will make it easier for AI programming... etc. I hope you get the idea what i want to really ask. Please help.

See the link I posted above; that will give you a good idea of the technology you'll need to learn to implement this game.

#5062232 New to Coding - Strategy Game

Posted by on 16 May 2013 - 03:23 AM

Hello! Let me begin by saying that I am a complete novice when it comes to coding. I have a good handle on symbolic logic, but that seems to only be tangentially related to actual coding. However, I am eager to learn as I have, due to my upcoming three month sabbatical, been elected by my friends to learn how to code a strategy game that we've been working on for a few months. The main question that I have is this, what sort of language should I set myself to learn in order to successfully code this game?


Onto what I understand are the essentials. 


First of all, we want this to be a strictly online game played in browser. Some of us have tablets as our main computing devices, others have Macs, others Windows, etc. We figured that a browser-based game would off the greatest accessibility.


Second, to go along with the online theme, this will be strictly humans vs. humans; no AI teams will be included. What AI there will be will follow very simple rules involving movement only.


Third, the game is fairly similar to a more advanced Masters of Orion. At the moment, we're playing it via Dropbox utilizing a hex-based board. It will be more advanced in that technology will progress in a different manner and units are more customizable.


So, any ideas about what language I should look into using? Do you need more information?

As others said, learn HTML5/JavaScript.

- For graphics, have a look at `canvas`: https://developer.mozilla.org/en-US/docs/HTML/Canvas

- For sound, have a look at `audio`: https://developer.mozilla.org/en-US/docs/HTML/Using_HTML5_audio_and_video

- For the multiplayer aspect, you'll probably need to learn about WebSockets: https://developer.mozilla.org/en/docs/WebSockets

- For an example of a multiplayer browser game, have a look at "BrowserQuest": https://hacks.mozilla.org/2012/03/browserquest/, http://http://browserquest.mozilla.org/

  - BrowserQuest uses all of the above technology.

- With all of that, you can code the game yourself. You may also be able to build off of existing game engines/libs. Here's a list of JavaScript game engines: https://gist.github.com/bebraw/768272


I'm giving you a bunch of Mozilla links, but all of this stuff will work in most browsers. In fact, I've personally found `canvas` to perform slightly better in Chrome than in Firefox.


I think 3 months is ambitious if you're new to coding, but you should at least be able to turn out some sort of prototype. It will be a good learning experience. Be prepared to throws your prototype away and start again. Write as much code as you can, and don't worry if the code you write is crap. That's how you will learn.


Hope that helps.

#5061789 2d Platformer Gravity - constant or conditional!?

Posted by on 14 May 2013 - 08:34 AM

It depends on what you want exactly. Personally, I would go with the first approach you described (gravity constantly pulls, objects intersect, and collision response removes the intersection). This is relatively simple.


If you're just trying to make a basic platformer, I wouldn't try to emulate the Sonic physics. Sonice is nothing like most other platform games. Keep it simple.

#5056984 Understanding PyMMO

Posted by on 26 April 2013 - 09:21 AM

For the python standard libs, you shouldn't need any special citation. For other libs, check the project web page or source code for info about the license. When in doubt, ask the authors via email or IRC. Even if you do make a slight faux pas and forget to cite a lib properly, this shouldn't be a big problem unless you are trying to sell a product. But I'm not a lawyer, so do not take this as legal advice. Again, when in doubt, ask the author.

Regarding frameworks and libs, I see that you're trying to understand terminology. Knowing jargon and using it properly is good. :)

A library is simply a collection of functionality which encapsulates the details of a particular set of related tasks. An XML library is a good example (like the standard python 'xml' lib).

A framework may contain library-like code (and indeed, can be imported and used only as a library), but the distinguishing feature is that it suggests/forces you to construct your application a certain way. While a library will help you solve a particular problem in your application by abstracting away complexity, a framework will help you design, structure, and organize your code, in addition to abstracting away complexity.

Those are the best definitions I can come up with, in my own words. Someone else might have a better definition.

#5056945 Understanding PyMMO

Posted by on 26 April 2013 - 07:22 AM

I've read some of the style guide before, but haven't finished yet. I think I will finish it now, but don't worry, my code is pretty neat at the moment. Also, that tool will be useful.


I'm not worried. But someone else (including the future you) trying to read your code might. =)



I will start coding now. Is there a place here to post my code (when it's finished) so I can get feedback or review about it? I think getting some feedbacks will be nice.


Yes, there are many places to store your code online and receive feedback, which leads me to another important software development topic: version control. Are you using version control? If not, start using a version control system now.


One of the best places (in my opinion) to post code is GitHub.com. You'll need to learn how to use git, which is a great skill to have. Many people are using git. You can either store your code in your repository, or you can use `gists` which are a lighter-weight method of storing code and text. `gists` are ideal for small bodies of code (scripts, prototypes, examples, etc.), whereas a full repository is ideal for large bodies of code (a project, a library, etc.).


I recommend starting with gists first, because you don't need to learn git commands to use them. Gists are also good because they're tied to your github account, so you can find them easily. (As a software developer, github is a create place to build a portfolio. Many potential employers will ask for code samples; it's great to just be able to point them to your github page.)


Another simpler, quicker, and slightly more crude way to post code is to use something like pastebin.com or pastie.org. Both services can do syntax highlighting for a bunch of major languages (bash, C, XML, Java, Python, etc.).




If you're going to post code, make sure the license of the code is clear. This can either be done with a license header in the file (example: https://gist.github.com/larsbutler/5330230) or with a LICENSE file in the repository (example: https://github.com/larsbutler/geomet/blob/master/LICENSE.txt). If the code belongs to someone else, be sure to note who wrote it and how it is licensed. A lot of people who post code on their blogs do not specify a license for their code, which is a mistake in my opinion. (This leads to people either using code in such a way that the original author didn't intended or doesn't like, or simply not being able to use the code for fear of infringing on a copyright. The pymmo code, for example, did not include a license, as far as I can tell.


For your original code, you can choose an open source license so people can use your code. See http://en.wikipedia.org/wiki/List_of_software_licenses and http://opensource.org/licenses to find out more. If you don't really care that much and want to license your code in an extremely "free" way, the BSD or MIT license is a good choice.


If you want to post your code publicly, but you don't necessarily want to use an open source license, you can simply include a statement in your code that you are the copyright owner and that use of this code is not permitted for commercial/personal/educational (be specific as you want) purposes. Just be aware that if your code derived from open source licensed code, the license of that code may prohibit you from "closing" your code in this way.

#5056900 Understanding PyMMO

Posted by on 26 April 2013 - 05:38 AM

For the database I will use MySQL and SQLAlchemy, and Twisted for the network. If you know any interesting library which can help me doing this thing, tell me please. That is, if you don't mind it.


The philosophy of Python's standard libraries is "batteries included", so pretty much everything you'll need exists in the standard lib (apart from things like Twisted and SQLAlchemy). So it depends on what you want to do. Google is your friend in this case. If you want to do some particular thing in your code, just search "python <particular thing>". This will tell you pretty quickly if there is a package in the standard lib to help you with this.


It would be pointless to suggest particular libraries with knowing exactly what you're building. However, being rather passionate about Python, I will suggest a few other subjects for further reading:

  1. Python style guide (PEP8) - http://www.python.org/dev/peps/pep-0008/  <--- read this twice
  2. pep8 tool (for automatically checking if your code meets style guidelines) - https://pypi.python.org/pypi/pep8
  3. Learn about unit testing and write tests for your code - http://docs.python.org/2/library/unittest.html
  4. From a command prompt, type this: python -c "import this". Read.

#5056665 Understanding PyMMO

Posted by on 25 April 2013 - 09:20 AM

Wait. Maybe I get it wrong, but you said alternative. Does that mean I can avoid 'eval'? I thought the instruction map is just a way to make sure that the sent instruction is available and valid. The client sends the instruction in string, and if the instruction is in the map, it uses 'eval' to execute it. Do I get it wrong or I just misunderstand the word 'alternative'?


You don't need `eval` to execute it.


def move_character(char_id, vector):
    # TODO:

def kill_character(char_id):
    # TODO:

command_map = {
    'move_character': move_character,
    'kill_character': kill_character,

# sent from client; some string
command_name = 'move_character'
# also sent from client; a tuple or list, for example, which can be empty
# if the command doesn't take any arguments
command_args = (15, <whatever vector is>)

command_func = command_map.get(command_name)
if command_func is not None:
    # Do something else if the command is invalid


To understand the * sytanx, read http://docs.python.org/2/tutorial/controlflow.html#more-on-defining-functions, specifically http://docs.python.org/2/tutorial/controlflow.html#arbitrary-argument-lists and http://docs.python.org/2/tutorial/controlflow.html#unpacking-argument-lists.

#5056644 Understanding PyMMO

Posted by on 25 April 2013 - 08:15 AM

Oh, yes. It's eval. I forgot about their difference.
About the command_map, I actually have been thinking about that before. Using dictionary and check if the thing is in the dictionary. So, my assumption is right? The type of data sent between client and server is the instruction and the arguments needed? I have never coded any server stuff before, and I couldn't find such information in the Internet. I just used my own logic, which is questionable.

Yes, pretty much. You need to figure out a clean way to pack 1) the instruction name and 2) the arguments on the client side, and a way to unpack them properly on the server side. A simple way to do this would be to encode this in JSON; that may not be terribly efficient, but it's a simple place to start. Python has standard libs for encoding and decoding JSON: http://docs.python.org/2/library/json.html.



Can you please explain a little more about the reason why I must be careful while using eval? I feel like it's rather risky, but I'm not sure why. I guess I'm just paranoid.
P.S. I just read an article about being careful with eval, but I don't really understand the namespace thingy.


Two words: "code injection". http://en.wikipedia.org/wiki/Code_injection


If you use `eval` to execute an arbitrary instruction, it is possible that a client could, for example, send the instruction name '__import__("sys").exit()' as a string, which would crash the server process once `eval` executes it. If the server process is being run as superuser (which it shouldn't be), technically this security hole could result in the server box getting completely 0wnz3d. If you're using an `eval` in a program which runs in isolation on a single machine and never hits the network, probably you don't need to care. But once you open the program up to a network and, more importantly, provide a server interface _directly_ to an `eval`, you do need to be careful.


Regardless of the security risks, there are almost always better alternatives to `eval`. In your case, using an explicitly defined map of instructions is one of those alternatives.


`eval` for Python is kind of like `goto` for C: Just because you CAN use it doesn't necessarily mean you SHOULD. =P

#5056583 Understanding PyMMO

Posted by on 25 April 2013 - 01:33 AM

Well, I have a small question about this. Since this question is too... simple, I don't think making a new thread is a good idea, so here we go.


Like I said, I'm new to network programming (I learn programming from the internet. I even haven't been in college). My question is simple. What kind of information does the client send to the server, and vice versa?


My current opinion is it's something like "the character moves. The character id is x, and it moves to [insert the movement vector here]." Is my assumption correct? My idea is to send a string which is the name of an available function in the server, along with the arguments needed. For example, here the command is move, so it will call move(char_id, vector) with Python exec(). Is it correct? Or is there a better way (I'm sure there is)?


Also, what things I should pay attention at while doing this? Is using exec() bad? Do you have any advice for doing this?


Thank you again. Sorry if this sounds too newbie, but well... I am. laugh.png

I think you're mistaking `exec` for `eval`. And yes, you should be very careful using `eval`. Probably a better idea is creating a map of valid commands. Something like this:


def move_character(char_id, vector):
    # TODO:

def kill_character(char_id):
    # TODO:

command_map = {
  'move_character': move_character,
  'kill_character': kill_character,


So if the command sent the server is not one of the registered commands in `command_map`, you ignore it. This is a simple way you can start defining (and enforcing) the contract between client and server.

Try something simple like this and build on it as necessary.

#5056036 Understanding PyMMO

Posted by on 23 April 2013 - 07:47 AM

Do you have any other tips to understand people's code? I'm going to use Twisted for the network. Just trying.


Yep. One thing you can do is write tests for it, if it's not already tested. This way, you have a concrete method of exercising the code and to test if your assumptions about the code are correct.


Another thing you can do is to re-write parts of the code, meaning, copy it exactly by typing out each character. This is not the same as copy/paste. Copying the code by writing will give you a "muscle memory" for the code and you will notice subtle things as you are copying it that you wouldn't normally notice when you are just reading.


Last but not least, actually write some code of your own. Figure out what you want to build and see if you can use or modify the code to suit your needs.


By the way, if I find something I can't understand, can I ask you here?


Of course you can post questions to the forum. If you have a specific question, it's probably best to create a new post (and link back to this one for reference).

#5055985 Understanding PyMMO

Posted by on 23 April 2013 - 04:39 AM

I think you're going to get much more from people on this forum if you ask for help to understand a very specific piece of code. I doubt anyone is going to want to dig into someone else's code and comment it for you.


I've got a better idea: Why not try to comment it yourself? Take a copy of the code and read through it, but don't just read it like a book from start to finish. Get your self whiteboard or a big blank piece of paper and make notes and sketches about the various components of the code. For example, you can start by making a list of the source files:


- client.py

- encoding.py

- mkuser.py

- player.py

- server.py

- world.py


Next, open each file and take note of what it contains. Does it import anything? Make a note of that. What classes does it contain? What functions does it contain? Don't look at the code in too much detail, just look for names. If the code is written well, the names should give you good conceptual ideas.


Also look for `main` functions or a `if __name__ == "__main__"` block in the code, or something like that. Find the "entry point" of the client and server (see the README.txt). From the entry point, read through the first few steps of what it is doing. What kind of functions is it calling? What kind of objects is it creating? What are the relationships of those objects?


Once you think understand the conceptual idea about a piece of code (a class, a function, etc.), add some comments. Even if you're wrong, just add comments about what you THINK the code is doing. Correct them later if you need to. Comments can even be questions, like "# why is this necessary?".


Have you run the code? If not, do it. Try the different examples in the README. Become a "power user" first. Then, start thinking about what feature you might add. Make it something small. Try to build it, and ask questions if you need help.


I hope that helps. =)

#5052467 Simple MORPG project planning

Posted by on 12 April 2013 - 09:21 AM

Oh, slightly off topic. Learn to use a version control system, if you haven't already. This is necessary even for solo projects, in my opinion, and absolutely critical for a team.

If you already are, great! And sorry for the assumption. If not, git and svn are good choices. I prefer git for several reasons, but I will stop now before initiating a tool choice holy war.

#5052416 Simple MORPG project planning

Posted by on 12 April 2013 - 06:59 AM

Python is a slow language, so, unless you are using an engine that provides you with binds and code written in c/c++, the project won't scale really well. You can use an optimizer to improve your performance (cython and pypy are good places to look at).
Python network layer to send variables that are not string is pretty annoying, so you probably want to take some time to read a little about it. I would recommend you take a look at this: http://docs.python.org/2/library/struct.html


Say that Python is 'slow' a broad generalization which is not useful. Scalability of a system is not simply a matter of language choice; it's more often a matter of design. It also depends on what your definition of "scale" is.


The client programmer decided to use C# to code the program. The Python is used only in the server. Therefore, I think the performance issue won't be so big right? Or it will? I heard it will be fine as long as I run it in its realm. Sorry, I don't really understand why Python is a slow language. Is there a way to optimize it? I know it's something about the compiler and the way Python runs.


Python should be just fine for your server. Python is technically slower than a compiled language because there is additional execution overhead in the Python interpreter. But don't worry about that. It's fast enough for many things.


Also, don't worry about optimization until you have _actually_ profiled your code and have identified _real_ bottlenecks. Read that last sentence again. Resist the temptation to guess about where bottlenecks exist in the present or future, and instead learn to use a profiler. See http://docs.python.org/2/library/profile.html. Often bottlenecks you find are caused by redundant computation or a poor choice of data structures or algorithms; these issues have nothing to do with your language choice. As a last resort, if you *really* need blazing speed for number crunching, etc. (_after_ you've profiled your code), you can always write C extensions to optimize those keys pieces.


If you're dealing with a database, you may find that some bottlenecks are caused by the database (inefficient queries, latency, etc.). These sort of issues also have nothing to do with your language choice.


So if you're already familiar with Python, stick with it. It's a fine choice. =)

#5025067 I need help

Posted by on 24 January 2013 - 05:44 AM

How do you develop 2d jumping like the kind found in megaman, or Mario. I know you have to control y velocity I have gotten that far I even have my character jumping but he never caps his jump if I leave the jumping button pressed he will jump forever any help would be greatly appreciated and thank you in advance ps I'm using slick2d with Java

Have you modelled gravity into your game yet? If not, I would do that first. Place the character up in the air somewhere and apply gravitational forces to pull your character down. (By the way, you can apply this downward force all the time--which is physically realistic anyway.) You'll also need to implement basic collision detection and response between the character and a platform.

So with these components you have:
- character is up in the air
- gravity pulls it down
- platforms "catch" the character so it doesn't fall forever

With these in place, implementing jumping is simply a matter of giving the character an initial upward velocity when the key is pressed. The opposition of gravity will gradually decelerate the character, it will stop moving at the peak of the jump, and beginning falling. If implemented correctly, you should get a nice, smooth, parabolic jump. That's it in a nutshell, but there are some cases you need to account for. As Cornstalks said, you need to make sure you're already on the ground before you can jump. Also, you need all around collision response to handle, for example, what happens when the character jumps and hit its head on a platform above.

Hopefully that helps.