It was until C++11 - C++11 was a big overhaul that added a lot of useful features.
Many of C++'s flaws are stuff itâs inherited from C.
const
applies to types, not functions, so itâs a bit more nuanced than that.
const
should be thought of as meaning âread onlyâ and should be used with read-only data, but constexpr
should be used instead of const
when possible.
(Note: C++ literature doesnât tend to use the word âmethodâ, it prefers âfunctionâ. Particularly terms like âmember functionâ and ânon-member functionâ/âfree functionâ.)
The C++ standard library uses lowercase and underscores,
but Arduino code tends to use Pascal case for types and camel case for functions/objects*,
so for Arduboy games you should probably stick to the Arduino style so your code is more consistent.
(* Note: In C++, anything that occupies memory is an object and not all objects have member functions, hence itâs âeverythingâs an objectâ, but in a different and more efficient way to Javaâs idea of âeverythingâs an objectâ.)
You technically can, but itâs considered bad form.
The comma operator is rarely used and not widely understood so it generally harms readability.
(Also not all uses of a comma are instances of the comma operator which muddies the waters.)
A slightly less important but still valid reason is that the comma operator forces the left hand side of the expression to be sequenced before the right hand side which can interfere with the compilerâs ability to optimise by removing some of the flexibility it has to reorder operations.
I also learnt C# before C++ so I know what you mean.
The biggest leap is in dealing with pointers and having to be in charge of managing your own memory instead of relying on a GC.
Suddenly you actually have to understand how RAM works. :P
Iâm not sure what youâre asking/saying.
Itâs more the case that most of the more modern languages are targeting x86 computers so 32-bit and 64-bit have become the norm.
C++ was made back in the days where 16-bit computers were the norm and some CPUs uses word sizes that werenât a multiple of 8.
(Although technically it inherited its int
rules from C, which goes back further.)
As @filmote pointed out, most games just draw every single loop
iteration.
In your case youâd need to move both the print
and the display
calls out of the if
and into the loop so itâs always drawing.
There actually are badges on the forum, but only @bateske can make them.
(My favourite badge is empathetic.)
The platformio.ini
is a big give away. :P
I also use VS Code (well, technically VS Codium, but same difference) but I use the Arduino plugin instead of PlatformIO because it behaves the same way the Arduino IDE would.
Itâs not the casing itself thatâs important, itâs that the name of the .ino
file has to match the folder name.
Windows uses a case-insensitive file system, but Linux has a case-sensitive file system so itâs likely that the folder name and file name have to match exactly in regard to letter case.
I.e. if you want to make a file called bouncetext.ino
then go ahead, but make sure itâs in a folder called bouncetext
rather than BounceText
(or vice-versa).
Thatâs going to take quite a bit of explaining and demonstration so Iâll come back to it, lest this comment grow any larger.
I looked at how youâve updated your code on GitHubâŚ
It wonât compile because this isnât legal:
uint8_t 0;
After removing those two lines it all compiles.
Most likely you forgot to move setCursor
as well.
I tried not moving that and it does indeed cause flickering.
Doing this works:
void loop() {
if (!arduboy.nextFrame()) {
return;
}
arduboy.pollButtons();
if (arduboy.justPressed(UP_BUTTON)) {
if (speed > 1) {
--speed;
}
}
if (arduboy.justPressed(DOWN_BUTTON)) {
++speed;
}
if (arduboy.justPressed(A_BUTTON)) {
speed = 10;
}
if (arduboy.justPressed(B_BUTTON)) {
paused = !paused;
}
if (arduboy.everyXFrames(speed)) {
if (!paused) {
nextPosition();
}
}
arduboy.clear();
arduboy.setCursor(x_current, y_current);
arduboy.print(title);
arduboy.display();
}
As does:
void loop() {
if (!arduboy.nextFrame()) {
return;
}
arduboy.pollButtons();
if (arduboy.justPressed(UP_BUTTON)) {
if (speed > 1) {
--speed;
}
}
if (arduboy.justPressed(DOWN_BUTTON)) {
++speed;
}
if (arduboy.justPressed(A_BUTTON)) {
speed = 10;
}
if (arduboy.justPressed(B_BUTTON)) {
paused = !paused;
}
if (arduboy.everyXFrames(speed)) {
if (!paused) {
nextPosition();
}
}
arduboy.setCursor(x_current, y_current);
arduboy.print(title);
arduboy.display(CLEAR_BUFFER);
}