Widget101
Posts: 4
Joined: Mon Mar 23, 2015 7:08 pm

Coding Games Tutorial in MagPi Help

Sun Feb 24, 2019 5:58 pm

Hi,

I'm trying to run through the Coding Games tutorial which started in MagPi Issue 65 and would appreciate some guidance.

I seem to be falling at the first hurdle where the instructions say to download Codeblocks using 'sudo apt-get codeblocks'

I couldn't get this to work but after a google search I managed to find a command 'sudo apt-get install codeblocks' which does seem to work but doesn't give me the same IDE layout as the author shows on the page. I don't have the Sources filter which creates the main.cpp file(?) and I also don't seem to have the Debug commands which the Author references.

I'm wondering whether this is a difference between codeblocks versions and whether this series of tutorials is still usable given its a year old.

Any help would be appreciated.

Many thanks,

cmrincon
Posts: 18
Joined: Thu May 24, 2018 7:39 pm

Re: Coding Games Tutorial in MagPi Help

Tue Feb 26, 2019 9:33 am

Did you try "sudo apt-get update" before installing codeblocks?

Brian Beuken
Posts: 177
Joined: Fri Jan 29, 2016 12:51 pm

Re: Coding Games Tutorial in MagPi Help

Tue Feb 26, 2019 12:20 pm

There was indeed a typo on that issue it should have said apt-get install

As for the layout, Code::Blocks does update from time to time and things get shuffled around, don't worry to much about it not being identical to the magazine. The key things are all still there.

The concepts of C++ are always valid even if the IDE's change a little with updates, the articles will be relevant for a long time and there's support available at my website www.scratchpadgames.net on the forums if you get stuck
Very old computer game programmer, now teaching very young computer game programmers, some very bad habits.
Wrote some book about coding Pi's and SBC's, it's out now...go get it!
http://www.scratchpadgames.net/

dsyleixa123
Posts: 293
Joined: Mon Jun 11, 2018 11:22 am

Re: Coding Games Tutorial in MagPi Help

Tue Feb 26, 2019 6:41 pm

Brian Beuken wrote:
Tue Feb 26, 2019 12:20 pm
There was indeed a typo on that issue it should have said apt-get install

As for the layout, Code::Blocks does update from time to time and things get shuffled around, don't worry to much about it not being identical to the magazine. The key things are all still there.

The concepts of C++ are always valid even if the IDE's change a little with updates, the articles will be relevant for a long time and there's support available at my website www.scratchpadgames.net on the forums if you get stuck
@Brian Beuken
are you the author of the MagPi C++ game programming tutorial?

Brian Beuken
Posts: 177
Joined: Fri Jan 29, 2016 12:51 pm

Re: Coding Games Tutorial in MagPi Help

Wed Feb 27, 2019 1:00 am

yes :D
Very old computer game programmer, now teaching very young computer game programmers, some very bad habits.
Wrote some book about coding Pi's and SBC's, it's out now...go get it!
http://www.scratchpadgames.net/

dsyleixa123
Posts: 293
Joined: Mon Jun 11, 2018 11:22 am

Re: Coding Games Tutorial in MagPi Help

Wed Feb 27, 2019 11:47 am

thant's great! :)

Unfortunately the screenshots feat. the source code listings are incredibly small in the MagPi tutorial, almost unreadable. Are there source code listings as text files provided, to download or to browse for copy+paste?

Brian Beuken
Posts: 177
Joined: Fri Jan 29, 2016 12:51 pm

Re: Coding Games Tutorial in MagPi Help

Wed Feb 27, 2019 12:17 pm

All the source code is available to download from the MagPi github, you don't need to type in from the images

https://github.com/themagpimag
Very old computer game programmer, now teaching very young computer game programmers, some very bad habits.
Wrote some book about coding Pi's and SBC's, it's out now...go get it!
http://www.scratchpadgames.net/

dsyleixa123
Posts: 293
Joined: Mon Jun 11, 2018 11:22 am

Re: Coding Games Tutorial in MagPi Help

Thu Feb 28, 2019 9:28 am

Brian Beuken wrote:
Wed Feb 27, 2019 12:17 pm
All the source code is available to download from the MagPi github, you don't need to type in from the images

https://github.com/themagpimag
thank you, that information was missing when I was reading through the MagPi tutorial!

Brian Beuken
Posts: 177
Joined: Fri Jan 29, 2016 12:51 pm

Re: Coding Games Tutorial in MagPi Help

Thu Feb 28, 2019 1:33 pm

No it does say in every article that the code is availlable at the magpi git hub, its where all code for all projects can be downloaded, but if you are not aware of how git hub works it might be confusing.

Hope you're ok with it now, any problems feel free to ask here or on my support site at www.scatchpadgames.net
Very old computer game programmer, now teaching very young computer game programmers, some very bad habits.
Wrote some book about coding Pi's and SBC's, it's out now...go get it!
http://www.scratchpadgames.net/

User avatar
bensimmo
Posts: 4074
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Coding Games Tutorial in MagPi Help

Thu Feb 28, 2019 2:25 pm

Typo in the web URL so it doesn't work.
I assume this reply will be wrong shortly ;-)
First link above to the website works :-)

Many thanks for the tutorials

dsyleixa123
Posts: 293
Joined: Mon Jun 11, 2018 11:22 am

Re: Coding Games Tutorial in MagPi Help

Thu Feb 28, 2019 4:48 pm

Brian Beuken wrote:
Thu Feb 28, 2019 1:33 pm
No it does say in every article that the code is availlable at the magpi git hub, its where all code for all projects can be downloaded, but if you are not aware of how git hub works it might be confusing.
Hope you're ok with it now, any problems feel free to ask here or on my support site at www.scatchpadgames.net
I didn't see the url of the "magpi git hub" anywhere written in the MagPi article, but now it's fine of course, thank you!
( Of course I know a little bit about github repos, I have one by myself ;) )

Widget101
Posts: 4
Joined: Mon Mar 23, 2015 7:08 pm

Re: Coding Games Tutorial in MagPi Help

Thu Feb 28, 2019 7:18 pm

Thanks for the help with this guys!

I'll try the information GitHub.

And thanks Brian for giving your time and expertise to write them! Just checked out your scratchpad site and looks like lots of great stuff on there as well! :D I'm going to enjoy going through it.

dsyleixa123
Posts: 293
Joined: Mon Jun 11, 2018 11:22 am

Re: Coding Games Tutorial in MagPi Help

Fri Mar 01, 2019 9:20 am

Brian Beuken wrote:
Thu Feb 28, 2019 1:33 pm
No it does say in every article that the code is availlable at the magpi git hub, its where all code for all projects can be downloaded, but if you are not aware of how git hub works it might be confusing.

Hope you're ok with it now, any problems feel free to ask here or on my support site at www.scatchpadgames.net
Now as to vol 66 (part 2):
1st,
do I have to install a graphic lib or package (presumably openGL)? in case yes, how to?
(I am using an old Pi2 with Stretch)
(again the screenshots are incredible small by font size, and additionally blurred when enlarging the pictures, and it's hard to recognize anything important)

2nd,
As I prefer Geany over code::blocks,
so which extra -L... or I... do I have to insert to the Geany compile and build preferences?

3rd,
Into which Raspi directories do I have to copy some of the libs or .h or .c(pp) files so that it can be found by Geany, the linker, and the gcc compiler automatically for either #include <...>, not having to use then extra -L... or -I.... flags for compile and build/link any more?
( I don't use makefile, just the Geany build preferences)

Brian Beuken
Posts: 177
Joined: Fri Jan 29, 2016 12:51 pm

Re: Coding Games Tutorial in MagPi Help

Fri Mar 01, 2019 2:20 pm

dsyleixa123 wrote:
Fri Mar 01, 2019 9:20 am

Now as to vol 66 (part 2):
1st,
do I have to install a graphic lib or package (presumably openGL)? in case yes, how to?
(I am using an old Pi2 with Stretch)
(again the screenshots are incredible small by font size, and additionally blurred when enlarging the pictures, and it's hard to recognize anything important)

2nd,
As I prefer Geany over code::blocks,
so which extra -L... or I... do I have to insert to the Geany compile and build preferences?

3rd,
Into which Raspi directories do I have to copy some of the libs or .h or .c(pp) files so that it can be found by Geany, the linker, and the gcc compiler automatically for either #include <...>, not having to use then extra -L... or -I.... flags for compile and build/link any more?
( I don't use makefile, just the Geany build preferences)
Sadly I have no control over the printed size of the screen shots, they are there mainly as guides but should be zoom-able on the downloaded version?
Feel free to ask here or for a quicker response on my forums, if you get stuck with anything.

1 ok 1st.. no, OpenGLES2.0 is part of your Rasbian set up, even the older ones are fine, I've had demo's running on an original Pi A with no issues, apart from speed.
One thing to be aware of is that you might have your raspberry set up to use the semi emulated OpenGL, rather than pure OpenGLES2.0 check this by going into a terminal and entering
sudo raspi-config
Go to advanced Options then GL Driver and select Legacy, which disables the OpenGL drivers in favour of OpenGLES2.0


2 I'm sorry I've never used Geany, so don't know exactly how to set it up, I'm sure someone else can help with that.

3 The libs themselves are found in specific directories in Raspbian and are supplied in the Code::Blocks demos.I've not used Geany before so I assume the set up needs you to add the dirs yourself,
The include dirs are
/opt/vc/include
/opt/vc/include/interface/vcos/pthreads
/opt/vc/include/interface
/opt/vc/include/interface/vmcs_host/linux

the binary/lib dir is
/opt/vc/lib/

and the libnames on stretch are
GLESv2_static
EGL_static
vchiq_arm
vcos
khrn_static
bcm_host
pthread
Very old computer game programmer, now teaching very young computer game programmers, some very bad habits.
Wrote some book about coding Pi's and SBC's, it's out now...go get it!
http://www.scratchpadgames.net/

dsyleixa123
Posts: 293
Joined: Mon Jun 11, 2018 11:22 am

Re: Coding Games Tutorial in MagPi Help

Fri Mar 01, 2019 5:01 pm

thanks for your reply!
about the screenshots and zooming:
if not zoomed, the fonts are too small to recogize what's written, and when zoomed-in, it's all totaly blurred, so again nothing to recognize.

about compile + build flags i probably was not clear in my question -
these are my current settings:

Code: Select all

Geany settings for compile: 
g++ -Wall -pthread  -I/opt/vc/include  -lshapes  -c "%f"  -lwiringPi 
 (I use the -l flags even if they are redundant for compile)

Geany settings for make/build:
g++ -Wall -pthread -I/opt/vc/include  -lshapes  -o "%e" "%f"  -lwiringPi  

what do I have to add to make your examples work with all the libs and headers your programs need?

Brian Beuken
Posts: 177
Joined: Fri Jan 29, 2016 12:51 pm

Re: Coding Games Tutorial in MagPi Help

Fri Mar 01, 2019 7:16 pm

hmm I'm quite pleased I don't use Geany it looks like a lot of effort to build a project

I listed the libs names and include directories in the previous reply, it looks like you'll have to enter them the same way you are doing pthreads.
Very old computer game programmer, now teaching very young computer game programmers, some very bad habits.
Wrote some book about coding Pi's and SBC's, it's out now...go get it!
http://www.scratchpadgames.net/

dsyleixa123
Posts: 293
Joined: Mon Jun 11, 2018 11:22 am

Re: Coding Games Tutorial in MagPi Help

Fri Mar 01, 2019 8:06 pm

Brian Beuken wrote:
Fri Mar 01, 2019 7:16 pm
hmm I'm quite pleased I don't use Geany it looks like a lot of effort to build a project

I listed the libs names and include directories in the previous reply, it looks like you'll have to enter them the same way you are doing pthreads.
Unfortunately I am unable to cope with this task, as I don't know enough about OpenGL files and nothing at all about code::blocks; OTOH it's too hard to follow the tutorial on my Pi screen (and not even on my Windows notebook) because the screenshots are not readable to me.
For Borland Pascal, Delphi, and C++ Builder I never had to use makefiles or -I... or -L...., so I am afraid I'll have to resign for C++ on the Pi.

Brian Beuken
Posts: 177
Joined: Fri Jan 29, 2016 12:51 pm

Re: Coding Games Tutorial in MagPi Help

Fri Mar 01, 2019 9:50 pm

Sorry I can't help more, as I say Geany isn't an IDE I use, its a bit too primitive. The articles were written for Code::Blocks which really is pretty straight foward, and you can load the projects and build and run them. If you must work with Geany, you can maybe review the way Code::Blocks includes the libraries and accesses them via the include and binary directories.

Don't give up, its only the first hurdle, and you're making it harder for yourself by refusing to use the samples that are supplied.
Very old computer game programmer, now teaching very young computer game programmers, some very bad habits.
Wrote some book about coding Pi's and SBC's, it's out now...go get it!
http://www.scratchpadgames.net/

dsyleixa123
Posts: 293
Joined: Mon Jun 11, 2018 11:22 am

Re: Coding Games Tutorial in MagPi Help

Sat Mar 02, 2019 8:59 am

thanks for your wishes, but I can only work with simple IDEs like Geany or the Arduino IDE. Codeblocks has far too many confusing options, windows, settings, sidebars, preferences which I do not understand (and above all, not even can recognize) , I would need an elaborated codeblocks tutorial before being able to use that and then big images and code to c+p to work with, like in Adafruit or Sparkfun Arduino tutorials. Also openGL looks incredible overcomplicated and inconvenient to use, the Adafruit Arduino graphic libs and even openVG for the Pi are waaayy easier.
So the C++ game programming is IMO more for advanced C++ users on the Pi and unfortunately not suitable for beginners like me. Nonetheless I wish the rest of the participants much success!

Brian Beuken
Posts: 177
Joined: Fri Jan 29, 2016 12:51 pm

Re: Coding Games Tutorial in MagPi Help

Sat Mar 02, 2019 3:36 pm

If I get some time I'll try to port the demos to Geany, but at the moment I'm snowed under with work, so maybe someone else could do that?

I can't stress enough though, that using the right tools makes the task much easier, Geany from my 1st look at it, isn't a project base IDE, its a file editor, designed to work on individual files. I'm sure it can be made to work on a project but really, its making your life (clearly) more complex than Code::Blocks does.

Code::Blocks can look daunting at 1st, but the core concepts are pretty universal to IDE's and not too hard to master when you take small steps, as I tried to do in the tuts. I will put up a small tut on Code::Blocks sometime soon on my website. Though its not my favourite means of coding. If you have a PC, its much easier to hook your Raspberry to it via a network cable and use Visual Studio, and VisualGDB... My book covers how to do that in some detail.

OpenGLES, indeed is complex, it requires an understanding of maths, rendering, world and view co-ordinates, hardware and more, but again, small steps. Anyone can learn these things by making small steps, working through mistakes and taking pride in getting the 1st things on screen. Understanding comes from building on errors, and failure leading to success.

It takes time, so I hope you will come back to it again and move from beginner to, where I am, which is ...almost understanding what I'm doing! Almost. :D :D
Very old computer game programmer, now teaching very young computer game programmers, some very bad habits.
Wrote some book about coding Pi's and SBC's, it's out now...go get it!
http://www.scratchpadgames.net/

dsyleixa123
Posts: 293
Joined: Mon Jun 11, 2018 11:22 am

Re: Coding Games Tutorial in MagPi Help

Sat Mar 02, 2019 5:23 pm

yes, indeed, I admit: single-file programs are all I am used to, anything else is far too confusing (except for some extra #included .h or .c files). Who actually needs more than that, and what for? Just do all the program coding in the program file which has the main() function ;)
But if once a Geany version will exist, I'll gladly have a look at it, thanks a lot! 8-)

jahboater
Posts: 4474
Joined: Wed Feb 04, 2015 6:38 pm

Re: Coding Games Tutorial in MagPi Help

Sat Mar 02, 2019 6:17 pm

dsyleixa123 wrote:
Sat Mar 02, 2019 5:23 pm
Who actually needs more than that, and what for?
When you type "cc" or "gcc" on the Pi, you start the compiler, which is just a program like yours.
:) its source tree has at least 1,764,372 source files (.c .h .s and .cpp) :)
and 8061 makefiles ...

dsyleixa123
Posts: 293
Joined: Mon Jun 11, 2018 11:22 am

Re: Coding Games Tutorial in MagPi Help

Sat Mar 02, 2019 6:29 pm

just put it all in 1.
or perhaps 2.
no makefile though ;)

Brian Beuken
Posts: 177
Joined: Fri Jan 29, 2016 12:51 pm

Re: Coding Games Tutorial in MagPi Help

Sat Mar 02, 2019 6:58 pm

:D C++ and other OOP languages work on the principles of collections of objects, called classes, which themselves make use of other classes, each is defined in its own file, the more classes you have the more files you have. Each class needs an h file and a CPP file to be viable in normal usage.

Asking to put it all into 1 file is kinda missing the point of what C++ does and can do for you.

But a good IDE like Code::Blocks or Visual Studio, lets you keep track of all these classes and edit and compile them as one project to produce the executable.

Dont hang on to an old coding method that really won't work for C++.
Games are big, really big, I've kept the numbers of classes to a minimum in the tutorials but you do need to define a lot to get even basic usage...Once a class is defined, you can leave it, and trust it to be there when you need it.

The days of single file programs, for things like games, are long gone.
Very old computer game programmer, now teaching very young computer game programmers, some very bad habits.
Wrote some book about coding Pi's and SBC's, it's out now...go get it!
http://www.scratchpadgames.net/

dsyleixa123
Posts: 293
Joined: Mon Jun 11, 2018 11:22 am

Re: Coding Games Tutorial in MagPi Help

Sun Mar 03, 2019 8:54 am

yes, as to just 1 file at all of course I just was kidding.
I actually referred to your statement that Geany perhaps cannot handle multiple file projects.
As to .h and .cpp files for object classes it's also obvious, like for Arduino which is legal C++ (using classes for Serial, Wire, TFTs, sensors,...) :
nonetheless, even if the main program (feat the main() function) is #including perhaps dozens of "libraries" for a ton of objects, the main program is still just 1 file, so I have to handle just 1 file for my project (e.g., by Geany). When there was a need to change a class source code, I can open , change, and save that in a 2nd editor tab intermediately, and then proceed with the main file source code, and compile (F8), build (F9), and run it (F5), no need for makefiles.

Return to “C/C++”