 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
Cogboy
Joined: 19 Jan 2005 Posts: 45
|
Posted: Sat Mar 25, 2006 4:13 am Post subject: Help with seemingly erroneous syntax error |
|
|
Hi, just installed cygwin and psp sdk the day before yesterday and been having some fun with oslib, but now i've come across an error that makes absolutely no sense as far as i can see.
Here is the error i get from cygwin:
| Code: | $ make kxploit
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -G4 -Wall -02 -c -o main.o mai
n.c
main.c: In function 'p1CalcPos':
main.c:77: error: syntax error before 'else'
make: *** [main.o] Error 1 |
seems fairly simple no? Think again.
| Code: | #include <oslib/oslib.h>
#include <math.h>
PSP_MODULE_INFO("Sams Game", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
OSL_IMAGE *player1;
void Keys();
void p1CalcPos();
int main()
{
//Initialize the different parts of the library
oslInit(0);
oslInitGfx(OSL_PF_8888, 1);
oslInitConsole();
//load files
player1 = oslLoadImageFile("player1.png", OSL_IN_RAM, OSL_PF_5551);
//Configure the joypad
oslSetKeyAutorepeatInit(40);
oslSetKeyAutorepeatInterval(10);
//Initialize variables
player1->centerX = player1->sizeX / 2; //Rotation center of player1s sprite
player1->centerY = player1->sizeY / 2;
player1->x = 240; //Place player1 at the center of the screen
player1->y = 136;
//Main loop
while (!osl_quit)
{
oslStartDrawing(); //Display code
Keys();
oslClearScreen(RGB(0,0,0)); //Black screen
oslSetBilinearFilter(1); //Smoothing
p1CalcPos();
oslDrawImage(player1);
oslEndDrawing(); //End of display code
oslSyncFrame(); //Synchronization
}
//Game terminated (HOME -> quit)
oslEndGfx();
oslQuit();
return 0;
}
void Keys()
{
oslReadKeys();
//buttons
if (osl_keys->pressed.triangle) oslSetBilinearFilter(0);
if (osl_keys->held.L) player1->angle -= 3; //make a rotation to player1
if (osl_keys->held.R) player1->angle += 3;
if (osl_keys->pressed.start) oslQuit(); //exit the game
}
void p1CalcPos()
{
float pi = 3.141592;
float thrust = 0.6;
float decay = 0.98;
int maxSpeed = 25;
static int xSpeed = 0;
static int ySpeed = 0;
static int speed = 0;
if (osl_keys->held.cross)
xSpeed+=(thrust*sin(player1->angle*(pi/180)));
ySpeed+=(thrust*cos(player1->angle*(pi/180)));
else
xSpeed *= decay;
ySpeed *= decay;
speed = sqrt( ( xSpeed * xSpeed ) + ( ySpeed * ySpeed ) );
if (speed>maxSpeed)
xSpeed *= ( maxSpeed / speed );
ySpeed *= ( maxSpeed / speed );
player1->x -= xSpeed;
player1->y -= ySpeed;
}
|
And the makefile just in case its involved somewhere:
| Code: | TARGET = main
OBJS = main.o
YOURLIBS=
INCDIR =
CFLAGS = -G4 -Wall -O2
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LDFLAGS =
STDLIBS= -losl -lpng -lz \
-lpspsdk -lpspctrl -lpspumd -lpsprtc -lpsppower -lpspgu -lpspaudiolib -lpspaudio -lm
LIBS=$(STDLIBS)$(YOURLIBS)
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Sams Game
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak |
If i comment out my p1CalcPos function it compiles and runs fine, displaying my nicely smoothed spaceship in the center of the screen and rotating with the triggers.
But i can't for the life of me figure out what the hell is causing this error.
this is the first time i have used C, and only the seccond game i have coded. The first one being a flash version of what i hope this will be eventually.
Basicly, i need all the help i can get.
Thanks in advance,
Cogboy. _________________ "the sony PSP was built by god, to determine who on earth had the best skills to defeat the armies of satan" - Saint Peter. |
|
| Back to top |
|
 |
weltall
Joined: 20 Feb 2004 Posts: 310
|
Posted: Sat Mar 25, 2006 4:30 am Post subject: |
|
|
the compiler is correct there is a problem with your if/else
if (osl_keys->held.cross)
xSpeed+=(thrust*sin(player1->angle*(pi/180)));
ySpeed+=(thrust*cos(player1->angle*(pi/180)));
else
xSpeed *= decay;
ySpeed *= decay;
...
if (speed>maxSpeed)
xSpeed *= ( maxSpeed / speed );
ySpeed *= ( maxSpeed / speed );
if you don't put { } after the if statement you can't do two lines of code but only one so the compiler see this like this
if osl_keys->held.cross = 1 do this xSpeed+=(thrust*sin(player1->angle*(pi/180)));
then also if osl_keys->held.cross = 0 do this ySpeed+=(thrust*cos(player1->angle*(pi/180)));.
where is the if of this else?
so to make this compile and do what you want to do, you must modify these lines like this:
| Code: | if (osl_keys->held.cross) {
xSpeed+=(thrust*sin(player1->angle*(pi/180)));
ySpeed+=(thrust*cos(player1->angle*(pi/180)));
} else {
xSpeed *= decay;
ySpeed *= decay;
}
...
if (speed>maxSpeed) {
xSpeed *= ( maxSpeed / speed );
ySpeed *= ( maxSpeed / speed );
} |
|
|
| Back to top |
|
 |
Cogboy
Joined: 19 Jan 2005 Posts: 45
|
Posted: Sat Mar 25, 2006 4:50 am Post subject: |
|
|
Thanks, i knew it would be something simple. :P
I guess i am kinda diving in the deep end here but this new OldSchoolLibrary is helping a lot. _________________ "the sony PSP was built by god, to determine who on earth had the best skills to defeat the armies of satan" - Saint Peter. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|