gpt4 book ai didi

c - 我正在运行 gbdk 一个 gameboy 游戏制作程序,并且在以下代码中遇到解析错误

转载 作者:行者123 更新时间:2023-11-30 15:39:31 25 4
gpt4 key购买 nike

#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

最佳答案

您的问题是您必须在函数中间定义新变量。无论出于何种原因,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;

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

关于c - 我正在运行 gbdk 一个 gameboy 游戏制作程序,并且在以下代码中遇到解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21420865/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com