-
Notifications
You must be signed in to change notification settings - Fork 0
/
frametime.py
74 lines (60 loc) · 1.8 KB
/
frametime.py
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
73
74
# -*- coding: utf-8 -*-
# File: frametime.py
# Author: Casey Jones
#
# Created on July 20, 2009, 4:48 PM
#
# This file is part of Alpha Beta Gamma (abg).
#
# ABG is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ABG is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ABG. If not, see <http://www.gnu.org/licenses/>.
######
# finds the amount of time it took to render a frame
# and converts pixels/sec to pixels/frame so that
# objects can move at the desired speed no matter
# what the fps is
# This module can also measure the time and figure
# out if a new enemy can be spawned.
import time
#from time import time
start_time = 1
end_time = 0
diff_time = 1
spawn_time = 0
def start():
global start_time
start_time = time.time()
return start_time
def end():
global start_time
global end_time
global diff_time
end_time = time.time()
diff_time = end_time - start_time
if diff_time < 0.010:
time.sleep(0.010 - diff_time)
diff_time = 0.010
return diff_time
def get_diff_time():
return diff_time
def modify_speed(lspeed):
return [diff_time*x for x in lspeed]
def can_create_enemy():
global spawn_time
spawn_time += diff_time
#spawn time is 5 seconds, just a placeholder for now
if spawn_time >= 0.75:
spawn_time = 0
return True
else:
return False