Duhjoker
Well-known member
I got it working properly. I went ahead and just made 4 new if functions using the extra parenthesis example posted earlier in the thread and transcribed it to the other three movements. I made progress by adding last x and last y in the loop past the last movement if. left started repeating along with down and right. I looked a little closer and saw the move repeat integers were off. The pwm 400's need to be set to 2 and the 600's set to one and all is working.
Thank you by the way!! You taught me new piece of programming!!!!
Code:
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
int y = ss1.analogRead(2);
int x = ss1.analogRead(3);
#define MoveRepeatRate 100 // set this for how long in milis to wait for auto repeat move
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if ( (x > 600) && ( (last_x < 600) || ( 1 == player.player_directionRepeat && MoveRepeat >= MoveRepeatRate ) ) ) {
Serial.println(F("UP")); ///RIGHT
MoveRepeat = 0;
player.player_directionRepeat = 1;
tft.writeRectNBPP(player.player_x, player.player_y, 16, 16, 4, paulrearwa, palette); //// this mixed with the call below it calls bitmaps for walking
tft.writeRectNBPP(player.player_x, player.player_y, 16, 16, 4, paulrearwb, palette); ///// read above
player.player_direction = 1; ////when movement ends player bitmap faces this direction paul rear
player.player_y -= 4; ///move player y - 4 pixels
if (checkcolision())
{
player.player_y += 4; ///causes player to stop when collision happens
player.player_directionRepeat = 0;
}
last_x = x; ////added this
last_y = y; ////added this
}
if (player.player_y <= 16) { ////keeps player from walking off the screen.
player.player_y = 16;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
if ( (x < 400) && ( (last_x > 400) || ( 2 == player.player_directionRepeat && MoveRepeat >= MoveRepeatRate ) ) ) {
Serial.println(F("DOWN")); ///LEFT
MoveRepeat = 0;
player.player_directionRepeat = 2;
tft.writeRectNBPP(player.player_x, player.player_y, 16, 16, 4, paulfrontwa, palette);
tft.writeRectNBPP(player.player_x, player.player_y, 16, 16, 4, paulfrontwb, palette);
player.player_direction = 2; ////when movement ends player bitmap faces this direction paul rear
player.player_y += 4; ///move player y - 4 pixels
if (checkcolision())
{
player.player_y -= 4;
player.player_directionRepeat = 0;
}
last_x = x; ////added this
last_y = y; ////added this
}
if (player.player_y >= 224) {
player.player_y = 224;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
if ( (y < 400) && ( (last_y > 400) || ( 2 == player.player_directionRepeat && MoveRepeat >= MoveRepeatRate ) ) ) {
Serial.println(F("LEFT")); ///DOWN
MoveRepeat = 0;
player.player_directionRepeat = 2;
tft.writeRectNBPP(player.player_x, player.player_y, 16, 16, 4, paulleftw, palette);
tft.writeRectNBPP(player.player_x, player.player_y, 16, 16, 4, paulleft, palette);
player.player_direction = 3;
player.player_x -= 4;
if (checkcolision())
{
player.player_x += 4;
player.player_directionRepeat = 0;
}
last_x = x; ////added this
last_y = y; ////added this
}
if (player.player_x >= 304) {
player.player_x = 304;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
if ( (y > 600) && ( (last_y < 600) || ( 1 == player.player_directionRepeat && MoveRepeat >= MoveRepeatRate ) ) ) {
Serial.println(F("RIGHT")); ///UP
MoveRepeat = 0;
player.player_directionRepeat = 1;
tft.writeRectNBPP(player.player_x, player.player_y, 16, 16, 4, paulrightw, palette);
tft.writeRectNBPP(player.player_x, player.player_y, 16, 16, 4, paulright, palette);
player.player_direction = 4;
player.player_x += 4;
if (checkcolision())
{
player.player_x -= 4;
player.player_directionRepeat = 0;
}
last_x = x; ////added this
last_y = y; ////added this
}
if (player.player_x <= 16) {
player.player_x = 16;
}
Thank you by the way!! You taught me new piece of programming!!!!