This repository has been archived by the owner on Jan 1, 2022. It is now read-only.
/
sound.monkey
72 lines (50 loc) · 1.51 KB
/
sound.monkey
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
Strict
Import flixel
Function Main:Int()
New Sprites()
Return 0
End Function
Class Sprites Extends FlxGame
Method New()
Super.New(640, 480, SpritesState.ClassObject, 1, 60)
End Method
Method OnContentInit:Void()
#if TARGET = "html5" OR TARGET = "android"
FlxAssetsManager.AddSound("main", "beep.ogg")
#ElseIf TARGET = "glfw" Or TARGET = "xna"
FlxAssetsManager.AddSound("main", "beep.wav")
#Else
FlxAssetsManager.AddSound("main", "beep.mp3")
#end
End Method
End Class
Class SpritesStateClass Implements FlxClass
Method CreateInstance:Object()
Return New SpritesState()
End Method
Method InstanceOf:Bool(object:Object)
Return (SpritesState(object) <> Null)
End Method
End Class
Class SpritesState Extends FlxState
Global ClassObject:FlxClass = New SpritesStateClass()
Field soundBox:FlxSprite
Field player:FlxSprite
Method Create:Void()
player = New FlxSprite(10, 300)
Add(player)
soundBox = New FlxSprite(500, 200)
Add(soundBox)
soundBox.Facing = FlxObject.LEFT
Local sound:FlxSound = (New FlxSound).Load("main", True).Proximity(500, 200, player, 300)
FlxG.sounds.Add(sound)
sound.Play()
End Method
Method Update:Void()
player.velocity.x = 0
If (FlxG.keys.Right Or (FlxG.Touch().Pressed And FlxG.Touch().screenX > FlxG.width / 2)) player.velocity.x = 100
If (FlxG.keys.Left Or (FlxG.Touch().Pressed And FlxG.Touch().screenX < FlxG.width / 2)) player.velocity.x = -100
If (FlxG.keys.Escape) Error ""
Super.Update()
End Method
End Class