Users browsing this thread:
Python programming
#1
i don't know if i'm making much sense but here goes

I've recently read more and more on Python (3) and I really like it.
So far I've only done stuff one might consider 'simple' and my input/output consists of text only - and by text I mean inputting text that gets transformed into numbers; integers or floats, or strings, lists or other types. Manipulating these makes for a great exercise in data manipulation but ultimately I'm stuck with text and text only with everything happening in the Terminal.
My endgame is displaying and manipulating real binary files. Instead of inputting text to terminal and dicking around with whatever I can make out of that data, I want to use the same tricks but for inputting real files, reading them as hex or binary values and displaying real graphics, and by graphics I don't mean PNG images or stuff like that, but graphics where I explicitly tell how the graphics should be formed, 1D tiles, RGBA, 4bpp, RLE - you know, explaining how the format works to a computer.

There obviously isn't a Python library/framework/module/whatever explicitly for ROM hacking or Sprite-related things and right now I'm looking into pyglet. I just want to know if I'm shooting myself in the ass.
What are some programming paradigms and what's good practice when dealing with binaries?
Once there was a way to get back homeward
Reply
Thanked by:
#2
Just a warning; I don't hate Python, but you could say it's not my cup of tea. I have used it and know it to a decent extent but it's generally not my language of choice. I'll still try and help though.
I don't know how one goes about making graphical stuff in Python, but I personally see it as more of a language for scripts rather than programs. I'm not saying it's a terrible choice but it might just not be a great one. That said pyglet looks pretty sweet so I could be completely wrong.

In general, I don't know of any particular paradigm or conventions when messing with binary data. Personally I just kinda open the files and read what I need to when I need to.
What I do suggest for programming anything, is to try separate stuff out into multiple functions/methods. For example say you have about 20 lines of code that I dunno, save an image object into a PNG file. That would be convenient to have in a function which you can then call from various places. You just call "saveImage", passing in the image and the output file name, and it'll handle the rest. You can separate the specifics of that task from your application's overall logic.

Apart from that I would just say take it slow. Hack stuff out, you can make ugly code as long as you know it's ugly, and then once you're comfortable with the library and understand how things work, you can try clean it up and make it more manageable. You're gonna have to experiment for a while before you know your way around reading/writing and working with binary stuff with your code (and displaying images with it) and can start make a proper program.

That's all I can think of at the moment. I love it when people give coding a go though, I would like to help where I can so don't feel afraid to ask for it. As I said Python isn't my forte though so I'm not sure how helpful I can be with language-specific questions.
You may have a fresh start any moment you choose, for this thing that we call "failure" is not the falling down, but the staying down. -Mary Pickford
Reply
Thanked by: Raccoon Sam
#3
If you're using Python for image loading and manipulation, PIL/Pillow/Image is the best library for that. You can see an example of me using it here. In that instance, I loaded a 32bpp image and color-reduced it down to 15bpp. The basic process involves loading an image as a texture, converting that to a pixel array, working on the individual pixels then saving it back as an image.

After a quick search, it seems that it also supports binaries as images. You can install Pillow by typing "pip install pillow" into your console.

After that, pyglet would probably be your best bet. I've never used it but I imagine it has as much functionality as other OpenGL libraries. It has basic support for pixel access so you have that going for you, at least.

As far as programming paradigms go, I haven't heard of any as far as binary files go. Always backup everything, I guess? Kinda goes without saying.
Reply
Thanked by: Raccoon Sam
#4
DragonDePlatino - your example seems more straightforward. Speed isn't the top priority so I don't think it makes much difference how I render the final product, using OpenGL or however PIL renders that stuff. The Stack Overflow link is extremely helpful so thank you for that too.
puggsoy - thank you for the tip. I usually write some kind of a plan on paper with a pencil and then start defining my functions. It's easier to write a rough draft of what I want and then start making it prettier step by step.
Although not strictly related to the subject, what languages do you personally find the most comfortable to program in? I really really like Python but learning new things is always good.

but hey Thank you both.
Once there was a way to get back homeward
Reply
Thanked by:
#5
Glad to hear you got some use out of that!

Personally, I like programming in Python and C. Python for small one-off scripts and C for hobby game development. Java is a really nice language, but too wordy for small things and too slow for making games. I used to program games in C++ but got sick of how complex and messy the language is.
Reply
Thanked by:
#6
(10-31-2016, 08:18 AM)Raccoon Sam Wrote: Although not strictly related to the subject, what languages do you personally find the most comfortable to program in? I really really like Python but learning new things is always good.

Personally I love Haxe, it's lets me do most things I want to with relative ease, mostly because I just have a lot of experience with it and know my way around it well. It's not quite as simple as Python and requires some extra boilerplate stuff sometimes, but it is quite powerful and lets me do what I want. It's also just a really cool language that might be good to look into later on if you feel like branching out.
Like Platino said Java is also really nice, at my university it's used as the main language for software courses, including introductory ones. It's not very low-level but it still teaches you a lot of things that are relevant in general programming. It's a really good language to start out with, once you know it you can learn most other languages relatively easily.

(10-31-2016, 08:55 AM)DragonDePlatino Wrote: I used to program games in C++ but got sick of how complex and messy the language is.

Now I only know C (and don't have too much experience yet) but isn't C++ just C with classes (and some other small changes)? Which I assume would be useful for games? To my knowledge game development is usually easier and makes more sense with an object-oriented design. I understand that's it's way more complex than C but in that case maybe a higher-level language is better suited. Nowadays, making games in C/C++ is usually only worth it if you need some low-level hardware or memory control for optimization purposes.
That said C is still an awesome language (obviously) and I'm not trying to convince you to switching to something else, I'm just curious as to the choice.
You may have a fresh start any moment you choose, for this thing that we call "failure" is not the falling down, but the staying down. -Mary Pickford
Reply
Thanked by:
#7
The issue I have with C++ is that it's *not* just C with classes. There's lambdas, templates, variadic functions, static casting, friend classes, namespaces and AAARGH! When programming in C++, I spend more time worrying about OOP instead of making a game. I ask myself questions like "should this be in a static class, global variable or namespace?" instead of "how much health should this enemy have?"

With that being said, I only program in C because I enjoy it more than C++. I fully understand that C is antiquated by modern standards and C++ is the most popular gamedev language for a reason.

As for Java, I agree that it's a great introductory language. It is much better for OOP and is almost exclusively used in mobile gamedev. Raccoon Sam, if you ever outgrow Python then Java is a good second language to learn.
Reply
Thanked by:


Forum Jump: