-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lewis Lepton
committed
Aug 9, 2016
1 parent
c28bbd5
commit 23886b7
Showing
3 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
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 @@ | ||
package; | ||
|
||
import kha.System; | ||
import kha.Scheduler; | ||
import kha.Assets; | ||
|
||
class Main { | ||
public static function main() { | ||
System.init({title:"041_projectSound", width:800, height:600}, function(){ | ||
Assets.loadEverything(function(){ | ||
var Project = new Project(); | ||
Scheduler.addTimeTask(Project.update, 0, 1 / 60); | ||
System.notifyOnRender(Project.render); | ||
}); | ||
}); | ||
} | ||
} |
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,97 @@ | ||
package; | ||
|
||
import kha.Framebuffer; | ||
import kha.graphics2.Graphics; | ||
import kha.Color; | ||
import kha.audio1.Audio; | ||
import kha.audio1.AudioChannel; | ||
import kha.Assets; | ||
|
||
import zui.Zui; | ||
import zui.Id; | ||
|
||
class Project { | ||
public var WIDTH = 800; | ||
public var HEIGHT = 600; | ||
|
||
public var ui:Zui; | ||
|
||
public var playThunder = false; | ||
public var thunderSound:AudioChannel; | ||
public var thunderPos:Float; | ||
|
||
public var playRain = false; | ||
public var rainSound:AudioChannel; | ||
public var rainPos:Float; | ||
|
||
public var playFire = false; | ||
public var fireSound:AudioChannel; | ||
public var firePos:Float; | ||
|
||
public function new() { | ||
ui = new Zui(Assets.fonts.quicksand, 18); | ||
|
||
thunderSound = Audio.play(Assets.sounds.thunder, true); | ||
thunderSound.pause(); | ||
rainSound = Audio.play(Assets.sounds.rain, true); | ||
rainSound.pause(); | ||
fireSound = Audio.play(Assets.sounds.fireplace, true); | ||
fireSound.pause(); | ||
} | ||
|
||
public function update():Void { | ||
thunderPos = thunderSound.position; | ||
rainPos = rainSound.position; | ||
firePos = fireSound.position; | ||
} | ||
|
||
public function render(framebuffer:Framebuffer):Void { | ||
var graphics = framebuffer.g2; | ||
graphics.begin(); | ||
soundGraphic(graphics); | ||
graphics.end(); | ||
gui(graphics); | ||
toggleStates(); | ||
} | ||
|
||
public function gui(graphics:Graphics){ | ||
ui.begin(graphics); | ||
if (ui.window(Id.window(), 0, 0, 200, HEIGHT)){ | ||
if (ui.node(Id.node(), 'thunder', 1 , true)){ | ||
thunderSound.volume = ui.slider(Id.slider(), 'volume', 0.0, 1.0, true); | ||
playThunder = ui.check(Id.check(), 'off/on'); | ||
} | ||
|
||
if (ui.node(Id.node(), 'rain', 1 , true)){ | ||
rainSound.volume = ui.slider(Id.slider(), 'volume', 0.0, 1.0, true); | ||
playRain = ui.check(Id.check(), 'off/on'); | ||
} | ||
|
||
if (ui.node(Id.node(), 'fire', 1 , true)){ | ||
fireSound.volume = ui.slider(Id.slider(), 'volume', 0.0, 1.0, true); | ||
playFire = ui.check(Id.check(), 'off/on'); | ||
} | ||
} | ||
ui.end(); | ||
} | ||
|
||
public function soundGraphic(graphics:Graphics){ | ||
graphics.color = Color.fromBytes(108, 109, 255); | ||
graphics.fillRect(200, 0, 100, thunderPos * 32); | ||
graphics.color = Color.fromBytes(129, 226, 255); | ||
graphics.fillRect(300, 0, 100, rainPos * 32); | ||
graphics.color = Color.fromBytes(255, 55, 48); | ||
graphics.fillRect(400, 0, 100, firePos * 32); | ||
} | ||
|
||
public function toggleStates(){ | ||
if (playThunder == true) thunderSound.play(); | ||
else if (playThunder == false) thunderSound.pause(); | ||
|
||
if (playRain == true) rainSound.play(); | ||
else if (playRain == false) rainSound.pause(); | ||
|
||
if (playFire == true) fireSound.play(); | ||
else if (playFire == false) fireSound.pause(); | ||
} | ||
} |
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,5 @@ | ||
let project = new Project('041_projectSound'); | ||
project.addAssets('Assets/**'); | ||
project.addSources('Sources'); | ||
project.addLibrary('zui'); | ||
resolve(project); |