forked from AdamAtomic/flixel
-
Notifications
You must be signed in to change notification settings - Fork 1
/
flx.py
146 lines (138 loc) · 4.61 KB
/
flx.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#! /usr/local/bin/python
import os
import sys
#BASIC SCRIPT PRESETS
width = 320 # Width of your game in 'true' pixels (ignoring zoom)
height = 240 # Height of your game in 'true' pixels
zoom = 2 # How chunky you want your pixels
src = 'src/' # Name of the source folder under the project folder (if there is one!)
preloader = 'Preloader' # Name of the preloader class
flexBuilder = True # Whether or not to generate a Default.css file
menuState = 'MenuState' # Name of menu state class
playState = 'PlayState' # Name of play state class
#Get name of project
if len(sys.argv) <= 1:
sys.exit(0)
project = sys.argv[1]
#Generate basic game class
filename = project+'/'+src+project+'.as';
try:
fo = open(filename, 'w')
except IOError:
print('Can\'t open '+filename+' for writing.')
sys.exit(0)
lines = []
lines.append('package\r\n')
lines.append('{\r\n')
lines.append('\timport org.flixel.*;\r\n')
lines.append('\t[SWF(width="'+str(width*zoom)+'", height="'+str(height*zoom)+'", backgroundColor="#000000")]\r\n')
lines.append('\t[Frame(factoryClass="Preloader")]\r\n')
lines.append('\r\n')
lines.append('\tpublic class '+project+' extends FlxGame\r\n')
lines.append('\t{\r\n')
lines.append('\t\tpublic function '+project+'()\r\n')
lines.append('\t\t{\r\n')
lines.append('\t\t\tsuper('+str(width)+','+str(height)+','+menuState+','+str(zoom)+');\r\n')
lines.append('\t\t}\r\n')
lines.append('\t}\r\n')
lines.append('}\r\n')
fo.writelines(lines)
fo.close()
#Generate preloader
filename = project+'/'+src+preloader+'.as';
try:
fo = open(filename, 'w')
except IOError:
print('Can\'t open '+filename+' for writing.')
sys.exit(0)
lines = []
lines.append('package\r\n')
lines.append('{\r\n')
lines.append('\timport org.flixel.system.FlxPreloader;\r\n')
lines.append('\r\n')
lines.append('\tpublic class '+preloader+' extends FlxPreloader\r\n')
lines.append('\t{\r\n')
lines.append('\t\tpublic function '+preloader+'()\r\n')
lines.append('\t\t{\r\n')
lines.append('\t\t\tclassName = "'+project+'";\r\n')
lines.append('\t\t\tsuper();\r\n')
lines.append('\t\t}\r\n')
lines.append('\t}\r\n')
lines.append('}\r\n')
fo.writelines(lines)
fo.close()
#Generate Default.css
if flexBuilder:
filename = project+'/'+src+'Default.css';
try:
fo = open(filename, 'w')
except IOError:
print('Can\'t open '+filename+' for writing.')
sys.exit(0)
fo.write('Add this: "-defaults-css-url Default.css"\nto the project\'s additonal compiler arguments.')
fo.close()
#Generate game menu
filename = project+'/'+src+menuState+'.as';
try:
fo = open(filename, 'w')
except IOError:
print('Can\'t open '+filename+' for writing.')
sys.exit(0)
lines = []
lines.append('package\r\n')
lines.append('{\r\n')
lines.append('\timport org.flixel.*;\r\n')
lines.append('\r\n')
lines.append('\tpublic class '+menuState+' extends FlxState\r\n')
lines.append('\t{\r\n')
lines.append('\t\toverride public function create():void\r\n')
lines.append('\t\t{\r\n')
lines.append('\t\t\tvar t:FlxText;\r\n')
lines.append('\t\t\tt = new FlxText(0,FlxG.height/2-10,FlxG.width,"'+project+'");\r\n')
lines.append('\t\t\tt.size = 16;\r\n')
lines.append('\t\t\tt.alignment = "center";\r\n')
lines.append('\t\t\tadd(t);\r\n')
lines.append('\t\t\tt = new FlxText(FlxG.width/2-50,FlxG.height-20,100,"click to play");\r\n')
lines.append('\t\t\tt.alignment = "center";\r\n')
lines.append('\t\t\tadd(t);\r\n')
lines.append('\t\t\t\r\n')
lines.append('\t\t\tFlxG.mouse.show();\r\n')
lines.append('\t\t}\r\n')
lines.append('\r\n')
lines.append('\t\toverride public function update():void\r\n')
lines.append('\t\t{\r\n')
lines.append('\t\t\tsuper.update();\r\n')
lines.append('\r\n')
lines.append('\t\t\tif(FlxG.mouse.justPressed())\r\n')
lines.append('\t\t\t{\r\n')
lines.append('\t\t\t\tFlxG.mouse.hide();\r\n')
lines.append('\t\t\t\tFlxG.switchState(new PlayState());\r\n')
lines.append('\t\t\t}\r\n')
lines.append('\t\t}\r\n')
lines.append('\t}\r\n')
lines.append('}\r\n')
fo.writelines(lines)
fo.close()
#Generate basic game state
filename = project+'/'+src+playState+'.as';
try:
fo = open(filename, 'w')
except IOError:
print('Can\'t open '+filename+' for writing.')
sys.exit(0)
lines = []
lines.append('package\r\n')
lines.append('{\r\n')
lines.append('\timport org.flixel.*;\r\n')
lines.append('\r\n')
lines.append('\tpublic class '+playState+' extends FlxState\r\n')
lines.append('\t{\r\n')
lines.append('\t\toverride public function create():void\r\n')
lines.append('\t\t{\r\n')
lines.append('\t\t\tadd(new FlxText(0,0,100,"INSERT GAME HERE"));\r\n')
lines.append('\t\t}\r\n')
lines.append('\t}\r\n')
lines.append('}\r\n')
fo.writelines(lines)
fo.close()
print('Successfully generated game class, preloader, menu state, and play state.')