Forums

OverviewV-Play 1 SupportPlatform Game, with large worlds › Reply To: Platform Game, with large worlds

OverviewV-Play 1 SupportPlatform Game, with large worlds › Reply To: Platform Game, with large worlds
#6069

Alex
V-Play Team

Hi,

of course it is possible :)

There is already a platformer made with V-Play in the app stores, Chicken Outbreak, which is also available as game template within the SDK.

We also have a Camera component which is already available but not yet announced or documented because zooming is not fully implemented (but i guess you don’t need to zoom anyway). You can find its sources here: PathToYourV-PlaySDK\Desktop\V-PlaySDK\qml\VPlay\core\Camera.qml

And another option for you, i made this short example for you to check out or even take as a base for your own platformer.

main.qml

import VPlay 1.0
import QtQuick 1.1

GameWindow {
  width: 320
  height: 480
  EntityManager {
    id: entityManager
    entityContainer: level
  }
  Scene {
    id: scene
    width: 320
    height: 480
    gridSize: 32

    PhysicsWorld {
      gravity.y: -10
      updatesPerSecondForPhysics: 60
      velocityIterations: 5
      positionIterations: 5
    }

    Item {
      id: level
      y: -player.y+scene.height/2

      Adventurer {
        id: player
        x: scene.gridSize*5
        y: scene.gridSize*8
      }
      Repeater {
        model: 20
        Block {
          x: scene.gridSize*5
          y: scene.gridSize*10-scene.gridSize*index*4
        }
      }
    }

    MultiTouchArea {
      anchors.fill: parent
      onClicked: {
        player.jump()
      }
      onSwipeUp: {
        player.superJump()
      }
    }
  }
}

Adventurer.qml

import QtQuick 1.1
import VPlay 1.0

EntityBase {
  id: player
  entityType: "player"

  width: scene.gridSize-2
  height: scene.gridSize-2

  property alias collider: collider

  Rectangle {
    width: parent.width
    height: parent.height
    color: "red"
  }

  BoxCollider {
    id: collider
    anchors.fill: parent
    categories: Box.Category1
  }

  function jump() {
    var localForward = collider.body.getWorldVector(Qt.point(0,-300));
    collider.body.applyLinearImpulse(localForward, collider.body.getWorldCenter());
  }

  function superJump() {
    var localForward = collider.body.getWorldVector(Qt.point(0,-415));
    collider.body.applyLinearImpulse(localForward, collider.body.getWorldCenter());
  }
}

Block.qml

import QtQuick 1.1
import VPlay 1.0

EntityBase {
  id: block
  entityType: "block"

  width: scene.gridSize
  height: scene.gridSize

  signal blockClicked
  signal blockDestroyed

  Rectangle {
    width: parent.width
    height: parent.height
    color: "blue"
  }

  BoxCollider {
    anchors.fill: parent
    bodyType: Body.Static
    // set this to true by default so the player can jump through blocks
    collisionTestingOnlyMode: true
    fixture.onBeginContact: {
      // if a block collides with a player, check if the player is above the block, in this case deactivate
      // the testing mode so the player stays on the block
      if(player.y <= block.y) collisionTestingOnlyMode = false
    }

    fixture.onEndContact: {
      // as soon as the player leaves the block we can switch to testing mode again
      collisionTestingOnlyMode = true
    }
  }
}

 

When you run this example, you can either click the screen to do a normal jump, or swipe up for a superjump. The player will always be centered in the screen and the level is moved accordingly to the players y-value with one simple property binding:

Item {
  id: level
  y: -player.y+scene.height/2
  // ...
}

I hope this helps you :)

Cheers,
Alex

 

 

 

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support