#include <SPI.h> //import connection
#include <Gamebuino.h> //import arduino game library
Gamebuino gb; //build gamebuino object
//player variables
int player_h = 4; //height of 4x4 player
int player_w = 4; //width of 4x4 player
int player_x = (LCDWIDTH - player_w)/2; //player starting cords
int player_y = (LCDHEIGHT - player_h)/2; //player starting cords
int player_vy = 2; //???
//enemy variables
int enemy_h =6; //height of 6x6 enemy
int enemy_w =6; //width of 6x6 enemy
int enemy_x =(LCDWIDTH - enemy_w)/2; //enemy starting cords
int enemy_y =(LCDHEIGHT - enemy_h)/2; //enemy starting cords
int number_1 = 1; //mutable number is not UPPERCASE
//enemy functions
int DistanceAddX(int enemy_x,int number_1) //calls enemy cord + 1
{
int result;
result = enemy_x + number_1;
return result;
}
int DistanceRemoveX(int enemy_x,int number_1) //calls enemy cord -1
{
int result;
result = enemy_x - number_1;
return result;
}
int DistanceAddY(int enemy_y,int number_1) //calls enemy cord +1
{
int result;
result = enemy_y + number_1;
return result;
}
int DistanceRemoveY(int enemy_y,int number_1) //calls enemy cord - 1
{
int result;
result = enemy_y - number_1;
return result; //make this resultRY? change up result
}
void setup() {
// put your setup code here, to run once:
gb.begin(); //begin gamebuino
gb.titleScreen(F(“Knight’s walk”)); //title name
gb.pickRandomSeed(); //generate random seed
gb.battery.show = false; //turn off battery meter
gb.display.fontSize = 2; //font is set
}
void loop() {
// put your main code here, to run repeatedly:
if(player_x > enemy_x) //player is below enemy
{
return DistanceAddX; //is enemy on the screen?
gb.display.fillRect(enemy_x, enemy_y, enemy_w, enemy_h); //create enemy
}
else if(player_x < enemy_x)
{
return DistanceRemoveX;
gb.display.fillRect(enemy_x, enemy_y, enemy_w, enemy_h); //redraw enemy
}
if(player_y > enemy_y)
{
return DistanceAddY;
gb.display.fillRect(enemy_x, enemy_y, enemy_w, enemy_h); //redraw enemy
}
else if(player_y < enemy_y)
{
return DistanceRemoveY;
gb.display.fillRect(enemy_x, enemy_y, enemy_w, enemy_h); //redraw enemy
}
if(gb.update()){ //if? why not while?
if(gb.buttons.repeat(BTN_UP, 1)){
player_y = max(0, player_y - player_vy); //vy? variable y cord?
}
if(gb.buttons.repeat(BTN_DOWN, 1)){
player_y = min(LCDHEIGHT - player_h, player_y + player_vy);
}
if(gb.buttons.repeat(BTN_LEFT, 1)){
player_x = max(0, player_x - player_vy);
}
if(gb.buttons.repeat(BTN_RIGHT, 1)){
player_x = min(LCDWIDTH - player_w, player_x + player_vy);
}
gb.display.fillRect(player_x, player_y, player_w, player_h); //create player
}
}
I’m not sure what your player is doing. It confused me. I’m also not familiar with max and min methods.
I wouldn’t write it like this. I would make the player and enemy one function and call them from your buttons. I haven’t done anything like this before.
You should focus on one thing at a time. Build your player separate from things like your title. It should be a concept of its own. When you understand what your character is doing, then figure out what your enemy is doing. Even if it’s just animations.
I’m not sure how the seed is used on gamebuino. I’m sure it isn’t too related to the problem. Just work on this one step at a time. You’re trying to finish a game before the paint dries.