Durdles - 2-Player Action Game
import QtQuick 2.0
import Felgo 4.0
import "../common" as Common
import ".."
import "../entities"
import "../entities/powerUps"
import "../scenes"
Rectangle {
id: fireButton
radius: GameInfo.radius
opacity: GameInfo.opacity
color: "transparent"
width: 90
height: 90
property var player
property var tank
property alias snowballSound1: snowballSound1
property alias snowballSound2: snowballSound2
property alias snowballSound3: snowballSound3
property alias icicleSound1: icicleSound1
property alias icicleSound2: icicleSound2
property alias icicleSound3: icicleSound3
Image {
id: fireImage
source: GameInfo.easyMode ? "../../assets/img/FireEasy.png" : "../../assets/img/FireHard.png"
anchors.centerIn: parent
width: parent.width
height: parent.height
anchors.fill: parent
}
MultiPointTouchArea {
z: 2
id: easyTouchControls
enabled: !GameInfo.gamePaused && GameInfo.easyMode ? true : false
anchors.fill: parent
touchPoints: [
TouchPoint {id: fireTouchPoint}
]
property real lastTime: 0
onPressed: {
var currentTime = new Date().getTime()
var timeDiff = currentTime - lastTime
if (timeDiff > player.minTimeDistanceBullet) {
lastTime = currentTime
if (player.activatePowershot){
icicle()
}else{
snowball()
}
tank.tankHead.playing=true
var speed = (player.activateAccelerator) ? 240 : 120
var rotation = tank.tankBody.rotation + 90
var xDirection = Math.cos(rotation * Math.PI / 180.0) * speed
var yDirection = Math.sin(rotation * Math.PI / 180.0) * speed
var startX = (16 * Math.cos((rotation) * Math.PI / 180)) + tank.x + tank.width / 2
var startY = (16 * Math.sin((rotation) * Math.PI / 180)) + tank.y + tank.height / 2
entityManager.createEntityFromUrlWithProperties(Qt.resolvedUrl("../entities/Bullet.qml"), {
"start" : Qt.point(startX, startY),
"velocity" : Qt.point(xDirection, yDirection),
"rotation" : tank.tankBody.rotation + 180,
"bulletType" : player.activatePowershot ? 1 : 0});
}
}
}
MultiPointTouchArea {
z: 2
id: hardTouchControls
enabled: !GameInfo.gamePaused && !GameInfo.easyMode ? true : false
anchors.fill: parent
property bool pressBool: false
property var lastTime: 0
property variant playerTwoAxisController: tank.getComponent("TwoAxisController")
touchPoints: [
TouchPoint {id: point1}
]
onTouchUpdated: upDateCannon()
onPressed: {
pressBool = true
upDateCannon()
}
onReleased: {
var currentTime = new Date().getTime()
var timeDiff = currentTime - lastTime
if (pressBool && timeDiff > player.minTimeDistanceBullet) {
lastTime = currentTime
if (player.activatePowershot){
icicle()
}else{
snowball()
}
tank.tankHead.playing = true
var speed = (player.activateAccelerator) ? 240 : 120
var xDirection = Math.cos(tank.tankCannon.rotation * Math.PI / 180.0) * speed
var yDirection = Math.sin(tank.tankCannon.rotation * Math.PI / 180.0) * speed
var startX= (16 * Math.cos((tank.tankCannon.rotation) * Math.PI / 180)) + tank.x + tank.width / 2
var startY= (16 * Math.sin((tank.tankCannon.rotation) * Math.PI / 180)) + tank.y + tank.height / 2
entityManager.createEntityFromUrlWithProperties(Qt.resolvedUrl("../entities/Bullet.qml"), {
"start" : Qt.point(startX, startY),
"velocity" : Qt.point(xDirection, yDirection),
"rotation" : tank.tankCannon.rotation + 90,
"bulletType" : player.activatePowershot ? 1 : 0});
}
pressBool= false
}
}
GameSoundEffect {
volume: 0.3
id: snowballSound1
source: Qt.resolvedUrl("../../assets/snd/Snow1.wav")
}
GameSoundEffect {
volume: 0.3
id: snowballSound2
source: Qt.resolvedUrl("../../assets/snd/Snow2.wav")
}
GameSoundEffect {
volume: 0.3
id: snowballSound3
source: Qt.resolvedUrl("../../assets/snd/Snow3.wav")
}
GameSoundEffect {
volume: 0.3
id: icicleSound1
source: Qt.resolvedUrl("../../assets/snd/Icicle1.wav")
}
GameSoundEffect {
volume: 0.3
id: icicleSound2
source: Qt.resolvedUrl("../../assets/snd/Icicle2.wav")
}
GameSoundEffect {
volume: 0.3
id: icicleSound3
source: Qt.resolvedUrl("../../assets/snd/Icicle3.wav")
}
function snowball() {
var random = Math.floor(Math.random() * 3) + 1
if (random==1) snowballSound1.play()
if (random==2) snowballSound2.play()
if (random==3) snowballSound3.play()
}
function icicle() {
var random = Math.floor(Math.random() * 3) + 1
if (random==1) icicleSound1.play()
if (random==2) icicleSound2.play()
if (random==3) icicleSound3.play()
}
function upDateCannon(){
var x = point1.x
var y = point1.y
x = x - (fireButton.width / 2)
y = (y - (fireButton.height / 2)) * (-1)
var angle = calcAngle(x, y)
tank.tankCannon.rotation = angle
}
function calcAngle(touchX, touchY) {