Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Durdles - 2-Player Action Game

 import QtQuick 2.0
 import Felgo 4.0
 import "../.."

 // the lifeUp powerUp refills a quarter of the player's health meter
 EntityBase {
   id: powLifeUp
   entityType: "powLifeUp"
   width: 25
   height: 25

   // count entities on the field
   onEntityCreated: GameInfo.powerUpCount+=1

   AnimatedImage {
     id: powLifeUpImage
     width: parent.width
     height: parent.height
     source: Qt.resolvedUrl("../../../assets/img/PULife.gif")
     anchors.centerIn: parent
     playing: true
   }

   BoxCollider {
     id: boxCollider
     anchors.fill: powLifeUpImage
     anchors.centerIn: parent
     sensor:true

     fixture.onBeginContact: (other, contactNormal) => {
       // the powerUp collides with the child collider of the player
       var collidedEntity = other.getBody().target;

       // if one of the players gets in contact with the shield powerUp, they regain some health and the timer resets
       // the powerUp itself gets destroyed and removed from the counter
       if (collidedEntity.isOfType("tankRed")){
         collidedEntity.plingSound.play();
         powLifeUp.destroy()
         GameInfo.powerUpCount -= 1
         collidedEntity.parent.life += GameInfo.fillEnergy

         if (collidedEntity.parent.life + GameInfo.fillEnergy > GameInfo.maxEnergy) {
           collidedEntity.parent.life = GameInfo.maxEnergy
         }
       } else if (collidedEntity.isOfType("tankBlue")){
         collidedEntity.plingSound.play()
         powLifeUp.destroy()
         GameInfo.powerUpCount -= 1
         collidedEntity.parent.life += GameInfo.fillEnergy

         if (collidedEntity.parent.life + GameInfo.fillEnergy > GameInfo.maxEnergy) {
           collidedEntity.parent.life = GameInfo.maxEnergy
         }
       }
Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded