[Solved] Lunar run SD Code

Understanding the language, error messages, etc.

[Solved] Lunar run SD Code

Postby clement » Sun May 10, 2015 7:43 am

Hi,

I would like to use the Myndale Code of Lunar run for a new game.

But I don't understand how this work.

First Myndale Use the persistence :
Code: Select all
  gb.display.persistence = true;


And he load the map ".DAT"

Code: Select all
PFFS.lseek_file(screen_num*(LCDWIDTH*LCDHEIGHT/8));
    uint8_t * buffer = gb.display.getBuffer();
    for (int row=0; row<LCDHEIGHT/8; row++, buffer+=LCDWIDTH)
      PFFS.read_file((char *)buffer, LCDWIDTH, &bytes_read);



Finally he draw the ship :

Code: Select all
 
gb.display.setColor(INVERT);
  if (grayscale_frame)
    drawBitmap(dst_x, dst_y, dst_w, dst_h, src_x, src_y, image1);
  else
    drawBitmap(dst_x, dst_y, dst_w, dst_h, src_x, src_y, image2);


All work fine !

When I do the same thing in my game the world is correctly draw, but the Player are persisted in the screen.
the code for load map is same as the Myndale Code

I change the code for draw Player :
Code: Select all


    gb.display.drawBitmap((player.x % LCDWIDTH) - 4,(player.y % LCDHEIGHT) - 5, player.sprites[player.currentState].sprite1); //Sprite
/* another test */

    gb.display.setColor(INVERT);
    gb.display.drawBitmap((player.x % LCDWIDTH) - 4,(player.y % LCDHEIGHT) - 5, player.sprites[player.currentState].sprite1); //Sprite


/* another test */

    gb.display.setColor(INVERT,INVERT);
   
    if(gb.frameCount%2 == 0)//grey scale frame
    {
      gb.display.drawBitmap((player.x % LCDWIDTH) - 4,(player.y % LCDHEIGHT) - 5, player.sprites[player.currentState].sprite1); //Sprite
    }
    else {
      gb.display.drawBitmap((player.x % LCDWIDTH) - 4,(player.y % LCDHEIGHT) - 5, player.sprites[player.currentState].sprite2); //inverse sprite (black are white and white are black)
    }

/* and with draw Myndale's bitmap */

    gb.display.setColor(INVERT);
   
    if(gb.frameCount%2 == 0)
    {
      drawBitmap((player.x % LCDWIDTH) - 4,(player.y % LCDHEIGHT) - 5,8,11,0,0, player.sprites[player.currentState].sprite1);
    }
    else {
      drawBitmap((player.x % LCDWIDTH) - 4,(player.y % LCDHEIGHT) - 5,8,11,0,0, player.sprites[player.currentState].sprite2);     
    }




Thx for your help :)
Last edited by clement on Fri May 22, 2015 7:02 am, edited 1 time in total.
clement
 
Posts: 161
Joined: Sat Oct 25, 2014 8:06 am

Re: Lunar run SD Code

Postby Myndale » Tue May 19, 2015 6:02 am

I'd have to see a working sample of your code but I'll try to explain how the LunarRun code works. At the moment there isn't enough free RAM to store the entire screen, even in compressed format. What I do instead is load the level in and draw the ship in its current position using INVERT. Then, once per frame I draw the ship in its old position using INVERT to erase it, update the ship position and then draw it with INVERT again.

I haven't looked closely at your code but if you're seeing your player persisting then it probably means either 1) you haven't drawn it with INVERT immediately after the erase, 2) you're not doing it twice in your render look, or 3) you're not updating the ship position in between the two. Remember the purpose of the first draw is to erase the ship from the previous frame, so make sure you draw it in exactly the same position that you drew it the second time in the frame before.
Myndale
 
Posts: 507
Joined: Sat Mar 01, 2014 1:25 am

Re: Lunar run SD Code

Postby clement » Tue May 19, 2015 6:51 am

Thx Myndale,

I draw my sprite with invert but I do it once per frame.

Thx a lot !
clement
 
Posts: 161
Joined: Sat Oct 25, 2014 8:06 am

Re: [Solved] Lunar run SD Code

Postby jonnection » Mon May 25, 2015 1:04 pm

Myndale wrote:I'd have to see a working sample of your code but I'll try to explain how the LunarRun code works. At the moment there isn't enough free RAM to store the entire screen, even in compressed format. What I do instead is load the level in and draw the ship in its current position using INVERT. Then, once per frame I draw the ship in its old position using INVERT to erase it, update the ship position and then draw it with INVERT again.


That is, however, not the only way to do it. You could simply draw the screen once per each refresh directly from the SD card.

Here is 20 frames per second directly from SD card with PetitFATFS with 2 x 128 byte buffer.

User avatar
jonnection
 
Posts: 317
Joined: Sun May 04, 2014 8:21 pm


Return to Programming Questions

Who is online

Users browsing this forum: No registered users and 85 guests

cron