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 "../../levels"
 import "../.."

 // spawns powerUps at random intervalls
 EntityBase {
   id: powerUpSpawn
   entityType: "powerUpSpawn"
   z: 2

   property alias spawnBody: spawnBody
   property alias circleCollider: circleCollider
   property alias spawnSound: spawnSound

   // the powerUps spawn at a certain distance around the powerUpSpawn
   property int minSpawnRadius: 27
   property double spawnRadiusDelta: 1.5

   // play a sound when a powerup spawns
   GameSoundEffect {
     volume: 0.3
     id: spawnSound
     // an ogg file is not playable on windows, because the extension is not supported!
     source: Qt.resolvedUrl("../../../assets/snd/Spawn.wav")
   }

   // visual representation of the PowerUpSpawn
   Image {
     id: spawnBody
     width: 40
     height: 40
     anchors.centerIn: parent
   }

   CircleCollider {
     id: circleCollider
     radius: 20
     x: -radius
     y: -radius
     bodyType: Body.Static
   }

   // pick a random time between 8 and 20 seconds
   property int timeMin: 8000
   property int timeSpan: 12000
   property int limit: Math.ceil(Math.random() * (timeSpan) + timeMin);

   Timer {
     id: timerGame
     interval: limit;
     running: GameInfo.gamePaused ? false : true;
     repeat: true;

     onTriggered: {
       // spawn items in calculated random intervals
       limit = Math.ceil(Math.random() * (timeSpan) + timeMin);

       // spawn items only when there are not already too many on the field
       if (GameInfo.powerUpCount<GameInfo.maxPowerUpsOnField){
         spawnRandomItem()
       }
     }
   }

   // create a random powerUp
   function spawnRandomItem(){
     // pick one of four types of powerUps
     var differentItems = 4
     var randomItem = Math.ceil(Math.random() * (differentItems));

     // calculate a random angle and radius
     var randomAngle = Math.ceil(Math.random() * (359));
     var radius = Math.ceil(Math.random() * (spawnRadiusDelta)) + minSpawnRadius;

     // calculate a position with the angle and radius
     var startX = (radius*Math.cos((randomAngle)*Math.PI/180)) + powerUpSpawn.x
     var startY = (radius*Math.sin((randomAngle)*Math.PI/180)) + powerUpSpawn.y

     // search for the corresponding image
     var url
     if (randomItem==1){url = "PowerUpAccelerator.qml"}
     if (randomItem==2){url = "PowerUpLifeUp.qml"}
     if (randomItem==3){url = "PowerUpPowershot.qml"}
     if (randomItem==4){url = "PowerUpShield.qml"}

     spawnSound.play()

     // create the powerUp entity
     entityManager.createEntityFromUrlWithProperties(
           Qt.resolvedUrl(url), {
             "z": 1,
             "x": startX-12,
             "y": startY-12,
           }
Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded