Moped Climb - Box2d game in progress...

ilan

Expert
Licensed User
Longtime User
Good luck, it looks like your most ambitious game yet.

Just out of interest, are you seeing increasing amounts of income now from your in game adverts? I am wanting to develop more games and would feel more motivated to do so if I knew I would start making some extra cash from them.

from my games i dont see much income but i also dont have really good games. this one will be definitely the top game i made until today.
and i am sure you can make nice revenue from games.

BUT if you need some motivation i will send you now a "small" motivation via PM ;)
 

Peter Simpson

Expert
Licensed User
Longtime User
 

melonZgz

Active Member
Licensed User
Longtime User
I like it a lot!
BTW, can I show you a little project I'm in?


It's almost the same idea ;)

So.. how are you handling the terrain?
In mine, I have about 10 prefabs, drawn with Gimp an modelled with the physics editor tool. They are 30m width and I'm adding them one after another.
I really don't know another way to do it... maybe using tiles and quads?
 

ilan

Expert
Licensed User
Longtime User
I like it a lot!
BTW, can I show you a little project I'm in?


It's almost the same idea ;)

So.. how are you handling the terrain?
In mine, I have about 10 prefabs, drawn with Gimp an modelled with the physics editor tool. They are 30m width and I'm adding them one after another.
I really don't know another way to do it... maybe using tiles and quads?

nice, i have also those sprites.
how are you connecting the wheels? are you using a wheeljoint? or prismatic+revolutejoint?
 

ilan

Expert
Licensed User
Longtime User
So.. how are you handling the terrain?
In mine, I have about 10 prefabs, drawn with Gimp an modelled with the physics editor tool. They are 30m width and I'm adding them one after another.
I really don't know another way to do it... maybe using tiles and quads?

this is also how i do it, i create about 16 screen's in gimp and then create the bodies with the physics body editor tool. then i add them with a loop to my game.
my game looks now a little bit different since the last video i added water as a sensor and parts falling down to it and start swim.
when i cross the bridge it will break at the end and i remove 1 distancejoint and the bridge fall down (really nice effect)

the swimming part can be seen here:

 

ilan

Expert
Licensed User
Longtime User
this is how i did it to but i think it is better to use a whelljoint and i cannot figure out how to set it :(
 

melonZgz

Active Member
Licensed User
Longtime User
this is also how i do it, i create about 16 screen's in gimp and then create the bodies with the physics body editor tool. then i add them with a loop to my game.
my game looks now a little bit different since the last video i added water as a sensor and parts falling down to it and start swim.
when i cross the bridge it will break at the end and i remove 1 distancejoint and the bridge fall down (really nice effect)
That sounds great!
this is how i did it to but i think it is better to use a whelljoint and i cannot figure out how to set it :(
I do not know either.
BTW, are you using Fixed timestep in your Box2d games?
I mean the step used in Box2DLights demos, because some days ago I tested my game in a tablet that can go only 55 FPS and the game felt a bit slower...
can you post the code for your prismatic joint defination?

Here you go:

B4X:
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '                Car Body
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Dim escalaCoche As Int = 3
    Dim bd As lgBox2DBodyDef
    bd.Position.Set(18, 2)
    bd.Type = World.BODYTYPE_Dynamic
    Dim fd As lgBox2DFixtureDef
    fd.Density = 5
    fd.Friction = 0.8
    fd.Restitution = 0.2
    fd.filter.groupIndex = -1
   
    cocheBody= World.CreateBody (bd)
    Loader.AttachFixture(cocheBody,"coche",fd,escalaCoche)
    cocheTextura.Initialize("body2.png")
   
    cocheSprite.InitializeWithTexture(cocheTextura)
    cocheSprite.SetSize(escalaCoche, escalaCoche * cocheSprite.Height / cocheSprite.Width)
    Dim Origin As lgMathVector2
    Origin = Loader.GetOrigin("coche", escalaCoche)
    cocheSprite.SetOrigin(Origin.X, Origin.Y)
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '                Axis
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Dim axleShape As lgBox2DPolygonShape
    Dim V1, V2 As lgMathVector2
    axleShape.SetAsBox(0.2,0.2)
   
    Dim axleFixture As lgBox2DFixtureDef
    axleFixture.Density = 0.5
    axleFixture.Friction = 3   
    axleFixture.Restitution = 0.1
    axleFixture.shape = axleShape
    axleFixture.filter.groupIndex = -1

    Dim axleBodyDef As lgBox2DBodyDef
    axleBodyDef.Type = World.BODYTYPE_Dynamic

    'Eje trasero       
    Dim punto As lgMathVector2
    punto.Set(0.13* escalaCoche,0.045* escalaCoche)   
    axleBodyDef.position.Set2(cocheBody.getWorldPoint(punto))   
    Dim rearAxle As lgBox2DBody = World.createBody(axleBodyDef)
    rearAxle.createFixture(axleFixture)

    'Eje delantero
    punto.Set(0.81* escalaCoche,0.045* escalaCoche)   
    axleBodyDef.position.Set2(cocheBody.getWorldPoint(punto))
    Dim frontAxle As lgBox2DBody = World.createBody(axleBodyDef)
    frontAxle.createFixture(axleFixture)
       
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '                Wheels
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Dim escalaRuedas As Float = 1
   
    texturaRuedas.Initialize("rueda.png")
   
    Dim fd As lgBox2DFixtureDef
    fd.Density = 5
    fd.Friction = 5
    fd.Restitution = 0.1
    fd.filter.groupIndex = -1   
    Dim wheelBodyDef As lgBox2DBodyDef
    wheelBodyDef.Type = World.BODYTYPE_Dynamic
    wheelBodyDef.angularDamping = 1.0
    Dim punto As lgMathVector2
    'la trasera
    punto.Set(0.13* escalaCoche,0.045* escalaCoche)
    wheelBodyDef.position.Set2(cocheBody.getWorldPoint(punto))       
    rearWheel = World.CreateBody (wheelBodyDef)
    Loader.AttachFixture(rearWheel,"rueda",fd,escalaRuedas)
    'la delantera
    punto.Set(0.81* escalaCoche,0.045* escalaCoche)
    wheelBodyDef.position.Set2(cocheBody.getWorldPoint(punto))       
    frontWheel = World.CreateBody (wheelBodyDef)
    Loader.AttachFixture(frontWheel,"rueda",fd,escalaRuedas)
    'los sprites de las ruedas
    For i=0 To 1
        ruedasSprite(i).InitializeWithTexture(texturaRuedas)
        ruedasSprite(i).SetSize(escalaRuedas, escalaRuedas * ruedasSprite(i).Height / ruedasSprite(i).Width)
        Dim Origin As lgMathVector2
        Origin = Loader.GetOrigin("rueda", escalaRuedas)
        ruedasSprite(i).SetOrigin(Origin.X, Origin.Y)
    Next

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '                Revolute Joints
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Dim punto As lgMathVector2
    punto.Set(0,0)
    Dim rearWheelRevoluteJointDef As lgBox2DRevoluteJointDef   
    Dim frontWheelRevoluteJointDef As lgBox2DRevoluteJointDef   
   
    rearWheelRevoluteJointDef.Initialize(rearWheel,rearAxle,rearWheel.GetWorldPoint(punto))
    rearWheelRevoluteJointDef.enableMotor=True
    rearWheelRevoluteJointDef.maxMotorTorque=70
    rearWheelRevoluteJoint=World.CreateJoint(rearWheelRevoluteJointDef)

'    Dim frontWheelRevoluteJointDef As lgBox2DRevoluteJointDef   
    Dim punto As lgMathVector2
    punto.Set(0,0)
    frontWheelRevoluteJointDef.Initialize(frontWheel,frontAxle,frontWheel.GetWorldPoint(punto))
    frontWheelRevoluteJointDef.enableMotor=True
    frontWheelRevoluteJointDef.maxMotorTorque=20
    frontWheelRevoluteJoint =World.CreateJoint(frontWheelRevoluteJointDef)


    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '                Prismatic Joints
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Dim axlePrismaticJointDef As lgBox2DPrismaticJointDef
   
    axlePrismaticJointDef.lowerTranslation = -0.3
    axlePrismaticJointDef.upperTranslation = 0.05
    axlePrismaticJointDef.enableLimit = True
    axlePrismaticJointDef.enableMotor = True
    ' front axle
    punto.Set(0,0)
    Dim direccion As lgMathVector2
    direccion.Set(-0.5,1)
    direccion.nor
    axlePrismaticJointDef.Initialize(cocheBody,frontAxle,frontAxle.GetWorldPoint(punto),direccion)
    frontAxlePrismaticJoint = World.CreateJoint(axlePrismaticJointDef)
   
    ' rear axle
    direccion.Set(0.5,1)
    direccion.nor
    axlePrismaticJointDef.Initialize(cocheBody,rearAxle,rearAxle.GetWorldPoint(punto),direccion)
   
    rearAxlePrismaticJoint  = World.CreateJoint(axlePrismaticJointDef)

I hope you understand it, it's a mix of spanish and english :p
It was my first use of Box2D, so maybe now I'd do it different (I started the catapult and this one at the same time, then I decided to focus on the catapult one as I tought it would be easier)
 

ilan

Expert
Licensed User
Longtime User
That sounds great!

I do not know either.
BTW, are you using Fixed timestep in your Box2d games?
I mean the step used in Box2DLights demos, because some days ago I tested my game in a tablet that can go only 55 FPS and the game felt a bit slower...


Here you go:

B4X:
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '                Car Body
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Dim escalaCoche As Int = 3
    Dim bd As lgBox2DBodyDef
    bd.Position.Set(18, 2)
    bd.Type = World.BODYTYPE_Dynamic
    Dim fd As lgBox2DFixtureDef
    fd.Density = 5
    fd.Friction = 0.8
    fd.Restitution = 0.2
    fd.filter.groupIndex = -1
  
    cocheBody= World.CreateBody (bd)
    Loader.AttachFixture(cocheBody,"coche",fd,escalaCoche)
    cocheTextura.Initialize("body2.png")
  
    cocheSprite.InitializeWithTexture(cocheTextura)
    cocheSprite.SetSize(escalaCoche, escalaCoche * cocheSprite.Height / cocheSprite.Width)
    Dim Origin As lgMathVector2
    Origin = Loader.GetOrigin("coche", escalaCoche)
    cocheSprite.SetOrigin(Origin.X, Origin.Y)
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '                Axis
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Dim axleShape As lgBox2DPolygonShape
    Dim V1, V2 As lgMathVector2
    axleShape.SetAsBox(0.2,0.2)
  
    Dim axleFixture As lgBox2DFixtureDef
    axleFixture.Density = 0.5
    axleFixture.Friction = 3  
    axleFixture.Restitution = 0.1
    axleFixture.shape = axleShape
    axleFixture.filter.groupIndex = -1

    Dim axleBodyDef As lgBox2DBodyDef
    axleBodyDef.Type = World.BODYTYPE_Dynamic

    'Eje trasero      
    Dim punto As lgMathVector2
    punto.Set(0.13* escalaCoche,0.045* escalaCoche)  
    axleBodyDef.position.Set2(cocheBody.getWorldPoint(punto))  
    Dim rearAxle As lgBox2DBody = World.createBody(axleBodyDef)
    rearAxle.createFixture(axleFixture)

    'Eje delantero
    punto.Set(0.81* escalaCoche,0.045* escalaCoche)  
    axleBodyDef.position.Set2(cocheBody.getWorldPoint(punto))
    Dim frontAxle As lgBox2DBody = World.createBody(axleBodyDef)
    frontAxle.createFixture(axleFixture)
      
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '                Wheels
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Dim escalaRuedas As Float = 1
  
    texturaRuedas.Initialize("rueda.png")
  
    Dim fd As lgBox2DFixtureDef
    fd.Density = 5
    fd.Friction = 5
    fd.Restitution = 0.1
    fd.filter.groupIndex = -1  
    Dim wheelBodyDef As lgBox2DBodyDef
    wheelBodyDef.Type = World.BODYTYPE_Dynamic
    wheelBodyDef.angularDamping = 1.0
    Dim punto As lgMathVector2
    'la trasera
    punto.Set(0.13* escalaCoche,0.045* escalaCoche)
    wheelBodyDef.position.Set2(cocheBody.getWorldPoint(punto))      
    rearWheel = World.CreateBody (wheelBodyDef)
    Loader.AttachFixture(rearWheel,"rueda",fd,escalaRuedas)
    'la delantera
    punto.Set(0.81* escalaCoche,0.045* escalaCoche)
    wheelBodyDef.position.Set2(cocheBody.getWorldPoint(punto))      
    frontWheel = World.CreateBody (wheelBodyDef)
    Loader.AttachFixture(frontWheel,"rueda",fd,escalaRuedas)
    'los sprites de las ruedas
    For i=0 To 1
        ruedasSprite(i).InitializeWithTexture(texturaRuedas)
        ruedasSprite(i).SetSize(escalaRuedas, escalaRuedas * ruedasSprite(i).Height / ruedasSprite(i).Width)
        Dim Origin As lgMathVector2
        Origin = Loader.GetOrigin("rueda", escalaRuedas)
        ruedasSprite(i).SetOrigin(Origin.X, Origin.Y)
    Next

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '                Revolute Joints
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Dim punto As lgMathVector2
    punto.Set(0,0)
    Dim rearWheelRevoluteJointDef As lgBox2DRevoluteJointDef  
    Dim frontWheelRevoluteJointDef As lgBox2DRevoluteJointDef  
  
    rearWheelRevoluteJointDef.Initialize(rearWheel,rearAxle,rearWheel.GetWorldPoint(punto))
    rearWheelRevoluteJointDef.enableMotor=True
    rearWheelRevoluteJointDef.maxMotorTorque=70
    rearWheelRevoluteJoint=World.CreateJoint(rearWheelRevoluteJointDef)

'    Dim frontWheelRevoluteJointDef As lgBox2DRevoluteJointDef  
    Dim punto As lgMathVector2
    punto.Set(0,0)
    frontWheelRevoluteJointDef.Initialize(frontWheel,frontAxle,frontWheel.GetWorldPoint(punto))
    frontWheelRevoluteJointDef.enableMotor=True
    frontWheelRevoluteJointDef.maxMotorTorque=20
    frontWheelRevoluteJoint =World.CreateJoint(frontWheelRevoluteJointDef)


    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '                Prismatic Joints
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Dim axlePrismaticJointDef As lgBox2DPrismaticJointDef
  
    axlePrismaticJointDef.lowerTranslation = -0.3
    axlePrismaticJointDef.upperTranslation = 0.05
    axlePrismaticJointDef.enableLimit = True
    axlePrismaticJointDef.enableMotor = True
    ' front axle
    punto.Set(0,0)
    Dim direccion As lgMathVector2
    direccion.Set(-0.5,1)
    direccion.nor
    axlePrismaticJointDef.Initialize(cocheBody,frontAxle,frontAxle.GetWorldPoint(punto),direccion)
    frontAxlePrismaticJoint = World.CreateJoint(axlePrismaticJointDef)
  
    ' rear axle
    direccion.Set(0.5,1)
    direccion.nor
    axlePrismaticJointDef.Initialize(cocheBody,rearAxle,rearAxle.GetWorldPoint(punto),direccion)
  
    rearAxlePrismaticJoint  = World.CreateJoint(axlePrismaticJointDef)

I hope you understand it, it's a mix of spanish and english :p
It was my first use of Box2D, so maybe now I'd do it different (I started the catapult and this one at the same time, then I decided to focus on the catapult one as I tought it would be easier)


thank you, i will study your code and compare it with mine. you are right, that kind of game is not a simple project for the first box2d game :confused:
maybe i should start with a simpler one
 

wonder

Expert
Licensed User
Longtime User
I dont think that i will make games in the future without using box2d + libgdx.
Indeed, Box2D is awesome! I think I will follow your path as well, Ilan.
I'm kind of okay with writing my own physics, but the collision detection is what kills me.

My goal for 2017 is to be working with Unreal Engine 4 / C++ on the PC and B4A / C++ / libGDX / Box2D on Android. :)

By the way, what kind of gravity do you have in your game, Earth gravity?
 

ilan

Expert
Licensed User
Longtime User
By the way, what kind of gravity do you have in your game, Earth gravity?

I use meters as units for my box2d world. Like this you can use real world units.

My gravity y is -10 (i know the gravity should be -9.8) i am still in building process will probalbly change it to -9.8
 
Top