Durdles - 2-Player Action Game
import QtQuick 2.0
import Felgo 4.0
import "../levels"
EntityBase {
id: iglu
entityId: "iglu"
entityType: "iglu"
width: 75
height: 90
z: 5
property alias igluBody: igluBody
property alias porter: porter
property alias rectColliderLeft: rectColliderLeft
property alias rectColliderRight: rectColliderRight
property alias rectColliderBottom: rectColliderBottom
property alias teleportSound: teleportSound
property alias glowTimer: glowTimer
GameSoundEffect {
volume: 0.3
id: teleportSound
source: Qt.resolvedUrl("../../assets/snd/Teleport.wav")
}
Image {
z: 10
id: igluBody
width: parent.width
height: parent.height
anchors.centerIn: parent
}
PolygonCollider {
bodyType: Body.Static
id: rectColliderLeft
anchors.centerIn: parent
vertices: [
Qt.point(igluBody.x + igluBody.width/5, igluBody.y),
Qt.point(igluBody.x, igluBody.y + igluBody.height/2),
Qt.point(igluBody.x + igluBody.width/7, igluBody.y + igluBody.height/7*6),
Qt.point(igluBody.x + igluBody.width/2, igluBody.y+igluBody.height)
]
transform: Rotation {
origin.x: iglu.width / 2
origin.y: iglu.width / 2
angle: 135
}
}
PolygonCollider {
bodyType: Body.Static
id: rectColliderRight
vertices: [
Qt.point(igluBody.x + igluBody.width/5*4, igluBody.y),
Qt.point(igluBody.x + igluBody.width, igluBody.y + igluBody.height/2),
Qt.point(igluBody.x + igluBody.width/7*6, igluBody.y + igluBody.height/7*6),
Qt.point(igluBody.x+igluBody.width/2, igluBody.y+igluBody.height)
]
anchors.centerIn: parent
}
PolygonCollider {
bodyType: Body.Static
id: rectColliderBottom
vertices: [
Qt.point(igluBody.x + igluBody.width/5, igluBody.y + igluBody.height/5*2),
Qt.point(igluBody.x + igluBody.width/5*4, igluBody.y + igluBody.height/5*2),
Qt.point(igluBody.x+igluBody.width/2, igluBody.y+igluBody.height)
]
anchors.centerIn: parent
}
Timer {
id: teleportTimerPlayerBlue
interval: 750
running: false
repeat: false
property var destIglu
property var teleportedPlayer
property var destinationX
property var destinationY
onTriggered:{
teleportedPlayer.x = destinationX
teleportedPlayer.y = destinationY
teleportedPlayer.opacity = 1.0
teleportedPlayer.currentlyBeaming = false
}
}
Timer {
id: teleportTimerPlayerRed
interval: 750
running: false
repeat: false
property var destIglu
property var teleportedPlayer
property var destinationX
property var destinationY
onTriggered: {
teleportedPlayer.x = destinationX
teleportedPlayer.y = destinationY
teleportedPlayer.opacity = 1.0
teleportedPlayer.currentlyBeaming = false
}
}
Timer {
id: glowTimer
interval: 250
running: false
repeat: true
property int glowCounter: 0
onTriggered:{
if (glowCounter % 2 == 0){
igluBody.source= "../../assets/img/IgluLight.png"
}else{
igluBody.source= "../../assets/img/Iglu.png"
}
glowCounter++
if (glowCounter>=4) {
glowCounter=0
igluBody.source= "../../assets/img/Iglu.png"
glowTimer.running=false
}
}
}
BoxCollider {
id: porter
width: igluBody.width/2
height: igluBody.height/2
anchors.centerIn: parent
collisionTestingOnlyMode: true
fixture.onBeginContact: (other, contactNormal) => {
var collidedEntity = other.getBody().target;
if (collidedEntity.isOfType("tank")) {
teleportSound.play()
collidedEntity.x = scene.x - 200
collidedEntity.y = scene.y - 200
var iglus = entityManager.getEntityArrayByType("iglu")
var random = Math.floor(Math.random() * (iglus.length))
var destinationIglu = iglus[random]
while(iglu.entityId == destinationIglu.entityId) {
random = Math.floor(Math.random() * (iglus.length))
destinationIglu = iglus[random]
}
var destinationX = (40 * Math.cos((destinationIglu.rotation - 10) * Math.PI / 180)) + destinationIglu.x + tankRed.width / 2
var destinationY = (40 * Math.sin((destinationIglu.rotation - 10) * Math.PI / 180)) + destinationIglu.y + tankRed.width / 2
collidedEntity.opacity = 0.0
destinationIglu.glowTimer.running=true
if (collidedEntity.isOfType("tankRed")) {
collidedEntity.currentlyBeaming = true
teleportTimerPlayerRed.destinationX = destinationX
teleportTimerPlayerRed.destinationY = destinationY
teleportTimerPlayerRed.destIglu = destinationIglu
teleportTimerPlayerRed.teleportedPlayer = collidedEntity
teleportTimerPlayerRed.start()
} else {
collidedEntity.currentlyBeaming = true
teleportTimerPlayerBlue.destinationX = destinationX
teleportTimerPlayerBlue.destinationY = destinationY
teleportTimerPlayerBlue.destIglu = destinationIglu
teleportTimerPlayerBlue.teleportedPlayer = collidedEntity
teleportTimerPlayerBlue.start()
}
}