Hello everyone,
I’m new to the Picosystem, C++ and OOP – so what could go wrong? I want to create 2 alien sprites and display them on the screen using a class and objects. I’ve copied an example from this website C++ Classes and Objects and modified it but when I try to compile I get the errors below. I’ve looked at some other examples and noticed they put a forward declaration in but that hasn’t worked either.
Thanks for any help,
Leaf-frog
Compilation error ----------->
/home/leaffrog/ourproject/main.cpp:19:1: error: ‘space_alien1’ does not name a type
19 | space_alien1.x = 8;
| ^~~~~~~~~~~~
/home/leaffrog/ourproject/main.cpp:20:1: error: ‘space_alien1’ does not name a type
20 | space_alien1.y = 8;
| ^~~~~~~~~~~~
/home/leaffrog/ourproject/main.cpp:22:1: error: ‘space_alien2’ does not name a type
22 | space_alien2.x = 8+9;
| ^~~~~~~~~~~~
/home/leaffrog/ourproject/main.cpp:23:1: error: ‘space_alien2’ does not name a type
23 | space_alien2.y = 8;
| ^~~~~~~~~~~~
The Code ---------------->
// Forward declaration
class Alien;
#include “picosystem.hpp”
using namespace picosystem;
#define alien_sprite 89
class Alien {
public:
int x;
int y;
};
Alien space_alien1;
Alien space_alien2;
space_alien1.x = 8;
space_alien1.y = 8;
space_alien2.x = 8+9;
space_alien2.y = 8;
// ****************
// * Initialise *
// ****************
void init() {
}
// ****************
// * Update *
// ****************
void update(uint32_t tick) {
}
// ****************
// * Draw *
// ****************
void draw(uint32_t tick) {
pen(0, 0, 0);
clear();
pen(15, 15, 15);
text(“Hello, world!”, 0, 0);
sprite(alien_sprite, space_alien1.x, space_alien1.y);
sprite(alien_sprite, space_alien2.x, space_alien2.y);
}