-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from MisterGC/feature/enemies-are-alive
Feature/enemies are alive
- Loading branch information
Showing
11 changed files
with
223 additions
and
69 deletions.
There are no files selected for viewing
Submodule clayground
updated
3 files
+36 −7 | plugins/clay_world/ClayWorld.qml | |
+2 −0 | plugins/scaling_canvas/ScalingPoly.qml | |
+4 −0 | plugins/svg_tools/svginspector.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// (c) [email protected] - zlib license, see "LICENSE" file | ||
import QtQuick 2.12 | ||
import Clayground.Physics 1.0 | ||
import Clayground.ScalingCanvas 1.0 | ||
import QtQuick.Shapes 1.14 | ||
import Box2D 2.0 | ||
|
||
Item { | ||
id: theMaster | ||
property var path: [] | ||
property var _waypoints: [] | ||
property var gameWorld: parent | ||
property var _spawned: [] | ||
onEnabledChanged: { | ||
if (enabled) spawnTimer.start(); | ||
else spawnTimer.stop(); | ||
} | ||
|
||
Component.onCompleted: { | ||
let lenWuH = 1.0; | ||
for (let i=1; i<path.length; ++i) { | ||
let p = path[i]; | ||
let ent = theWayPointComp.createObject(gameWorld.coordSys, | ||
{ | ||
world: gameWorld.physics, | ||
pixelPerUnit: gameWorld.pixelPerUnit, | ||
xWu: p.x - lenWuH, | ||
yWu: p.y + lenWuH, | ||
widthWu: 2*lenWuH, | ||
heightWu: 2*lenWuH | ||
}); | ||
_waypoints.push(ent); | ||
_spawned.push(ent); | ||
} | ||
} | ||
|
||
Component { id: theWayPointComp; Waypoint {}} | ||
Timer { | ||
id: spawnTimer | ||
interval: 10000 | ||
repeat: true | ||
onTriggered: { | ||
let enemy = theSpawner.createObject(gameWorld.coordSys, | ||
{ | ||
world: gameWorld.physics, | ||
pixelPerUnit: gameWorld.pixelPerUnit, | ||
xWu: path[0].x, | ||
yWu: path[0].y, | ||
widthWu: 5, | ||
heightWu: 5, | ||
wpPath: _waypoints | ||
}); | ||
enemy.pixelPerUnit = Qt.binding( _ => {return gameWorld.pixelPerUnit;} ); | ||
enemy.active = Qt.binding( _ => {return gameWorld.running;} ); | ||
_spawned.push(enemy); | ||
} | ||
} | ||
|
||
Component { id: theSpawner; Enemy {} } | ||
|
||
|
||
ScalingPoly { | ||
canvas: gameWorld | ||
strokeStyle: ShapePath.DashLine | ||
dashPattern: [ 1, 4 ] | ||
vertices: path | ||
strokeColor: "red" | ||
opacity: .5 | ||
} | ||
|
||
Component.onDestruction: { | ||
spawnTimer.stop() | ||
for (let i=0; i<_spawned.length; ++i) { | ||
let ent = _spawned[i]; | ||
if (typeof ent !== 'undefined' && | ||
ent.hasOwnProperty("destroy")) | ||
ent.destroy(); | ||
} | ||
_spawned = []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// (c) [email protected] - zlib license, see "LICENSE" file | ||
import QtQuick 2.12 | ||
import Clayground.Physics 1.0 | ||
import Box2D 2.0 | ||
|
||
PhysicsItem { | ||
id: thePhyItem | ||
fixtures: [ | ||
Box { | ||
sensor: true | ||
width: thePhyItem.width | ||
height: thePhyItem.height | ||
categories: collCat.waypoint | ||
collidesWith: collCat.enemy | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.