/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
import QtQuick 2.0
import "../logic.js" as Logic
import ".."
Item {
id: container
property stringname: "Fish"
property intcol: 0
property realhp: 3
property realdamage: 1
property realspeed: 0.25
property introf: 30//In ticks
property intfireCounter: 0
property booldying: falsewidth: parent ? parent.squareSize : 0height: parent ? parent.squareSize : 0x: col*widthz: 1001functionfire() { }
functiondie() {
if (dying)
return;
dying=true;
bubble.jumpTo("burst");
if (fishSprite.currentSprite=="front")
fishSprite.jumpTo(Math.random() >0.5 ? "left" : "right" );
fishSwim.start();
Logic.gameState.score+=1;
killedSound.play();
bubble.scale=0.9destroy(350);
}
functioninked() {
if (hp>0)
ink.jumpTo("dirty");
}
functionhit(dmg) {
hp-=dmg;
if (hp<=0)
Logic.killMob(col, container);
}
Component.onCompleted: spawnSound.play()
SoundEffect {
id: spawnSoundsource: "../audio/catch.wav"
}
SoundEffect {
id: killedSoundsource: "../audio/catch-action.wav"
}
SpriteSequence {
id: fishSpritewidth: 64height: 64interpolate: falsegoalSprite: ""Sprite {
name: "left"source: "../gfx/mob-idle.png"frameWidth: 64frameHeight: 64frameCount: 1frameDuration: 800frameDurationVariation: 400to: { "front" : 1 }
}
Sprite {
name: "front"source: "../gfx/mob-idle.png"frameCount: 1frameX: 64frameWidth: 64frameHeight: 64frameDuration: 800frameDurationVariation: 400to: { "left" : 1, "right" : 1 }
}
Sprite {
name: "right"source: "../gfx/mob-idle.png"frameCount: 1frameX: 128frameWidth: 64frameHeight: 64frameDuration: 800frameDurationVariation: 400to: { "front" : 1 }
}
Sprite { //WORKAROUND: This prevents the triggering of a rendering error which is currently under investigation.name: "dummy"source: "../gfx/melee-idle.png"frameCount: 8frameWidth: 64frameHeight: 64frameX: 0frameDuration: 200
}
NumberAnimation on x {
id: fishSwimrunning: false
property boolgoingLeft: fishSprite.currentSprite=="right"to: goingLeft ? -360 : 360duration: 300
}
}
SpriteSequence {
id: bubblewidth: 64height: 64scale: 0.4+ (0.2*hp)
interpolate: falsegoalSprite: ""
Behavior on scale {
NumberAnimation { duration: 150; easing.type: Easing.OutBack }
}
Sprite {
name: "big"source: "../gfx/catch.png"frameCount: 1to: { "burst" : 0 }
}
Sprite {
name: "burst"source: "../gfx/catch-action.png"frameCount: 3frameX: 64frameDuration: 200
}
Sprite { //WORKAROUND: This prevents the triggering of a rendering error which is currently under investigation.name: "dummy"source: "../gfx/melee-idle.png"frameCount: 8frameWidth: 64frameHeight: 64frameX: 0frameDuration: 200
}
SequentialAnimation on width {
loops: Animation.InfiniteNumberAnimation { from: width*1; to: width*1.1; duration: 800; easing.type: Easing.InOutQuad }
NumberAnimation { from: width*1.1; to: width*1; duration: 1000; easing.type: Easing.InOutQuad }
}
SequentialAnimation on height {
loops: Animation.InfiniteNumberAnimation { from: height*1; to: height*1.15; duration: 1200; easing.type: Easing.InOutQuad }
NumberAnimation { from: height*1.15; to: height*1; duration: 1000; easing.type: Easing.InOutQuad }
}
}
SpriteSequence {
id: inkwidth: 64height: 64scale: bubble.scalegoalSprite: ""Sprite {
name: "clean"source: "../gfx/projectile-action.png"frameCount: 1frameX: 0frameWidth: 64frameHeight: 64
}
Sprite {
name: "dirty"source: "../gfx/projectile-action.png"frameCount: 3frameX: 64frameWidth: 64frameHeight: 64frameDuration: 150to: {"clean":1}
}
Sprite { //WORKAROUND: This prevents the triggering of a rendering error which is currently under investigation.name: "dummy"source: "../gfx/melee-idle.png"frameCount: 8frameWidth: 64frameHeight: 64frameX: 0frameDuration: 200
}
SequentialAnimation on width {
loops: Animation.InfiniteNumberAnimation { from: width*1; to: width*1.1; duration: 800; easing.type: Easing.InOutQuad }
NumberAnimation { from: width*1.1; to: width*1; duration: 1000; easing.type: Easing.InOutQuad }
}
SequentialAnimation on height {
loops: Animation.InfiniteNumberAnimation { from: height*1; to: height*1.15; duration: 1200; easing.type: Easing.InOutQuad }
NumberAnimation { from: height*1.15; to: height*1; duration: 1000; easing.type: Easing.InOutQuad }
}
}
SequentialAnimation on x {
loops: Animation.InfiniteNumberAnimation { from: x; to: x-5; duration: 900; easing.type: Easing.InOutQuad }
NumberAnimation { from: x-5; to: x; duration: 900; easing.type: Easing.InOutQuad }
}
}