Newb at game making Sprite and game map developing

Understanding the language, error messages, etc.

Re: Newb at game making Sprite and game map developing

Postby Duhjoker » Tue Aug 02, 2016 5:56 am

OK I put everything together and it compiles but I'm still getting flicker from the tilemap and sever speeds right or left to the boundary but up and down move correctly. I cant really tell if the player sprites are working correctly.

I went ahead and made a few terrain sprites extra for adding extra rooms and included them in the sketch. Not having to save all those huge bitmaps looks like it might be cheaper in the end which means more maps in a single program I say with fingers crossed



Code: Select all


#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;

const byte tilemap[] PROGMEM = {14,8,
6,6,
3,3,3,3,3,3,6,6,3,3,3,3,3,3,
3,3,3,5,3,6,6,6,3,3,3,3,3,3,
3,3,6,6,6,6,6,6,6,3,3,3,3,3,
3,6,6,6,6,6,6,6,6,6,3,3,3,3,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,
3,3,6,6,6,6,6,6,6,6,6,6,3,3,
3,3,6,6,6,6,6,6,6,6,6,6,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3};

const byte bush_bottom[] PROGMEM = {6,6,0x48,0x30,0x58,0x00,0x00,0x00,};
const byte bush_top[] PROGMEM = {6,6,0x00,0x00,0x00,0x30,0x48,0xb4,};
const byte bush[] PROGMEM = {6,6,0x30,0x48,0xb4,0x48,0x30,0x58,};
const byte rock_terrain[] PROGMEM = {6,6,0x48,0xa4,0x14,0xa0,0x84,0x50,};
const byte turtle_rock[] PROGMEM = {6,6,0x48,0xa4,0x14,0xa0,0x84,0x50,};
const byte port_noir[] PROGMEM = {6,6,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,};
const byte port_blanc[] PROGMEM = {6,6,0x00,0x00,0x00,0x00,0x00,0x00,};

const byte *spritesheet[] = {bush_bottom,bush_top,bush,rock_terrain,turtle_rock,port_noir,port_blanc};

const byte sever_front_1[] PROGMEM = {6,6,0x78,0x0,0x0,0x30,0x0,0xcc,};
const byte sever_front_2[] PROGMEM = {6,6,0x84,0x48,0x78,0x84,0x78,0x0,};
const byte sever_left_1[] PROGMEM = {6,6,0x78,0x80,0xc8,0xb4,0x0,0xcc,};
const byte sever_left_2[] PROGMEM = {6,6,0x4,0x58,0x30,0x0,0x78,0x0,};
const byte sever_rear_1[] PROGMEM = {6,6,0X78,0X78,0X0,0X30,0X0,0XCC,};
const byte sever_rear_2[] PROGMEM = {6,6,0x84,0x0,0x78,0x84,0x78,0x0,};
const byte sever_right_1[] PROGMEM = {6,6,0x78,0x4,0x4c,0xb4,0x0,0xcc,};
const byte sever_right_2[] PROGMEM = {6,6,0x80,0x68,0x30,0x0,0x78,0x0,};

  int player_x = 15;
  int player_y = 15;
  int player_direction = 0;

int x=0,y=0;


void setup() {
  gb.begin();
  gb.titleScreen(F("test"));
  gb.display.persistence = false;
}
void loop() {
  if(gb.update()){
    if (gb.buttons.repeat(BTN_RIGHT,1));
    if (gb.buttons.repeat(BTN_LEFT,1));
    if (gb.buttons.repeat(BTN_DOWN,1));
    if (gb.buttons.repeat(BTN_UP,1));
    gb.display.drawTilemap(x,y,tilemap,spritesheet); // draw the tilemap
//    gb.display.cursorY = 12; gb.display.println( x );gb.display.println( y );

 if(gb.buttons.repeat(BTN_UP,1)){
       gb.display.setColor(BLACK);{
    gb.display.drawBitmap(player_x,player_y,sever_rear_1);
    }
    gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,sever_rear_2);
    }
      player_direction = 1;
      player_y = player_y - 1;}
    if(player_y <= 0){
      player_y = 0;}



    if(gb.buttons.repeat(BTN_DOWN,1)){
      gb.display.setColor(BLACK);{
    gb.display.drawBitmap(player_x,player_y,sever_front_1);
    }
     gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,sever_front_2);
    }
      player_direction = 2;
      player_y = player_y + 1;}
    if(player_y >= 40){
      player_y = 40;}
  }


    if(gb.buttons.repeat(BTN_RIGHT,1)){
       gb.display.setColor(BLACK);{
    gb.display.drawBitmap(player_x,player_y,sever_right_1);
    }
     gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,sever_right_2);
    }
      player_direction = 3;
      player_x = player_x + 1;}
    if(player_x >= 77){
      player_x = 77;}


    if(gb.buttons.repeat(BTN_LEFT,1)){
       gb.display.setColor(BLACK);{
    gb.display.drawBitmap(player_x,player_y,sever_left_1);
    }
    gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,sever_left_2);
    }
      player_direction = 4;
      player_x = player_x - 1;}
    if(player_x <= -2){
      player_x = -2;}
     
      ////////////PLAYER DIRECTION/////////////

 if (player_direction == 1){
        gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_rear_1);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_rear_2);
        }
      }
      else if (player_direction == 2){
        gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_front_1);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_front_2);
        }
      }
else if (player_direction == 3){
        gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_left_1);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_left_2);
        }
      }
      else if (player_direction == 4){
        gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_right_1);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_right_2);
        }
      }
      else {
        gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_front_1);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_front_2);
        }
      }
 }


Edit: made a couple corrections player sprites stop with correct orientation but still zooms left and right and tilemap flickers. I can't figure out what I did to make it do that.

Edit 2: fixed my player sprites to 6,6, instead of 8,6. Don't know why I had them like that. Glitches still persist
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: Newb at game making Sprite and game map developing

Postby Duhjoker » Tue Aug 02, 2016 8:53 am

Ok I've staring at the screen and fixing things way too long but I think I know what the problem is.

On the player direction I need to add the

Code: Select all
else if (player_direction == X){
   gb.display.setColor(XXXX); {
   gb.display.drawBitmap(player_x,player_y,SpriteID);
}

For each color of player Sprite color

My new rock terrain sprite sucks gonna go back to the old.

Edit::: Fixing the { } placement seems to have fixed my sketch though as far as moving the character and the tilemap flickering. It's too late to try the what I mentioned above but for some reason the white bitmap I made labeled port_blanc shows a 3 bit vertical line on each 6x6 square on the tile map



Neat trick I learned tonight, if you click on a { or } bracket it will mark its match on the sketch so you can tell which ones are open and which ones are closed.
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: Newb at game making Sprite and game map developing

Postby naed » Tue Aug 02, 2016 1:42 pm

Sound like you've found your problem with the player sprite, that's because my example only included a one color black sprite, you would need to add a second command to show the grey pixels for your sprite, I look forward to hearing if this fix works

I've been looking at the collision detection for you, there is some info on this forum, but if I'm honest right now it's a little above my knowledge base
User avatar
naed
 
Posts: 140
Joined: Tue May 31, 2016 3:18 pm

Re: Newb at game making Sprite and game map developing

Postby Duhjoker » Tue Aug 02, 2016 11:16 pm

All right guys I think it's time to start a new thread. IDK about the rest of you but I think I finally understand how to display sprites and game maps. Should be enough info here get the most learningly challenged coder (I speak of myself) up and running.

A special thanks to Naed and Sorunome for your patience and time. I hope to be able to give back to the community myself.

Next guide:::: Newbs need help with collision detection.



At some point I will clean this thread up so most of my gobbledygook is gone Leaving only relevant information to make it easier to find what you are looking for. :P
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: Newb at game making Sprite and game map developing

Postby Duhjoker » Wed Aug 03, 2016 2:19 am

ok I having trouble with tilemapping. I got the flickering to stop but now it looks like its showing negative ? I don't really know but its also creating an extra set of three vertical pixels on the blank sprites.

Code: Select all

#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;

const byte tilemap[] PROGMEM = {14,8,
6,6,
3,3,3,3,3,3,6,6,3,3,3,3,3,3,
3,3,3,5,3,6,6,6,3,3,3,3,3,3,
3,3,6,6,6,6,6,6,6,3,3,3,3,3,
3,6,6,6,6,6,6,6,6,6,3,3,3,3,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,
3,3,6,6,6,6,6,6,6,6,6,6,3,3,
3,3,6,6,6,6,6,6,6,6,6,6,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3};

const byte bush_bottom[] PROGMEM = {6,6,0x48,0x30,0x58,0x00,0x00,0x00,};
const byte bush_top[] PROGMEM = {6,6,0x00,0x00,0x00,0x30,0x48,0xb4,};
const byte bush[] PROGMEM = {6,6,0x30,0x48,0xb4,0x48,0x30,0x58,};
const byte rock_terrain[] PROGMEM = {6,6,0x58,0xa4,0x14,0xa0,0x84,0x58,};
const byte turtle_rock[] PROGMEM = {6,6,0x48,0xa4,0x14,0xa0,0x84,0x50,};
const byte port_noir[] PROGMEM = {6,6,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,};
const byte port_blanc[] PROGMEM = {6,6,0x00,0x00,0x00,0x00,0x00,0x00,};

const byte *spritesheet[] = {bush_bottom,bush_top,bush,rock_terrain,turtle_rock,port_noir,port_blanc};

const byte sever_front_1[] PROGMEM = {6,6,0x78,0x0,0x0,0x30,0x0,0xcc,};
const byte sever_front_2[] PROGMEM = {6,6,0x84,0x48,0x78,0x84,0x78,0x0,};
const byte sever_left_1[] PROGMEM = {6,6,0x78,0x80,0xc8,0xb4,0x0,0xcc,};
const byte sever_left_2[] PROGMEM = {6,6,0x4,0x58,0x30,0x0,0x78,0x0,};
const byte sever_rear_1[] PROGMEM = {6,6,0X78,0X78,0X0,0X30,0X0,0XCC,};
const byte sever_rear_2[] PROGMEM = {6,6,0x84,0x0,0x78,0x84,0x78,0x0,};
const byte sever_right_1[] PROGMEM = {6,6,0x78,0x4,0x4c,0xb4,0x0,0xcc,};
const byte sever_right_2[] PROGMEM = {6,6,0x80,0x68,0x30,0x0,0x78,0x0,};

  int player_x = 15;
  int player_y = 15;
  int player_direction = 0;

int x=0,y=0;


void setup() {
  gb.begin();
  gb.titleScreen(F("test"));
  gb.display.persistence = false;
}


void loop() {
  if(gb.update()){
    if (gb.buttons.repeat(BTN_RIGHT,1));
    if (gb.buttons.repeat(BTN_LEFT,1));
    if (gb.buttons.repeat(BTN_DOWN,1));
    if (gb.buttons.repeat(BTN_UP,1));
    gb.display.drawTilemap(x,y,tilemap,spritesheet); // draw the tilemap
//    gb.display.cursorY = 12; gb.display.println( x );gb.display.println( y );






 if(gb.buttons.repeat(BTN_UP,1)){
       gb.display.setColor(BLACK);{
    gb.display.drawBitmap(player_x,player_y,sever_rear_1);
       }
    gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,sever_rear_2);
    }
      player_direction = 1;
      player_y = player_y - 1;}
    if(player_y <= 0){
      player_y = 0;}



    if(gb.buttons.repeat(BTN_DOWN,1)){
      gb.display.setColor(BLACK);{
    gb.display.drawBitmap(player_x,player_y,sever_front_1);
    }
     gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,sever_front_2);
    }
      player_direction = 2;
      player_y = player_y + 1;}
    if(player_y >= 40){
      player_y = 40;}
 


    if(gb.buttons.repeat(BTN_RIGHT,1)){
       gb.display.setColor(BLACK);{
    gb.display.drawBitmap(player_x,player_y,sever_right_1);
    }
     gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,sever_right_2);
    }
      player_direction = 3;
      player_x = player_x + 1;}
    if(player_x >= 77){
      player_x = 77;}


    if(gb.buttons.repeat(BTN_LEFT,1)){
       gb.display.setColor(BLACK);{
    gb.display.drawBitmap(player_x,player_y,sever_left_1);
    }
    gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,sever_left_2);
    }
      player_direction = 4;
      player_x = player_x - 1;}
    if(player_x <= -2){
      player_x = -2;}
     
      ////////////PLAYER DIRECTION/////////////

 if (player_direction == 1){
        gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_rear_1);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_rear_2);
        }
 }
     
      else if (player_direction == 2){
        gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_front_1);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_front_2);
        }
      }
else if (player_direction == 3){
        gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_left_1);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_left_2);
        }
}
      else if (player_direction == 4){
        gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_right_1);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_right_2);
        }
      }
      else {  gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_front_1);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_front_2);
        }
      }
  }
 
}
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: Newb at game making Sprite and game map developing

Postby Duhjoker » Wed Aug 03, 2016 2:40 am

fixed::: switched to binary on terrain sprites working now!!!!
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: Newb at game making Sprite and game map developing

Postby Duhjoker » Fri Nov 18, 2016 12:20 am

Ok so what if I want to do world map more a kind to legend of Zelda a link to the past, can I make my PC sprites go behind tiles? Where it disappears and the reappears out the other end?
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: Newb at game making Sprite and game map developing

Postby Duhjoker » Sat Jun 03, 2017 7:45 am

I'm working on playing with button controls and I have a question. What do these numbers represent .....

Code: Select all
if(player_y <= 40){
              player_y = 40;}


In this function to move a sprite.......

Code: Select all
       if (tft.buttons.repeat(BTN_DOWN,1)){
        tft.drawBitmap1(player_x, player_y,paul_front_black,16,16,BLACK);
         tft.drawBitmap1(player_x, player_y,paul_front_blue,16,16,BLUE);
          tft.drawBitmap1(player_x, player_y,paul_front_brown,16,16,BROWN);
           tft.drawBitmap1(player_x, player_y,paul_front_pink,16,16,PINK);
            tft.drawBitmap1(player_x, player_y,paul_front_yellow,16,16,YELLOW);

            player_direction = 2;
             player_y = player_y + 1;}
            if(player_y <= 40){
              player_y = 40;}



I cant find it in the old posts. But they are included in all the new posts as seen in a sketch above this post.
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: Newb at game making Sprite and game map developing

Postby awesome101 » Sat Jun 03, 2017 5:52 pm

It's to prevent Paul from vertically crossing past the fortieth pixels on the top of the screen. It's like a border he can't cross
awesome101
 
Posts: 159
Joined: Sat Jun 20, 2015 6:56 pm

Previous

Return to Programming Questions

Who is online

Users browsing this forum: No registered users and 15 guests

cron