Browse Source

Merge branch 'dev' of http://gogs.shuvit.org:3000/shuvit/shuvit into configobj_config_file

shuvit 3 years ago
parent
commit
249ccd40a8

+ 129
- 0
DList.py View File

@@ -0,0 +1,129 @@
1
+""" A node is a container which encapsulates any type of data.
2
+    The node object also has a reference to the NODE preceding and following
3
+    said object."""
4
+class Node(object):
5
+ 
6
+    def __init__(self, data, prev, next):
7
+        self.data = data
8
+        self.prev = prev
9
+        self.next = next
10
+        
11
+    def getNext(self):
12
+        if self.next is not None:
13
+            return self.next
14
+        print('There\'s nothing next, trying prev')
15
+        if self.prev is not None:
16
+            return self.prev
17
+        print('There\s nothing before either, just this one')
18
+        return self
19
+        
20
+    def getPrev(self):
21
+        if self.prev is not None:
22
+            return self.prev
23
+        print('There\'s nothing before, trying next')
24
+        if self.next is not None:
25
+            return self.next
26
+        print('There\'s nothing next either, just this one')
27
+        return self
28
+        
29
+    def getData(self):
30
+        return self.data
31
+ 
32
+""" A doubly-linked list implementation 
33
+    NOTE: the getters and setters return a reference to a Node object,
34
+    inside which is the data you're probably looking for. If you want to
35
+    access data, remember; after you call a get or find, use .data"""
36
+class DoubleList(object):
37
+ 
38
+    head = None
39
+    tail = None
40
+    length = 0;
41
+ 
42
+    """ Add a node to the list """
43
+    def append(self, data):
44
+        new_node = Node(data, None, None)
45
+        if self.head is None:
46
+            self.head = self.tail = new_node
47
+        else:
48
+            new_node.prev = self.tail
49
+            new_node.next = None
50
+            self.tail.next = new_node
51
+            self.tail = new_node
52
+        self.length = self.length + 1
53
+ 
54
+    """ Find a node in the list, then remove it """
55
+    def remove(self, node):
56
+        current_node = self.head
57
+ 
58
+        while current_node is not None:
59
+            if current_node == node:
60
+                # if it's not the first element
61
+                if current_node.prev is not None:
62
+                    current_node.prev.next = current_node.next
63
+                    current_node.next.prev = current_node.prev
64
+                # if its the last element
65
+                elif current_node.next is None:
66
+                    self.tail = current_node.prev
67
+                    self.tail.prev = current_node.prev.prev
68
+                    self.tail.next = None
69
+                else:
70
+                    # otherwise we have no prev (it's None), head is the next one, and prev becomes None
71
+                    self.head = current_node.next
72
+                    current_node.next.prev = None
73
+ 
74
+            current_node = current_node.next
75
+        self.length = self.length - 1
76
+    
77
+    def show(self):
78
+        print("Show list data:")
79
+        current_node = self.head
80
+        while current_node is not None:
81
+            print(current_node.data)
82
+            current_node = current_node.next
83
+        print("*"*50)
84
+        
85
+    """ Find a node in the list by value comparison """
86
+    def findNode(self, node_value):
87
+        current_node = self.head
88
+        
89
+        while current_node is not None:
90
+            if current_node.data == node_value:
91
+                return current_node
92
+            current_node = current_node.next
93
+    
94
+    """ Get a node by index position """
95
+    def get(self, index):
96
+        if index > self.length:
97
+            return none
98
+        elif index == 1:
99
+            return self.head
100
+        elif index == self.length:
101
+            return self.tail
102
+        else:
103
+            current_node = self.head
104
+            pos = 1
105
+            while pos < index:
106
+                current_node = current_node.next
107
+                pos = pos + 1
108
+            return current_node
109
+    
110
+    """ Checks if a node is in this list """
111
+    def contains(self, node):
112
+        current_node = self.head
113
+        while current_node is not None:
114
+            if current_node == node:
115
+                return true
116
+            current_node = current_node.next
117
+        return false
118
+        
119
+    """ Get the length of this list """
120
+    def getLength(self):
121
+        return self.length
122
+        
123
+    """ Get the head of this list """
124
+    def getHead(self):  # get head (;
125
+        return self.head
126
+        
127
+    """ Get the tail of this list """
128
+    def getTail(self):
129
+        return self.tail

+ 172
- 0
MusicPlayer.py View File

@@ -0,0 +1,172 @@
1
+import bge
2
+import os
3
+import aud
4
+import random
5
+import glob
6
+from DList import DoubleList
7
+from collections import OrderedDict
8
+from tinytag import TinyTag
9
+
10
+""" This is the Music Player as a component """
11
+class MusicPlayer(bge.types.KX_PythonComponent):
12
+
13
+    args = OrderedDict([])    
14
+
15
+    def start(self, args):
16
+        # dictionary
17
+        self.dictionary = bge.logic.globalDict
18
+        
19
+        # get mp3 files from the disk and create a list
20
+        self.directory = bge.logic.expandPath('//Music')
21
+        file_name = self.directory + '\\*.mp3'
22
+        file_list =  glob.glob(file_name)
23
+        
24
+        # use the mp3 list to make a playlist of nodes
25
+        self.playlist = DoubleList()
26
+        for name in file_list:
27
+            self.playlist.append(name)
28
+        
29
+        # previously played list of nodes
30
+        self.alreadyPlayed = DoubleList()
31
+        
32
+        # get a random song from the playlist, 
33
+        # remove it from the playlist
34
+        # add it to the alreadyPlayed list
35
+        # NOTICE: currentNode is a reference to a NODE in a list, if you want to play the song inside the node, use .data
36
+        self.currentNode = self.playlist.get(random.randint(0, self.playlist.getLength()))
37
+        self.nowPlaying = self.currentNode.getData()
38
+        self.playlist.remove(self.currentNode)
39
+        self.alreadyPlayed.append(self.nowPlaying)
40
+        print("Now Playing: " + self.nowPlaying)
41
+        self.setTag()
42
+        self.isPlaying = False
43
+
44
+        # create audio devices
45
+        self.device = aud.device()
46
+        self.factory = aud.Factory(self.nowPlaying)
47
+        self.handle = None        
48
+    
49
+    """ Update is called once every frame, and this is where
50
+        any input handling should go
51
+        
52
+        Controller Buttons: 
53
+        Y-Button - Play/Pause
54
+        LB       - Previous Track
55
+        RB       - Next Track
56
+        
57
+        TODO: Keyboard Buttons if these aren't alright
58
+        P        - Play/Pause
59
+        Pad Plus - Next Track
60
+        Pad Minus- Prev Track
61
+    """
62
+    def update(self):
63
+        keyboard = bge.logic.keyboard.events
64
+        up_dict = bge.logic.globalDict
65
+        #print(dictionary)
66
+        pKey = keyboard[bge.events.PKEY]
67
+        pPlus = keyboard[bge.events.PADPLUSKEY]
68
+        pMinus = keyboard[bge.events.PADMINUS]
69
+        lb = up_dict['lBump']
70
+        last_lb = up_dict['last_lBump']
71
+        rb = up_dict['rBump']
72
+        last_rb = up_dict['last_rBump']
73
+        y = up_dict['yBut']
74
+        last_y = up_dict['last_yBut']
75
+        JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
76
+        
77
+
78
+        #Run player on startup
79
+        if up_dict['music_start'] == True:
80
+            if self.isPlaying:
81
+                self.stopMusic()
82
+            else:
83
+                self.playMusic()                 
84
+            up_dict['music_start'] = False               
85
+
86
+        # Music controls only during pause/replay
87
+        if (up_dict['npause'] == True or up_dict['playback'] == True) or up_dict['music_start'] == True:
88
+            #stop/play
89
+            if (y == False and last_y == True) or pKey == JUST_ACTIVATED:
90
+                if self.isPlaying:
91
+                    self.stopMusic()
92
+                    up_dict['music_player'] = 0
93
+                else:
94
+                    self.playMusic()
95
+                    up_dict['music_player'] = 1
96
+            # Prev/Next
97
+            if self.isPlaying and self.handle.status:
98
+                if pMinus == JUST_ACTIVATED or (lb == False and last_lb == True):
99
+                    self.prevSong()
100
+                
101
+                if pPlus == JUST_ACTIVATED or (rb == False and last_rb == True):
102
+                    self.nextSong()
103
+        # if song ends, play next song
104
+        if self.isPlaying and not self.handle.status:
105
+            self.nextSong()
106
+
107
+    """ get info about song using TinyTag, then print to console """
108
+    def setTag(self):                
109
+        self.currTrackPath = os.path.join(self.directory, self.nowPlaying)
110
+        tag = TinyTag.get(self.currTrackPath)
111
+        self.currArtist = tag.artist
112
+        self.currTrackTitle = tag.title
113
+        self.dictionary['mu_artist'] = self.currArtist
114
+        self.dictionary['mu_title'] = self.currTrackTitle
115
+                
116
+        print('Artist: %s' % self.currArtist, 
117
+                ' Track: %s' % self.currTrackTitle)
118
+
119
+    def playMusic(self):
120
+        print('Play Music')
121
+        self.setTag()
122
+        self.handle = self.device.play(self.factory)
123
+        self.isPlaying = True
124
+        
125
+    def stopMusic(self):
126
+        print('Stop Music')
127
+        self.handle.stop()
128
+        self.isPlaying = False
129
+        
130
+    def nextSong(self):
131
+        print('Next Song')
132
+        # stop the current song
133
+        self.handle.stop()
134
+        
135
+        # get a song from the playlist
136
+        self.currentNode = self.playlist.get(random.randint(0, self.playlist.getLength()))
137
+        self.nowPlaying = self.currentNode.getData()
138
+        self.playlist.remove(self.currentNode)
139
+                
140
+        # add the song to the already played list
141
+        self.alreadyPlayed.append(self.nowPlaying)  
142
+        
143
+        # start the song
144
+        self.factory = aud.Factory(self.nowPlaying)
145
+        self.handle = self.device.play(self.factory)
146
+        self.setTag()
147
+        
148
+        # If playlist is empty, re-fill it
149
+        if self.playlist.getLength() == 0:
150
+            file_name = self.directory + '\\*.mp3'
151
+            file_list =  glob.glob(file_name)
152
+            for name in file_list:
153
+                self.playlist.append(name)
154
+        
155
+    """ Note on first call of this method, the current node will be equal to the tail of the already played list, 
156
+        however, it will be a node from a different list. We need to set current node equal to the tail node
157
+        of the already played list so that we can iterate through that list, instead of the other list """
158
+    def prevSong(self):
159
+        print('Prev Song')
160
+        # stop the current song
161
+        self.handle.stop()        
162
+        
163
+        if self.currentNode.getData() == self.alreadyPlayed.getTail().getData():
164
+            self.currentNode = self.alreadyPlayed.getTail()
165
+            
166
+        self.currentNode = self.currentNode.getPrev()
167
+        self.nowPlaying = self.currentNode.getData()
168
+        
169
+        # start the song
170
+        self.factory = aud.Factory(self.nowPlaying)
171
+        self.handle = self.device.play(self.factory)
172
+        self.setTag()

+ 2
- 2
README.md View File

@@ -1,2 +1,2 @@
1
-# shuvit
2
-Open source skateboarding game made with UPBGE / Blender.
1
+# shuvit
2
+Open source skateboarding game made with UPBGE / Blender.

BIN
Test/Music/Divineinfinite - Bang This.mp3 View File


BIN
Test/Music/Just 1 Soul - Growing.mp3 View File


+ 1
- 0
Test/Music/Test.txt View File

@@ -0,0 +1 @@
1
+Hello, friend

BIN
Test/Music/alien-spaceship_daniel_simion.wav View File


+ 12
- 0
active_camera_loc.py View File

@@ -0,0 +1,12 @@
1
+import bge
2
+
3
+
4
+def set(cont):
5
+    own = cont.owner
6
+
7
+    #own.getWorldPosition
8
+    scene = bge.logic.getCurrentScene()
9
+    cam = scene.active_camera
10
+    own.worldPosition = cam.worldPosition
11
+
12
+# dont call main(bge.logic.getCurrentController()), the py controller will

+ 209
- 209
ai_manager.py View File

@@ -1,210 +1,210 @@
1
-def printplaying(skater,deck):
2
-    splaying_layers = "S: "
3
-    playing_layers = "D: "
4
-    tplaying_layers = "T: "
5
-    for x in range(9999):
6
-        if skater.isPlayingAction(x):
7
-        #if trucks.isPlayingAction(x):
8
-        #if skater.isPlayingAction(x):                        
9
-            splaying_layers += str(x)
10
-            splaying_layers += " "        
11
-        if deck.isPlayingAction(x):
12
-        #if trucks.isPlayingAction(x):
13
-        #if skater.isPlayingAction(x):                        
14
-            playing_layers += str(x)
15
-            playing_layers += " "
16
-          
17
-    print(splaying_layers, playing_layers)
18
-
19
-def main():
20
-
21
-    frame_rate = 60    #Set this to the framerate of your game.
22
-    optimization = 1    #An integer, must be at least 1! Higher value will make a smaller saved file size. I do not reccomend setting it to anything other than 1 though.
23
-    #recording_cutoff = 6974#7300 #3600   #Frames at which the oldest recorded frame will be deleted. 0 is no cutoff.
24
-    
25
-    recorder_state = 1   #This is the main state of the recorder object. State will be reverted to this value when the user breaks out of the playback.
26
-    allow_playback_break = True   #Allow the player to resume playing from the position in the recording.
27
-
28
-    from bge import logic
29
-    import aiRecord
30
-    import aiSortData
31
-    import npcChangeAnim
32
-    from mathutils import Vector
33
-    import math
34
-    
35
-    debugg = True
36
-
37
-    cont = logic.getCurrentController()
38
-    own = cont.owner
39
-    scene = logic.getCurrentScene()
40
-    dict = logic.globalDict
41
-    own['valueIndex'] = own['valueIndex'] + 2
42
-    #dict['recorder_on'] = recorder_on
43
-    npc_index = own['npc_index']
44
-    skater = dict['spawned_npcs'][npc_index]
45
-    recorder_on = dict.get('recorder_on')
46
-    own['recorder_on'] = recorder_on
47
-    #print("recorder on: ", recorder_on) 
48
-    own["playback"] = True
49
-    recording_cutoff = own['replay_length']
50
-    idle_timer = own['idle_timer']
51
-    npc_playback = own['npc_playback']
52
-    
53
-    
54
-    
55
-    if 'data_loaded' not in own:
56
-        #own['data_loaded'] = 1
57
-        aiRecord.loadData(cont, own)
58
-        if debugg: print('ai_loadData')
59
-        
60
-    if npc_playback == True:
61
-        cube = own
62
-        aiRecord.loadData(cont, own)   
63
-        #own['move'] = False          
64
-        #....................
65
-
66
-        valueIndex = own['valueIndex']
67
-        n = (valueIndex / recording_cutoff) * 1000
68
-        n = int(round(n))
69
-        #print(own['valueIndex'])
70
-        if own['objIndex'] < (recording_cutoff-3):
71
-            own['objIndex'] = own['objIndex'] + 2
72
-        else:
73
-            own['objIndex'] = 4   
74
-            print('replay end')    
75
-            npcChangeAnim.main(cont)
76
-            #own['npc_replay_name'] = '30secA.dat'
77
-            own['inited'] = False
78
-            own['rotate_in'] = True
79
-            own['move_to'] = True
80
-            own['rotate_out'] = True 
81
-            aiRecord.loadData(cont, own)
82
-    else:
83
-        if idle_timer < 5:
84
-            idle_timer += 1
85
-            #print('idling', idle_timer)
86
-        else:
87
-            idle_timer = 0
88
-            own['npc_rotate'] = True                 
89
-            
90
-    if own['move'] == True:
91
-        speed = .15
92
-        target = own['rpStartLoc']
93
-        my_vector = Vector([target[0], target[1], target[2]])
94
-        length = (own.worldPosition - my_vector).length
95
-        obj = own['target_object_name']
96
-        vect = own.getVectTo(obj)   
97
-        if length < .1:
98
-            own['move'] = False
99
-            obj = own['target_object_name']
100
-    own['idle_timer'] = idle_timer   
101
-    
102
-    try:
103
-        obj = own['target_object_name']
104
-        #print(obj.worldPosition)
105
-    except:
106
-        pass    
107
-    
108
-    
109
-    #11111111
110
-    if own['rotate_in'] == False and own['move_to'] == False and own['rotate_out'] == False:
111
-        own['npc_playback'] = True
112
-        #obj = own['target_object_name']
113
-        #obj.endObject()
114
-        #print('ending target')    
115
-    if own['rotate_in'] == True:
116
-        tActu = cont.actuators['npcTracking']
117
-        tActu.object = own['target_object_name']
118
-        try:
119
-            own['rotate_in_timer'] = own['rotate_in_timer'] + 1
120
-        except:
121
-            own['rotate_in_timer'] = 0
122
-        if own['rotate_in_timer'] < 120:    
123
-            cont.activate(tActu)
124
-            skater.playAction('reg_idle1', 0,120, layer=2, play_mode=1, speed=.5)  
125
-        else:
126
-            cont.deactivate(tActu) 
127
-            own['rotate_in'] = False
128
-            own['rotate_in_timer'] = 0
129
-            skater.stopAction(2)
130
-
131
-    elif own['move_to'] == True:
132
-        target = own['rpStartLoc']
133
-        #print(target, 'target', own.worldPosition, '++++++')
134
-        my_vector = Vector([target[0], target[1], target[2]])
135
-        length = (own.worldPosition - my_vector).length
136
-        sActu = cont.actuators['npcSteering']
137
-        sActu.target = own['target_object_name']
138
-        #length = round(length, 7)
139
-        if length > .1:
140
-            #print(length, 'length < .1')
141
-            #pass
142
-            cont.activate(sActu)
143
-            skater.playAction('reg_nwalk', 0,35, layer=2, play_mode=1, speed=.5)
144
-        else:
145
-            cont.deactivate(sActu)
146
-            own['move_to'] = False
147
-            print(length, 'length met')
148
-            skater.stopAction(2)
149
-
150
-    elif own['rotate_out'] == True:    
151
-        #own['rpStartZ'] = 180
152
-        #print(own['rpStartZ'], 'start')
153
-        xyz = own.localOrientation.to_euler()
154
-        #print(xyz[2], 'non euler')
155
-        rotz = math.degrees(xyz[2])
156
-        xyz[2] = xyz[2] + 1.57
157
-        rotz_b = rotz + 180
158
-        if rotz_b > 360:
159
-            rotz_b -= 360
160
-        srotz_b = own['rpStartZ'] + 180
161
-        if srotz_b > 360:
162
-            srotz_b -= 360
163
-        #print (rotz_b, srotz_b, '---rotations')        
164
-        #print (rotz, own['rpStartZ'], '---rotations')
165
-        num = rotz - (own['rpStartZ'])
166
-        amt = .03
167
-        amt2 = 1
168
-        
169
-        
170
-        local = own.worldOrientation.inverted() * ( own['target_object_name'].worldPosition - own.worldPosition) 
171
-
172
-        if local.x >0:
173
-            #target is in front
174
-            #print('in front')
175
-            pass
176
-        else:
177
-            #target is behind
178
-            #print('behind')
179
-            pass
180
-        if local.y > 0:
181
-                 #object on right
182
-            #print('on right')
183
-            rot = 'right'
184
-        else:
185
-                 #object is on left 
186
-            #print('on left')
187
-            rot = 'left'       
188
-        
189
-        
190
-        
191
-        skater.playAction('reg_idle1', 0,120, layer=2, play_mode=1, speed=.5)
192
-        if abs(num) < amt2:
193
-            own['npc_playback'] = True
194
-            own['npc_rotate'] = False
195
-            print('----starting replay', num)
196
-            own['rotate_out'] = False
197
-            obj = own['target_object_name']
198
-            obj.endObject()
199
-            print('ending target') 
200
-            skater.stopAction(2)            
201
-        #elif rotz > own['rpStartZ']:
202
-        elif rot == 'right':    
203
-            own.applyRotation([0,0,amt], True)
204
-            own.worldPosition = own['rpStartLoc']
205
-        #elif rotz < own['rpStartZ']:
206
-        elif rot == 'left':    
207
-            own.applyRotation([0,0,-amt], True) 
208
-            own.worldPosition = own['rpStartLoc']                
209
-    #print(own['rotate_in'], own['move_to'], own['rotate_out'])                          
1
+def printplaying(skater,deck):
2
+    splaying_layers = "S: "
3
+    playing_layers = "D: "
4
+    tplaying_layers = "T: "
5
+    for x in range(9999):
6
+        if skater.isPlayingAction(x):
7
+        #if trucks.isPlayingAction(x):
8
+        #if skater.isPlayingAction(x):                        
9
+            splaying_layers += str(x)
10
+            splaying_layers += " "        
11
+        if deck.isPlayingAction(x):
12
+        #if trucks.isPlayingAction(x):
13
+        #if skater.isPlayingAction(x):                        
14
+            playing_layers += str(x)
15
+            playing_layers += " "
16
+          
17
+    print(splaying_layers, playing_layers)
18
+
19
+def main():
20
+
21
+    frame_rate = 60    #Set this to the framerate of your game.
22
+    optimization = 1    #An integer, must be at least 1! Higher value will make a smaller saved file size. I do not reccomend setting it to anything other than 1 though.
23
+    #recording_cutoff = 6974#7300 #3600   #Frames at which the oldest recorded frame will be deleted. 0 is no cutoff.
24
+    
25
+    recorder_state = 1   #This is the main state of the recorder object. State will be reverted to this value when the user breaks out of the playback.
26
+    allow_playback_break = True   #Allow the player to resume playing from the position in the recording.
27
+
28
+    from bge import logic
29
+    import aiRecord
30
+    import aiSortData
31
+    import npcChangeAnim
32
+    from mathutils import Vector
33
+    import math
34
+    
35
+    debugg = True
36
+
37
+    cont = logic.getCurrentController()
38
+    own = cont.owner
39
+    scene = logic.getCurrentScene()
40
+    dict = logic.globalDict
41
+    own['valueIndex'] = own['valueIndex'] + 2
42
+    #dict['recorder_on'] = recorder_on
43
+    npc_index = own['npc_index']
44
+    skater = dict['spawned_npcs'][npc_index]
45
+    recorder_on = dict.get('recorder_on')
46
+    own['recorder_on'] = recorder_on
47
+    #print("recorder on: ", recorder_on) 
48
+    own["playback"] = True
49
+    recording_cutoff = own['replay_length']
50
+    idle_timer = own['idle_timer']
51
+    npc_playback = own['npc_playback']
52
+    
53
+    
54
+    
55
+    if 'data_loaded' not in own:
56
+        #own['data_loaded'] = 1
57
+        aiRecord.loadData(cont, own)
58
+        if debugg: print('ai_loadData')
59
+        
60
+    if npc_playback == True:
61
+        cube = own
62
+        aiRecord.loadData(cont, own)   
63
+        #own['move'] = False          
64
+        #....................
65
+
66
+        valueIndex = own['valueIndex']
67
+        n = (valueIndex / recording_cutoff) * 1000
68
+        n = int(round(n))
69
+        #print(own['valueIndex'])
70
+        if own['objIndex'] < (recording_cutoff-3):
71
+            own['objIndex'] = own['objIndex'] + 2
72
+        else:
73
+            own['objIndex'] = 4   
74
+            print('replay end')    
75
+            npcChangeAnim.main(cont)
76
+            #own['npc_replay_name'] = '30secA.dat'
77
+            own['inited'] = False
78
+            own['rotate_in'] = True
79
+            own['move_to'] = True
80
+            own['rotate_out'] = True 
81
+            aiRecord.loadData(cont, own)
82
+    else:
83
+        if idle_timer < 5:
84
+            idle_timer += 1
85
+            #print('idling', idle_timer)
86
+        else:
87
+            idle_timer = 0
88
+            own['npc_rotate'] = True                 
89
+            
90
+    if own['move'] == True:
91
+        speed = .15
92
+        target = own['rpStartLoc']
93
+        my_vector = Vector([target[0], target[1], target[2]])
94
+        length = (own.worldPosition - my_vector).length
95
+        obj = own['target_object_name']
96
+        vect = own.getVectTo(obj)   
97
+        if length < .1:
98
+            own['move'] = False
99
+            obj = own['target_object_name']
100
+    own['idle_timer'] = idle_timer   
101
+    
102
+    try:
103
+        obj = own['target_object_name']
104
+        #print(obj.worldPosition)
105
+    except:
106
+        pass    
107
+    
108
+    
109
+    #11111111
110
+    if own['rotate_in'] == False and own['move_to'] == False and own['rotate_out'] == False:
111
+        own['npc_playback'] = True
112
+        #obj = own['target_object_name']
113
+        #obj.endObject()
114
+        #print('ending target')    
115
+    if own['rotate_in'] == True:
116
+        tActu = cont.actuators['npcTracking']
117
+        tActu.object = own['target_object_name']
118
+        try:
119
+            own['rotate_in_timer'] = own['rotate_in_timer'] + 1
120
+        except:
121
+            own['rotate_in_timer'] = 0
122
+        if own['rotate_in_timer'] < 120:    
123
+            cont.activate(tActu)
124
+            skater.playAction('reg_idle1', 0,120, layer=2, play_mode=1, speed=.5)  
125
+        else:
126
+            cont.deactivate(tActu) 
127
+            own['rotate_in'] = False
128
+            own['rotate_in_timer'] = 0
129
+            skater.stopAction(2)
130
+
131
+    elif own['move_to'] == True:
132
+        target = own['rpStartLoc']
133
+        #print(target, 'target', own.worldPosition, '++++++')
134
+        my_vector = Vector([target[0], target[1], target[2]])
135
+        length = (own.worldPosition - my_vector).length
136
+        sActu = cont.actuators['npcSteering']
137
+        sActu.target = own['target_object_name']
138
+        #length = round(length, 7)
139
+        if length > .1:
140
+            #print(length, 'length < .1')
141
+            #pass
142
+            cont.activate(sActu)
143
+            skater.playAction('reg_nwalk', 0,35, layer=2, play_mode=1, speed=.5)
144
+        else:
145
+            cont.deactivate(sActu)
146
+            own['move_to'] = False
147
+            print(length, 'length met')
148
+            skater.stopAction(2)
149
+
150
+    elif own['rotate_out'] == True:    
151
+        #own['rpStartZ'] = 180
152
+        #print(own['rpStartZ'], 'start')
153
+        xyz = own.localOrientation.to_euler()
154
+        #print(xyz[2], 'non euler')
155
+        rotz = math.degrees(xyz[2])
156
+        xyz[2] = xyz[2] + 1.57
157
+        rotz_b = rotz + 180
158
+        if rotz_b > 360:
159
+            rotz_b -= 360
160
+        srotz_b = own['rpStartZ'] + 180
161
+        if srotz_b > 360:
162
+            srotz_b -= 360
163
+        #print (rotz_b, srotz_b, '---rotations')        
164
+        #print (rotz, own['rpStartZ'], '---rotations')
165
+        num = rotz - (own['rpStartZ'])
166
+        amt = .03
167
+        amt2 = 1
168
+        
169
+        
170
+        local = own.worldOrientation.inverted() * ( own['target_object_name'].worldPosition - own.worldPosition) 
171
+
172
+        if local.x >0:
173
+            #target is in front
174
+            #print('in front')
175
+            pass
176
+        else:
177
+            #target is behind
178
+            #print('behind')
179
+            pass
180
+        if local.y > 0:
181
+                 #object on right
182
+            #print('on right')
183
+            rot = 'right'
184
+        else:
185
+                 #object is on left 
186
+            #print('on left')
187
+            rot = 'left'       
188
+        
189
+        
190
+        
191
+        skater.playAction('reg_idle1', 0,120, layer=2, play_mode=1, speed=.5)
192
+        if abs(num) < amt2:
193
+            own['npc_playback'] = True
194
+            own['npc_rotate'] = False
195
+            print('----starting replay', num)
196
+            own['rotate_out'] = False
197
+            obj = own['target_object_name']
198
+            obj.endObject()
199
+            print('ending target') 
200
+            skater.stopAction(2)            
201
+        #elif rotz > own['rpStartZ']:
202
+        elif rot == 'right':    
203
+            own.applyRotation([0,0,amt], True)
204
+            own.worldPosition = own['rpStartLoc']
205
+        #elif rotz < own['rpStartZ']:
206
+        elif rot == 'left':    
207
+            own.applyRotation([0,0,-amt], True) 
208
+            own.worldPosition = own['rpStartLoc']                
209
+    #print(own['rotate_in'], own['move_to'], own['rotate_out'])                          
210 210
 main()

+ 19
- 0
curves.osl View File

@@ -0,0 +1,19 @@
1
+
2
+
3
+uniform sampler2D bgl_RenderedTexture;
4
+
5
+uniform float BC_BRIGHTNESS = 2;
6
+uniform float BC_CONTRAST = 1;
7
+
8
+//const float BC_CONTRAST = 1.3;    //1 is no contrast.
9
+//const float BC_BRIGHTNESS = 1.15;    //1 is no brightness 1.15 is good
10
+
11
+void main()
12
+{
13
+    vec4 color = texture2D(bgl_RenderedTexture, gl_TexCoord[0].st);
14
+    
15
+    color = ((color-1)*max(BC_CONTRAST,0));
16
+    color = color+BC_BRIGHTNESS;
17
+     
18
+    gl_FragColor = color; 
19
+}

+ 72
- 0
lensflare01.osl View File

@@ -0,0 +1,72 @@
1
+
2
+uniform sampler2D bgl_RenderedTexture;
3
+uniform float bgl_RenderedTextureWidth;
4
+uniform float bgl_RenderedTextureHeight;
5
+uniform float sunX;
6
+uniform float sunY;
7
+uniform float timer;
8
+uniform float sundirect;
9
+uniform float sunScale; 
10
+
11
+float noise( float n )
12
+{
13
+     return fract(sin(n+timer/2.0));
14
+}
15
+
16
+//float noise2(vec2 co){
17
+    //return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
18
+//}
19
+
20
+vec3 lensflare(vec2 uv,vec2 pos,float sunscale)
21
+{
22
+	vec2 main = uv-pos;
23
+	vec2 uvd = uv*(length(uv));
24
+	
25
+	float ang = atan(main.y, main.x);
26
+	float dist=length(main); dist = pow(dist,.1);
27
+	float n = noise1(vec2((ang-timer/9.0)*16.0,dist*32.0));
28
+	
29
+	float f0 = 1.0/(length(uv-pos)/sunscale+1.0);
30
+	
31
+	f0 = f0+f0*(sin((ang+timer/18.0 + noise1(abs(ang)+n/2.0)*2.0)*12.0)*.1+dist*.1+.8);
32
+
33
+	float f2 = max(1.0/(1.0+32.0*pow(length(uvd+0.8*pos),2.0)),.0)*00.25;
34
+	float f22 = max(1.0/(1.0+32.0*pow(length(uvd+0.85*pos),2.0)),.0)*00.23;
35
+	float f23 = max(1.0/(1.0+32.0*pow(length(uvd+0.9*pos),2.0)),.0)*00.21;
36
+	
37
+	vec2 uvx = mix(uv,uvd,-0.5);
38
+	
39
+	float f4 = max(0.01-pow(length(uvx+0.4*pos),2.4),.0)*6.0;
40
+	float f42 = max(0.01-pow(length(uvx+0.45*pos),2.4),.0)*5.0;
41
+	float f43 = max(0.01-pow(length(uvx+0.5*pos),2.4),.0)*3.0;
42
+	
43
+	uvx = mix(uv,uvd,-.4);
44
+	
45
+	float f5 = max(0.01-pow(length(uvx+0.2*pos),5.5),.0)*2.0;
46
+	float f52 = max(0.01-pow(length(uvx+0.4*pos),5.5),.0)*2.0;
47
+	float f53 = max(0.01-pow(length(uvx+0.6*pos),5.5),.0)*2.0;
48
+	
49
+	uvx = mix(uv,uvd,-0.5);
50
+	
51
+	float f6 = max(0.01-pow(length(uvx-0.3*pos),1.6),.0)*6.0;
52
+	float f62 = max(0.01-pow(length(uvx-0.325*pos),1.6),.0)*3.0;
53
+	float f63 = max(0.01-pow(length(uvx-0.35*pos),1.6),.0)*5.0;
54
+	
55
+	vec3 c = vec3(.0);
56
+	
57
+	c.r+=f2+f4+f5+f6; c.g+=f22+f42+f52+f62; c.b+=f23+f43+f53+f63;
58
+	c+=vec3(f0);
59
+	
60
+	return c;
61
+}
62
+
63
+void main()
64
+{
65
+    vec4 renderedTex = texture2D(bgl_RenderedTexture, gl_TexCoord[0].st);
66
+    float xconv = bgl_RenderedTextureWidth / bgl_RenderedTextureHeight;
67
+    vec2 sunPos = vec2((sunX - 0.5) * xconv, sunY - 0.5);
68
+    vec2 uv = vec2((gl_TexCoord[0].s - 0.5) * xconv, gl_TexCoord[0].t - 0.5);
69
+    vec3 lens = lensflare(uv, sunPos, sunScale);
70
+    renderedTex.rgb += lens * sundirect;
71
+    gl_FragColor = renderedTex;
72
+}

+ 166
- 173
music_player.py View File

@@ -1,173 +1,166 @@
1
-#shuvit.org
2
-#mp3 player
3
-
4
-import bge
5
-import os
6
-import aud
7
-import random
8
-from tinytag import TinyTag
9
-
10
-directory = bge.logic.expandPath('//Music')
11
-file_list = os.listdir(directory) 
12
-selected = random.choice(file_list)
13
-full_path = os.path.join(directory, selected)
14
-
15
-dict = bge.logic.globalDict
16
-dict['mu_current_song'] = ''
17
-dict['mu_stopped'] = 0
18
-dict['mu_playlist'] = ''
19
-dict['mu_lib'] = ''
20
-dict['change_track'] = 0
21
-dict['mu_track_time'] = 0
22
-#dict['mu_last_track'] = ''
23
-#dict['mu_artist'] = ''
24
-#dict['mu_title'] = ''
25
-
26
-keyboard = bge.logic.keyboard
27
-JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
28
-
29
-def stop_music(sound):
30
-
31
-    print("Stop music")    
32
-    sound.pauseSound()
33
-    dict['mu_stopped'] = 1
34
-    dict['music_player'] = 0
35
-    
36
-def play_music():
37
-
38
-    print("Play music") 
39
-    full_path = os.path.join(directory, dict['mu_current_song'])
40
-    sound = bge.logic.getCurrentController().actuators['music_player']
41
-    sound.sound = aud.Factory(full_path)
42
-    sound.stopSound()
43
-    sound.startSound()
44
-    dict['mu_stopped'] = 0
45
-    dict['change_track'] = 0
46
-    dict['mu_track_time'] = 0 
47
-    dict['music_player'] = 1  
48
-
49
-    try:
50
-        tag = TinyTag.get(full_path)
51
-        print('Playing: ', 'Artist: %s' % tag.artist, 'Track: %s' % tag.title)
52
-        dict['mu_artist'] = tag.artist
53
-        dict['mu_title'] = tag.title
54
-        info = ('Music > ', 'Artist: %s' % tag.artist, 'Track: %s' % tag.title)
55
-        print(info)
56
-        dict['music_info'] = info
57
-    except:
58
-        print("Track has no tag.") 
59
-    print(dict['mu_title'], 'mu_title')
60
-def next_track():
61
-
62
-    print("next track")
63
-    dict = bge.logic.globalDict
64
-    plist = dict['mu_playlist']
65
-    cur_song = dict['mu_current_song']
66
-    pl_length = len(dict['mu_playlist'])    
67
-
68
-    if pl_length > 1:
69
-        try:
70
-            plist.remove(cur_song)
71
-        except:
72
-            pass    
73
-
74
-    if pl_length == 1:    
75
-        print('rebuilding playlist')
76
-        file_list = os.listdir(directory) 
77
-        plist = file_list
78
-
79
-    selected = random.choice(plist)
80
-    dict['mu_last_track'] = dict['mu_current_song']
81
-    dict['mu_current_song'] = selected
82
-    dict['mu_playlist'] = plist
83
-    dict['change_track'] = 0
84
-    dict['mu_track_time'] = 0
85
-    play_music()
86
-    
87
-    
88
-
89
-    #dict['music_info'] = info    
90
-
91
-def previous_track():
92
-
93
-    print("previous track") 
94
-    dict['mu_current_song'] = dict['mu_last_track']
95
-    play_music()
96
-
97
-def initer(cont):
98
-    #cont = bge.logic.getCurrentController()
99
-    own = cont.owner
100
-    dict = bge.logic.globalDict
101
-    if 'playback' not in dict:
102
-        dict['playback'] = True
103
-    if 'mp_inited' not in own:
104
-        own['mp_inited'] = True
105
-        print('Initializing music player')
106
-        
107
-        file_list = os.listdir(directory) 
108
-        dict['mu_lib'] = file_list
109
-        dict['mu_playlist'] = file_list
110
-        dict['change_track'] = 0
111
-        selected = random.choice(file_list)
112
-        dict['mu_current_song'] = selected
113
-        print('Current Track: ', dict['mu_current_song'])
114
-        full_path = os.path.join(directory, selected)
115
-
116
-        try:
117
-            tag = TinyTag.get(full_path)
118
-            print('Artist: %s' % tag.artist, 'Track: %s' % tag.title)
119
-            dict['mu_artist'] = tag.artist
120
-            dict['mu_title'] = tag.title            
121
-        except:
122
-            print("Track has no tag.")     
123
-
124
-def check_status():
125
-
126
-    sound = bge.logic.getCurrentController().actuators['music_player']
127
-    cur_song = dict['mu_current_song']
128
-    full_path = os.path.join(directory, dict['mu_current_song'])
129
-    sound = bge.logic.getCurrentController().actuators['music_player']
130
-    sound.sound = aud.Factory(full_path)  
131
-
132
-    if sound.time < dict['mu_track_time'] and dict['mu_stopped'] == 0 and dict['change_track'] == 0:
133
-        print('song over, getting new one')
134
-        dict['change_track'] = 1
135
-        dict['mu_track_time'] = 0
136
-    else:
137
-        dict['change_track'] = 0
138
-    dict['mu_track_time'] = sound.time    
139
-
140
-def main(cont):
141
-
142
-    dict = bge.logic.globalDict        
143
-    cur_song = dict['mu_current_song']    
144
-    full_path = os.path.join(directory, dict['mu_current_song'])
145
-    sound = bge.logic.getCurrentController().actuators['music_player']
146
-    sound.sound = aud.Factory(full_path)
147
-    sound.mode = 1
148
-    initer(cont)
149
-    if dict['music_player'] != 0:
150
-        if dict['mu_stopped'] == 0:        
151
-            sound.startSound()
152
-        if dict['change_track'] == 1:
153
-            dict['change_track'] = 0
154
-            next_track() 
155
-
156
-    plist = dict['mu_playlist']  
157
-    pl_length = len(dict['mu_playlist'])    
158
-    if pl_length == 0:
159
-        dict['mu_playlist'] = dict['mu_lib']        
160
-    #allow controlls while paused or in replay    
161
-    if dict['npause']  == 1 or dict['playback'] == True:
162
-        if dict['yBut'] == False and dict['last_yBut'] == True:
163
-            if dict['mu_stopped'] == 1:
164
-                play_music()    
165
-            else:
166
-                stop_music(sound)  
167
-        if dict['lBump'] == False and dict['last_lBump'] == True:
168
-            previous_track()
169
-        if dict['rBump'] == False and dict['last_rBump'] == True:
170
-            next_track()                
171
-            
172
-    
173
-#main()        
1
+#shuvit.org
2
+#mp3 player
3
+
4
+import bge
5
+import os
6
+import aud
7
+import random
8
+import glob
9
+from tinytag import TinyTag
10
+
11
+# dict
12
+dict = bge.logic.globalDict
13
+dict['mu_current_song'] = ''
14
+dict['mu_stopped'] = 1
15
+dict['change_track'] = 0
16
+dict['mu_track_time'] = 0
17
+
18
+# create file path
19
+directory = bge.logic.expandPath("//")
20
+file_name = directory + "Music\\*.mp3" # Test directory "Test\\Music\\*.mp3"
21
+file_list = glob.glob(file_name)
22
+selected = random.choice(file_list)
23
+full_path = os.path.join(directory, selected)
24
+dict['mu_playlist'] = file_list
25
+dict['mu_lib'] = file_list
26
+
27
+# inputs
28
+keyboard = bge.logic.keyboard
29
+JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
30
+
31
+def initer(cont):
32
+    own = cont.owner
33
+    dict = bge.logic.globalDict
34
+    if 'mplayback' not in dict:
35
+        dict['mplayback'] = True
36
+    if 'mp_inited' not in own:
37
+        own['mp_inited'] = True
38
+        print('Initializing music player')
39
+        
40
+        dict['mu_lib'] = file_list
41
+        dict['mu_playlist'] = file_list
42
+        dict['change_track'] = 0
43
+        selected = random.choice(file_list)
44
+        dict['mu_current_song'] = selected
45
+        print('Current Track: ', dict['mu_current_song'])
46
+        full_path = os.path.join(directory, selected)
47
+
48
+        try:
49
+            tag = TinyTag.get(full_path)
50
+            print('Artist: %s' % tag.artist, 'Track: %s' % tag.title)
51
+            dict['mu_artist'] = tag.artist
52
+            dict['mu_title'] = tag.title            
53
+        except:
54
+            print("Track has no tag.")  
55
+            
56
+def stop_music(sound):
57
+
58
+    print("Stop music")    
59
+    sound.pauseSound()
60
+    dict['mu_stopped'] = 1
61
+    dict['music_player'] = 0
62
+    
63
+def play_music():
64
+
65
+    print("Play music") 
66
+    full_path = os.path.join(directory, dict['mu_current_song'])
67
+    sound = bge.logic.getCurrentController().actuators['music_player']
68
+    sound.sound = aud.Factory(full_path)
69
+    sound.stopSound()
70
+    sound.startSound()
71
+    dict['mu_stopped'] = 0
72
+    dict['change_track'] = 0
73
+    dict['mu_track_time'] = 0 
74
+    dict['music_player'] = 1  
75
+    try:
76
+        tag = TinyTag.get(full_path)
77
+        print('Playing: ', 'Artist: %s' % tag.artist, 'Track: %s' % tag.title)
78
+        dict['mu_artist'] = tag.artist
79
+        dict['mu_title'] = tag.title
80
+        info = ('Music > ', 'Artist: %s' % tag.artist, 'Track: %s' % tag.title)
81
+        dict['music_info'] = info
82
+    except:
83
+        print("Track has no tag.") 
84
+    print(dict['mu_title'], 'mu_title')
85
+    
86
+def next_track():
87
+
88
+    print("next track")
89
+    dict = bge.logic.globalDict
90
+    plist = dict['mu_playlist']
91
+    cur_song = dict['mu_current_song']
92
+    pl_length = len(dict['mu_playlist'])    
93
+
94
+    if pl_length > 1:
95
+        try:
96
+            plist.remove(cur_song)
97
+        except:
98
+            pass    
99
+
100
+    if pl_length == 1:    
101
+        print('rebuilding playlist')
102
+        file_list = glob.glob(file_name)
103
+        plist = file_list
104
+
105
+    selected = random.choice(plist)
106
+    dict['mu_last_track'] = dict['mu_current_song']
107
+    dict['mu_current_song'] = selected
108
+    dict['mu_playlist'] = plist
109
+    dict['change_track'] = 0
110
+    dict['mu_track_time'] = 0
111
+    play_music()
112
+
113
+def previous_track():
114
+
115
+    print("previous track") 
116
+    dict['mu_current_song'] = dict['mu_last_track']
117
+    play_music()   
118
+
119
+def check_status():
120
+
121
+    sound = bge.logic.getCurrentController().actuators['music_player']
122
+    cur_song = dict['mu_current_song']
123
+    full_path = os.path.join(directory, dict['mu_current_song'])
124
+    sound = bge.logic.getCurrentController().actuators['music_player']
125
+    sound.sound = aud.Factory(full_path)  
126
+
127
+    if sound.time < dict['mu_track_time'] and dict['mu_stopped'] == 0 and dict['change_track'] == 0:
128
+        print('song over, getting new one')
129
+        dict['change_track'] = 1
130
+        dict['mu_track_time'] = 0
131
+    else:
132
+        dict['change_track'] = 0
133
+    dict['mu_track_time'] = sound.time    
134
+
135
+def main(cont):
136
+
137
+    dict = bge.logic.globalDict        
138
+    cur_song = dict['mu_current_song']    
139
+    full_path = os.path.join(directory, dict['mu_current_song'])
140
+    sound = bge.logic.getCurrentController().actuators['music_player']
141
+    sound.sound = aud.Factory(full_path)
142
+    sound.mode = 1
143
+    initer(cont)
144
+    if dict['music_player'] != 0:
145
+        if dict['mu_stopped'] == 1:        
146
+            play_music()
147
+        if dict['change_track'] == 1:
148
+            dict['change_track'] = 0
149
+            next_track() 
150
+
151
+    plist = dict['mu_playlist']  
152
+    pl_length = len(dict['mu_playlist'])    
153
+    if pl_length == 0:
154
+        dict['mu_playlist'] = dict['mu_lib']       
155
+         
156
+    #allow controlls while paused or in replay    
157
+    if dict['npause']  == 1 or dict['playback'] == True:
158
+        if dict['yBut'] == False and dict['last_yBut'] == True:
159
+            if dict['mu_stopped'] == 1:
160
+                play_music() 
161
+            else:
162
+                stop_music(sound)  
163
+        if dict['lBump'] == False and dict['last_lBump'] == True:
164
+            previous_track()
165
+        if dict['rBump'] == False and dict['last_rBump'] == True:
166
+            next_track() 

Loading…
Cancel
Save