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 3.0
 import ".."
 import "../entities"
 import "../controls"

 Item {
   id: levelBaseScene
   width: 320
   height: 480
   state: "0"

   // access the variables from the outside
   property alias playerRed: playerRed
   property alias playerBlue: playerBlue
   property alias tankRed: playerRed.tank
   property alias tankBlue: playerBlue.tank

   // used to anchor items to the main gameWindowAnchorItem
   Item {
     id: gameWindowAnchorItem
     x: gameScene.gameWindowAnchorItem.x
     y: gameScene.gameWindowAnchorItem.y
     width: gameScene.gameWindowAnchorItem.width
     height: gameScene.gameWindowAnchorItem.height
   }

   // show the game over message at the end of each game
   Rectangle {
     z: 20
     id: gameOver
     color: "white"
     anchors.centerIn: parent
     width: 200
     height: 80
     radius: 10
     border.width: GameInfo.border
     border.color: "lightgrey"
     opacity: GameInfo.gameOver ? 100 : 0

     // game over message in the color of the winner
     Text {
       id: textWinner
       text: "The winner of the round is <b>" + GameInfo.winner + "</b>"
       color: GameInfo.winnerRed ? GameInfo.red : GameInfo.blue
       anchors.horizontalCenter: parent.horizontalCenter
       anchors.top: parent.top
       anchors.topMargin: 18
       font.pixelSize: 14
       font.family: standardFont.name
     }

     // game statistic
     Text {
       id: textStatistic
       text: "Blue: " + GameInfo.blueVictory + "<br>Red: " + GameInfo.redVictory
       font.pixelSize: 12
       anchors.horizontalCenter: parent.horizontalCenter
       anchors.bottom: parent.bottom
       anchors.bottomMargin: 14
       horizontalAlignment:  Text.AlignHCenter
       font.family: standardFont.name
     }
   }

   // back button to leave scene
   MenuButton {
     label.height: 45
     label.width: 45
     label.source: "../../assets/img/Back.png"
     color: "transparent"
     z: 10
     anchors.right: gameWindowAnchorItem.right
     anchors.verticalCenter: gameWindowAnchorItem.verticalCenter
     onClicked: {
       resetLevel()
       gameScene.backButtonPressed()
     }
   }

   // background
   Image {
     z: -2
     id:background
     source: "../../assets/img/GameBG.png"

     // use this if the image should be centered, which is the most common case
     // if the image should be aligned at the bottom, probably the whole scene should be aligned at the bottom, and the image should be shited up by the delta between the imagesSize and the scene.y!
     anchors.centerIn: parent
     scale: 0.5
   }

   // PLAYER RED
   // player and tank
   Player {
     z: 2
     id: playerRed
     entityType: "player"
     variationType: "playerRed"
     tank.entityId: "tankRed"
     tank.variationType: "tankRed"
     tank.originX: gameScene.width / 2
     tank.originY: 50 + height / 2
     tank.rotation: 0
   }

   // movement controls
   Movement {
     z: 2
     id: movementRed
     player: playerRed
     tank: playerRed.tank
     originX: gameWindowAnchorItem.width - playerMovementImage.width - 10
     originY: 10
     anchors{
       left: gameWindowAnchorItem.left
       right: gameWindowAnchorItem.right
       top: gameWindowAnchorItem.top
     }
     height: gameWindowAnchorItem.height / 2
   }

   // easy and hard shot controls
   Shot {
     z: 2
     id: shotRed
     player: playerRed
     tank: playerRed.tank
     anchors {
       top: gameWindowAnchorItem.top
       topMargin: 10
       left: gameWindowAnchorItem.left
       leftMargin: 10
     }
   }

   // energy bar
   EnergyBar {
     z: 2
     energy: playerRed.life
     id: energyBarRed
     barColor: GameInfo.red
     anchors {
       horizontalCenter: gameWindowAnchorItem.horizontalCenter
       top: gameWindowAnchorItem.top
       topMargin: 10
     }
   }

   // PLAYER BLUE
   // player and tank
   Player {
     id: playerBlue
     entityType: "player"
     variationType: "playerBlue"
     tank.entityId: "tankBlue"
     tank.variationType: "tankBlue"
     tank.originX: gameScene.width / 2
     tank.originY: gameScene.height - 50 - height/2
     tank.rotation: 0
   }

   // movement controls
   Movement {
     id: movementBlue
     z: 2
     player: playerBlue
     tank: playerBlue.tank
     originX: 10
     originY: height - playerMovementImage.height - 10
     anchors {
       bottom: gameWindowAnchorItem.bottom
       left: gameWindowAnchorItem.left
       right: gameWindowAnchorItem.right
     }
     height: gameWindowAnchorItem.height/2
   }

   // shot controls
   Shot {
     z: 2
     id: shotBlue
     player: playerBlue
     tank: playerBlue.tank
     anchors {
       bottom: gameWindowAnchorItem.bottom
       bottomMargin: 10
       right: gameWindowAnchorItem.right
       rightMargin: 10
     }
   }

   // energy bar
   EnergyBar {
     z: 2
     energy: playerBlue.life
     id: energyBarBlue
     barColor: GameInfo.blue
     anchors {
       horizontalCenter: gameWindowAnchorItem.horizontalCenter
       bottom: gameWindowAnchorItem.bottom
       bottomMargin: 10
     }
   }

   // place the 4 walls
   Wall {
     id: wallLeft
     width: 15
     z: 1
     anchors {
       left: gameWindowAnchorItem.left//gameWindowAnchorItem.left
       top: gameWindowAnchorItem.top
       bottom: gameWindowAnchorItem.bottom
     }
     image.source: "../../assets/img/Wall2.png"
     image.rotation: 180
   }

   Wall {
     id: wallRight
     width: 15
     z: 1
     anchors {
       right: gameWindowAnchorItem.right
       bottom: gameWindowAnchorItem.bottom
       top: gameWindowAnchorItem.top
     }
     image.source: "../../assets/img/Wall2.png"
   }

   Wall {
     id: wallBottom
     height: 15
     z: 1
     anchors {
       left: gameWindowAnchorItem.left
       right: gameWindowAnchorItem.right
       bottom: gameWindowAnchorItem.bottom
     }
     image.source: "../../assets/img/Wall.png"
   }

   Wall {
     id: wallTop
     height: 15
     z: 1
     anchors {
       left: gameWindowAnchorItem.left
       right: gameWindowAnchorItem.right
       top:gameWindowAnchorItem.top
     }
     image.source: "../../assets/img/Wall.png"
     image.rotation: 180
   }

   // reset all game variables and player components
   function resetLevel(){
     activeLevelFileName = ""
     GameInfo.gameOver = false
     GameInfo.gamePaused = false
     GameInfo.testLevel = false;
     GameInfo.powerUpCount = 0;
     var toRemoveEntityTypes = ["powAccelerator", "powLifeUp", "powPowershot", "powShield", "singleBullet", "singleBulletOpponent"];
     entityManager.removeEntitiesByFilter(toRemoveEntityTypes);

     playerRed.reset();
     playerBlue.reset();
     movementRed.reset();
Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded