我正在运行gbdk一个gameboy游戏制作程序,我在下面的代码中得到解析错误

时间:2014-01-29 02:22:32

标签: c gameboy

#include <gb/gb.h>
#include <stdio.h>
#include "racecars.h"

/*

 RACECARS.C

 Tile Source File.

 Info:
  Form                 : All tiles as one unit.
  Format               : Gameboy 4 color.
  Compression          : None.
  Counter              : None.
  Tile size            : 8 x 8
  Tiles                : 0 to 16

  Palette colors       : None.
  SGB Palette          : None.
  CGB Palette          : None.

  Convert to metatiles : No.

 This file was generated by GBTD v2.2

*/

/* Start of tile array. */
unsigned char Racecars[] =
{
  0x7E,0x7E,0x42,0x5E,0xC3,0xD7,0xC3,0xDF,
  0x42,0x52,0x7E,0x7E,0xC3,0xC3,0xC3,0xC3,
  0x1C,0x1C,0x36,0x3E,0x62,0x7A,0x43,0x4B,
  0x41,0x5D,0x7F,0x7F,0x55,0x55,0x77,0x77,
  0x38,0x38,0x44,0xC6,0xAA,0xAA,0xAA,0xAA,
  0xAA,0xAA,0x82,0x82,0x44,0xC6,0x38,0x38,
  0x18,0x18,0x18,0x18,0x24,0x24,0x42,0x42,
  0xFF,0xFF,0x00,0xC6,0x00,0xC6,0x00,0x00,
  0x3C,0x3C,0x24,0xE7,0x24,0xE7,0x24,0x24,
  0x24,0xE7,0x3C,0xFF,0x24,0x24,0x3C,0x3C,
  0x18,0x18,0x24,0xE7,0x42,0xC3,0x42,0x42,
  0x42,0x42,0x24,0x66,0x18,0x7E,0x00,0x00,
  0xF2,0xF2,0x96,0x96,0xF2,0xF2,0x82,0x82,
  0x8F,0x8F,0x00,0x00,0x00,0x00,0x00,0x00,
  0xEE,0xEE,0x82,0x82,0x8E,0x8E,0x8B,0x8B,
  0xEE,0xEE,0x00,0x00,0x00,0x00,0x00,0x00,
  0xEE,0xEE,0x82,0x82,0x8E,0x8E,0x82,0x82,
  0xEE,0xEE,0x00,0x00,0x00,0x00,0x00,0x00,
  0xE2,0xE2,0x86,0x86,0x82,0x82,0x82,0x82,
  0xE7,0xE7,0x00,0x00,0x00,0x00,0x00,0x00,
  0xEA,0xEA,0x8A,0x8A,0x8E,0x8E,0x82,0x82,
  0xE2,0xE2,0x00,0x00,0x00,0x00,0x00,0x00,
  0xE7,0xE7,0x84,0x84,0x87,0x87,0x81,0x81,
  0xE7,0xE7,0x00,0x00,0x00,0x00,0x00,0x00,
  0xF7,0xF7,0x85,0x85,0x85,0x85,0xB5,0xB5,
  0x95,0x95,0xF7,0xF7,0x00,0x00,0x00,0x00,
  0x82,0x82,0x82,0x82,0x92,0x92,0x92,0x92,
  0x92,0x92,0x92,0x92,0xFE,0xFE,0x00,0x00,
  0xFF,0xFF,0x10,0x10,0x10,0x10,0x10,0x10,
  0x10,0x10,0xFF,0xFF,0x00,0x00,0x00,0x00,
  0x82,0x82,0xC2,0xC2,0xA2,0xA2,0x92,0x92,
  0x8A,0x8A,0x86,0x86,0x82,0x82,0x00,0x00,
  0x20,0x20,0x30,0x30,0x38,0x38,0x3C,0x3C,
  0x20,0x20,0x20,0x20,0x20,0x20,0xFF,0xFF
};

/* End of RACECARS.C */

int main(void){             //starts the main function
 int x,y,st,key,z;          //define the integers x and y wich will be used to define the hero position, key will be used later
 int x1,y1,st1;             
 int x2,y2,st2;             
 int x3,y3,st3; 
    x=20;                   //set x as 20
    y=20;                   //set y as 20
    st=0;                   //sprite type(1=closed 0=open)
    z=0;                    //set z=0, z will be used for testing if its time to change sprite or not

    set_sprite_data(0,76,Racecars);     //set our sprite data   

    wait_vbl_done();            //wait for the visual blank to be done
    set_sprite_tile(0,0);           //set our tile 0 as the tile 0 of our tile data-pacman open
    set_sprite_tile(1,1);           //set our tile 1 as the 1st tile of our tile data-pacman closed
    set_sprite_tile(2,2);
    set_sprite_tile(3,3);
    set_sprite_tile(4,4);
    set_sprite_tile(5,5);
    set_sprite_tile(6,6);
    set_sprite_tile(7,7);
    set_sprite_tile(8,8);
    set_sprite_tile(9,9);
    set_sprite_tile(10,10);
    set_sprite_tile(11,11);
    set_sprite_tile(12,12);
    set_sprite_tile(13,13);
    set_sprite_tile(14,14);
    set_sprite_tile(15,15);
    set_sprite_tile(16,16);

    move_sprite(st,x,y);            

    #define MapSizeX 256;   

    #define MapSizeY 256;   


    UBYTE ScrollXCnt;   

    UBYTE ScrollYCnt;   

    BYTE SCXCnt;        

    BYTE SCYCnt;        

    UBYTE tempa, tempb; 

    UWORD Cnt;      





    Cnt = 0;

    wait_vbl_done();

    for(tempa = 0; tempa != 32; tempa++) {

        set_bkg_tiles(0,tempa,32,tempa+1,TileMap[Cnt]);

        Cnt = Cnt + MapSizeX;   

    }
    if(joypad() & J_UP) ScrollUp();

    if(joypad() & J_DOWN) ScrollDown();

    if(joypad() & J_LEFT) ScrollLeft();

    if(joypad() & J_RIGHT) ScrollRight();

    wait_vbl_done();

    scroll_bkg(x,y);  

    ScrollX++;  or  ScrollX--;

    ScrollY++;  or  ScrollY--;

    SCXCnt++;   or  SCXCnt++;

    SCYCnt++;   or  SCYCnt--;

        if(SCXCnt == 8) {

        SCXCnt = 0;     

        Cnt = ScrollX / 8;  



        Cnt = Cnt + 20;     





        for(tempa = 0; tempa != 224; tempa++) {



            set_bkg_tiles(0,tempa,1,tempa+1,TileMap[Cnt]);

            Cnt = Cnt + MapSizeX;

        }       

    }

    if(SCXCnt == -8) {

        SCXCnt = 0;

        SCXCnt = 0;     

        Cnt = ScrollX / 8;  


        Cnt--;          




        for(tempa = 0; tempa != 224; tempa++) {



            set_bkg_tiles(0,tempa,1,tempa+1,TileMap[Cnt]);


            Cnt = Cnt + MapSizeX;

        }       

    }
    .

    .

    .

这是c代码

我运行了提示,弹出了以下错误。

   Parse error before ubyte line 108
   Parse error before scroll x
   Parse error before scroll y
   Parse error before scxCnt
   Parse error before ScyCnt
   Parse error before 32

3 个答案:

答案 0 :(得分:1)

您的问题是您要在函数中间定义新变量。无论出于何种原因,GBDK编译器都不允许这样做。 (这显然是ANSI C / C89标准的一部分)

您可以通过更改main()的顶部

来解决此问题
int main(void){             //starts the main function
 int x,y,st,key,z;          //define the integers x and y wich will be used to define the hero position, key will be used later
 int x1,y1,st1;             
 int x2,y2,st2;             
 int x3,y3,st3; 

到此:

int main(void){             //starts the main function
    int x,y,st,key,z;          //define the integers x and y wich will be used to define the hero position, key will be used later
    int x1,y1,st1;
    int x2,y2,st2;
    int x3,y3,st3;

    //These variables are used later on.
    UBYTE ScrollXCnt;
    UBYTE ScrollYCnt;
    BYTE SCXCnt;
    BYTE SCYCnt;
    UBYTE tempa, tempb;
    UWORD Cnt;

或者,您可以将从这些变量开始的所有代码移动到另一个函数,然后使用该函数声明这些变量,并且一切都会正常。

答案 1 :(得分:0)

您可能缺少定义UBYTE的包含文件。

答案 2 :(得分:0)

当前的 sdcc 4.1.0 和 gbdk-2020 4.0.3 不应出现该 UBYTE 错误

GBDK 的最后一次更新是 2001 年左右......

虽然其他错误来自您的代码无效。

这不是有效的 C 代码:

    ScrollX++;  or  ScrollX--;

    ScrollY++;  or  ScrollY--;

    SCXCnt++;   or  SCXCnt++;

    SCYCnt++;   or  SCYCnt--;

而且我认为这不是您想要的:

    #define MapSizeX 256;   

    #define MapSizeY 256; 

定义总是无作用域的,因为它们是由预处理器而不是编译器处理的。而你更想要#define MapSizeX 256U

您编写的内容将适用于您的代码。 Cnt = Cnt + MapSizeX; 变成 Cnt = Cnt + 256;; 没什么大不了的,但以后可能会坏掉。