Durdles - 2-Player Action Game
import QtQuick 2.0
import Felgo 4.0
import "../levels"
import ".."
EntityBase {
id: player
variationType: "playerRed"
entityType: "player"
property bool onLake: false
property int life: GameInfo.maxEnergy
property bool activateShield: false
property int activeShieldCounter: 0
property bool activateAccelerator: false
property int activeAcceleratorCounter: 0
property bool activatePowershot: false
property int activePowershotCounter: 0
property int stdTimeDistanceBetweenBullets: 500
property int minTimeDistanceBullet: stdTimeDistanceBetweenBullets
property bool activateHitShield: false
property int activeHitShieldCounter: 0
property alias tank: tank
property string bodySource
property string headSource
property alias winnerSound: winnerSound
GameSoundEffect {
volume: 0.3
id: winnerSound
source: Qt.resolvedUrl("../../assets/snd/Winner.wav")
}
Tank {
property bool currentlyBeaming: false
id: tank
rotation: 0
tankBody.source: variationType === "tankBlue" ? "../../assets/img/BlueBody.gif" : "../../assets/img/RedBody.gif"
tankHead.source: variationType === "tankBlue" ? "../../assets/img/BlueHead.gif" : "../../assets/img/RedHead.gif"
}
Timer {
id: timerPlayer
interval: 100; running: true; repeat: true;
onTriggered: {
if (activateShield) {
tank.shield.opacity = 1
activeShieldCounter ++;
}
if (activeShieldCounter === 80) {
activateShield = false;
activeShieldCounter = 0;
}
if (activateShield == false) {
tank.shield.opacity = 0
}
if (activateAccelerator) {
activeAcceleratorCounter ++;
minTimeDistanceBullet = 20;
tank.fire.opacity = 1
}
if (activeAcceleratorCounter === 80) {
activateAccelerator = false;
activeAcceleratorCounter = 0;
minTimeDistanceBullet = stdTimeDistanceBetweenBullets;
}
if (activateAccelerator == false) {
tank.fire.opacity = 0
}
if (activatePowershot) {
activePowershotCounter ++
}
if (activePowershotCounter === 80) {
activatePowershot = false; activePowershotCounter = 0;
}
if (activateHitShield) {
activeHitShieldCounter ++;
tank.opacity = 0.2;
}
if (activeHitShieldCounter === 10) {
activateHitShield = false;
activeHitShieldCounter = 0;
tank.opacity = 1;
}
}
}
GameSoundEffect {
volume: 0.3
id: screamSound1
source: Qt.resolvedUrl("../../assets/snd/Injury1.wav")
}
GameSoundEffect {
volume: 0.3
id: screamSound2
source: Qt.resolvedUrl("../../assets/snd/Injury2.wav")
}
function onDamage() {
onDamageWithBulletType(0)
}
function scream() {
var random = Math.floor(Math.random() * 2) + 1
if (random == 1){
screamSound1.play()
}else{
screamSound2.play()
}
}
function onDamageWithBulletType(bulletType) {
if (activateHitShield || tank.currentlyBeaming) {
return
}
var damage = 0;
switch (bulletType) {
case 0:
damage = GameInfo.normalDamage;
break;
case 1:
damage = GameInfo.powerDamage;
break;
default:
damage = GameInfo.normalDamage;
break;
}
if (activateShield) {
damage = damage / 100.0 * (100 - GameInfo.shieldDamageReduction)
}
if (!GameInfo.gameOver){
life = life - damage;
}
activateHitShield = true
scream()
if (life <= 0) {
endGame()
}
}
function endGame(){
if (variationType == "playerBlue"){
GameInfo.winnerRed = true
GameInfo.redVictory += 1
GameInfo.winner = "Red"
}else if (variationType == "playerRed"){
GameInfo.winnerRed = false
GameInfo.blueVictory += 1
GameInfo.winner = "Blue"
}
winnerSound.play()
GameInfo.gamePaused = true
GameInfo.gameOver = true
entityManager.getEntityById("tankRed").circleCollider.linearDamping = 2000
entityManager.getEntityById("tankBlue").circleCollider.linearDamping = 2000
entityManager.getEntityById("tankRed").tankBody.playing = false
entityManager.getEntityById("tankBlue").tankBody.playing = false
var toRemoveEntityTypes = ["powAccelerator", "powLifeUp", "powPowershot", "powShield", "singleBullet", "singleBulletOpponent"];
entityManager.removeEntitiesByFilter(toRemoveEntityTypes);
}
function reset(){
player.onLake = false;
player.life = GameInfo.maxEnergy;
tank.x = tank.originX;
tank.y = tank.originY;
if(variationType == "playerRed"){
tank.tankBody.rotation = 0;
tank.tankCannon.rotation = 90;
tank.rotation = 0;
}else if (variationType == "playerBlue"){
tank.tankBody.rotation = 180
tank.tankCannon.rotation = 270
tank.rotation = 0;
}
activateShield = false
activeShieldCounter = 0
activateAccelerator = false
activeAcceleratorCounter = 0
activatePowershot = false
activePowershotCounter = 0
stdTimeDistanceBetweenBullets = 500
minTimeDistanceBullet = stdTimeDistanceBetweenBullets
activateHitShield = false