In both cases it compiles fine but well this runs perfectly
this results in the game crashing.
Does anybody know what I'm doing wrong and how to correct it?
Code:
#include <stdio.h>
#include <time.h>
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_mixer.h>
#include <SDL_opengl.h>
#include <Box2D.h>
#include <string>
#include <math.h>
bool quit = false;
#include "Generic\generic.h"
#include "Game\Game_main.h"
SDL_Event event;
const float PIXELS_PER_UNIT = 100.0;
const float32 timeStep = 1.0f / 30.0f;
const int32 iterations = 1;
b2World *world = 0;b2AABB worldAABB;
b2Body *youbody;b2Body *citybody;
int main( int argc, char *argv[] ){
init();
Game_init();
worldAABB.lowerBound.Set(-100000,-100000);
worldAABB.upperBound.Set(100000,100000);
b2Vec2 gravity(0,0);bool doSleep = true;world = new b2World(worldAABB,gravity,doSleep);
b2BodyDef youbodydef;
youbodydef.position.Set((float32)youx/PIXELS_PER_UNIT,(float32)youy/PIXELS_PER_UNIT);
youbodydef.linearDamping=4.5;
youbodydef.angularDamping=4.5;
youbodydef.allowSleep = false;
b2Body* youbody = world->CreateBody(&youbodydef);
b2CircleDef youShapeDef;
youShapeDef.radius = 17/PIXELS_PER_UNIT;
youShapeDef.density = 6;
youShapeDef.friction = 0;
youbody->CreateShape(&youShapeDef);
youbody->SetMassFromShapes();
Timer fps;
while( quit == false ){
fps.start();
Game_run();
if (up+down+left+right>0){
float32 x=youbody->GetLinearVelocity().x+(float32)(sin(moveangle*PIover180)*walkspeed);
float32 y=youbody->GetLinearVelocity().y+(float32)(cos(moveangle*PIover180)*walkspeed);
youbody->SetLinearVelocity(b2Vec2(x,y));}
youx=youbody->GetPosition().x*PIXELS_PER_UNIT;
youy=youbody->GetPosition().y*PIXELS_PER_UNIT;
world->Step(timeStep,iterations);
while( SDL_PollEvent( &event ) ){if( event.type == SDL_QUIT ){quit = true;}}
SDL_GL_SwapBuffers();
if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ){SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() );}
}SDL_Quit();return 0;}
#include <time.h>
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_mixer.h>
#include <SDL_opengl.h>
#include <Box2D.h>
#include <string>
#include <math.h>
bool quit = false;
#include "Generic\generic.h"
#include "Game\Game_main.h"
SDL_Event event;
const float PIXELS_PER_UNIT = 100.0;
const float32 timeStep = 1.0f / 30.0f;
const int32 iterations = 1;
b2World *world = 0;b2AABB worldAABB;
b2Body *youbody;b2Body *citybody;
int main( int argc, char *argv[] ){
init();
Game_init();
worldAABB.lowerBound.Set(-100000,-100000);
worldAABB.upperBound.Set(100000,100000);
b2Vec2 gravity(0,0);bool doSleep = true;world = new b2World(worldAABB,gravity,doSleep);
b2BodyDef youbodydef;
youbodydef.position.Set((float32)youx/PIXELS_PER_UNIT,(float32)youy/PIXELS_PER_UNIT);
youbodydef.linearDamping=4.5;
youbodydef.angularDamping=4.5;
youbodydef.allowSleep = false;
b2Body* youbody = world->CreateBody(&youbodydef);
b2CircleDef youShapeDef;
youShapeDef.radius = 17/PIXELS_PER_UNIT;
youShapeDef.density = 6;
youShapeDef.friction = 0;
youbody->CreateShape(&youShapeDef);
youbody->SetMassFromShapes();
Timer fps;
while( quit == false ){
fps.start();
Game_run();
if (up+down+left+right>0){
float32 x=youbody->GetLinearVelocity().x+(float32)(sin(moveangle*PIover180)*walkspeed);
float32 y=youbody->GetLinearVelocity().y+(float32)(cos(moveangle*PIover180)*walkspeed);
youbody->SetLinearVelocity(b2Vec2(x,y));}
youx=youbody->GetPosition().x*PIXELS_PER_UNIT;
youy=youbody->GetPosition().y*PIXELS_PER_UNIT;
world->Step(timeStep,iterations);
while( SDL_PollEvent( &event ) ){if( event.type == SDL_QUIT ){quit = true;}}
SDL_GL_SwapBuffers();
if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ){SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() );}
}SDL_Quit();return 0;}
this results in the game crashing.
Code:
#include <stdio.h>
#include <time.h>
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_mixer.h>
#include <SDL_opengl.h>
#include <Box2D.h>
#include <string>
#include <math.h>
bool quit = false;
#include "Generic\generic.h"
#include "Game\Game_main.h"
SDL_Event event;
const float PIXELS_PER_UNIT = 100.0;
const float32 timeStep = 1.0f / 30.0f;
const int32 iterations = 1;
b2World *world = 0;b2AABB worldAABB;
b2Body *youbody;b2Body *citybody;
void box2dblah(){
if (up+down+left+right>0){
float32 x=youbody->GetLinearVelocity().x+(float32)(sin(moveangle*PIover180)*walkspeed);
float32 y=youbody->GetLinearVelocity().y+(float32)(cos(moveangle*PIover180)*walkspeed);
youbody->SetLinearVelocity(b2Vec2(x,y));}
youx=youbody->GetPosition().x*PIXELS_PER_UNIT;
youy=youbody->GetPosition().y*PIXELS_PER_UNIT;
world->Step(timeStep,iterations);}
int main( int argc, char *argv[] ){
init();
Game_init();
worldAABB.lowerBound.Set(-100000,-100000);
worldAABB.upperBound.Set(100000,100000);
b2Vec2 gravity(0,0);bool doSleep = true;world = new b2World(worldAABB,gravity,doSleep);
b2BodyDef youbodydef;
youbodydef.position.Set((float32)youx/PIXELS_PER_UNIT,(float32)youy/PIXELS_PER_UNIT);
youbodydef.linearDamping=4.5;
youbodydef.angularDamping=4.5;
youbodydef.allowSleep = false;
b2Body* youbody = world->CreateBody(&youbodydef);
b2CircleDef youShapeDef;
youShapeDef.radius = 17/PIXELS_PER_UNIT;
youShapeDef.density = 6;
youShapeDef.friction = 0;
youbody->CreateShape(&youShapeDef);
youbody->SetMassFromShapes();
Timer fps;
while( quit == false ){
fps.start();
Game_run();
box2dblah();
while( SDL_PollEvent( &event ) ){if( event.type == SDL_QUIT ){quit = true;}}
SDL_GL_SwapBuffers();
if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ){SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() );}
}SDL_Quit();return 0;}
#include <time.h>
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_mixer.h>
#include <SDL_opengl.h>
#include <Box2D.h>
#include <string>
#include <math.h>
bool quit = false;
#include "Generic\generic.h"
#include "Game\Game_main.h"
SDL_Event event;
const float PIXELS_PER_UNIT = 100.0;
const float32 timeStep = 1.0f / 30.0f;
const int32 iterations = 1;
b2World *world = 0;b2AABB worldAABB;
b2Body *youbody;b2Body *citybody;
void box2dblah(){
if (up+down+left+right>0){
float32 x=youbody->GetLinearVelocity().x+(float32)(sin(moveangle*PIover180)*walkspeed);
float32 y=youbody->GetLinearVelocity().y+(float32)(cos(moveangle*PIover180)*walkspeed);
youbody->SetLinearVelocity(b2Vec2(x,y));}
youx=youbody->GetPosition().x*PIXELS_PER_UNIT;
youy=youbody->GetPosition().y*PIXELS_PER_UNIT;
world->Step(timeStep,iterations);}
int main( int argc, char *argv[] ){
init();
Game_init();
worldAABB.lowerBound.Set(-100000,-100000);
worldAABB.upperBound.Set(100000,100000);
b2Vec2 gravity(0,0);bool doSleep = true;world = new b2World(worldAABB,gravity,doSleep);
b2BodyDef youbodydef;
youbodydef.position.Set((float32)youx/PIXELS_PER_UNIT,(float32)youy/PIXELS_PER_UNIT);
youbodydef.linearDamping=4.5;
youbodydef.angularDamping=4.5;
youbodydef.allowSleep = false;
b2Body* youbody = world->CreateBody(&youbodydef);
b2CircleDef youShapeDef;
youShapeDef.radius = 17/PIXELS_PER_UNIT;
youShapeDef.density = 6;
youShapeDef.friction = 0;
youbody->CreateShape(&youShapeDef);
youbody->SetMassFromShapes();
Timer fps;
while( quit == false ){
fps.start();
Game_run();
box2dblah();
while( SDL_PollEvent( &event ) ){if( event.type == SDL_QUIT ){quit = true;}}
SDL_GL_SwapBuffers();
if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ){SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() );}
}SDL_Quit();return 0;}
Does anybody know what I'm doing wrong and how to correct it?