Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


thok

Member Since 23 Dec 2011
Offline Last Active Oct 22 2014 03:19 AM

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

Posted by thok 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 thok 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 thok 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.).

 

ABOUT LICENSING:

 

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 thok 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 thok 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:
    pass

def kill_character(char_id):
    # TODO:
    pass

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:
    command_func(*command_args)
else:
    # 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 thok 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 thok 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:
    pass

def kill_character(char_id):
    # TODO:
    pass

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 thok 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 thok 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 thok 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 thok 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 thok 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.


#4994696 HELP!

Posted by thok on 28 October 2012 - 07:30 AM

I downloaded jdk 7 but I am unsure how to open it. Any advice?


You don't "open" the JDK. JDK (Java Development Kit) is just a collection of programs and library code that allow you to compile Java applications. What you need now is an editor or and IDE. Go download Eclipse and go google search for "java hello world in eclipse". This should help you get started.


#4986693 Goto: How should I work the code out?

Posted by thok on 04 October 2012 - 02:47 AM

Here's a Java pseudo-code I'm working on shown below:

[source lang="java"]public void someFunction(//Some parameters) {//some boolean flags here.switch (p.orientation) { case VERTICAL: if (booleanFlag1){ if (booleanFlag2){ //Some other codes. goto Label; } //Some codes } else if (booleanFlag3){ if (booleanFlag4){ //Some other codes. } //Some codes } reflectResponse(); break; default: return;}Label://Some more codes... (required)}[/source]

I'm very tempted to use "goto" in Java, but as always, goto isn't allowed because of said issue. I will digress from that.

I only know from Java doc here that said "break" keyword works for for...loop, do...while..., and switch...case... only. Anything I can do?

  • You cannot use goto in Java.
  • If you want to execute some code _only_ in the VERTICAL case when booleanFlag1 and booleanFlag2 are both true, don't do it this way. This is what you're trying to do, right? Instead, put this code in a separate function or method and call it inside the second `if` clause.



#4985870 Hardware/Software Limits?!?!?

Posted by thok on 01 October 2012 - 03:07 PM

Linux isn't going to help you, especially on a _low-end_ machine. If you want to run modern software, you need a modern machine.




PARTNERS