Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 146 lines (138 sloc) 4.717 kb
b8dcecd @AdamAtomic added flx.py to the flixel project
AdamAtomic authored
1 #! /usr/local/bin/python
2 import os
3 import sys
4
5 #BASIC SCRIPT PRESETS
6 width = 320 # Width of your game in 'true' pixels (ignoring zoom)
7 height = 240 # Height of your game in 'true' pixels
8 zoom = 2 # How chunky you want your pixels
9 src = 'src/' # Name of the source folder under the project folder (if there is one!)
10 preloader = 'Preloader' # Name of the preloader class
11 flexBuilder = True # Whether or not to generate a Default.css file
12 menuState = 'MenuState' # Name of menu state class
13 playState = 'PlayState' # Name of play state class
14
15 #Get name of project
16 if len(sys.argv) <= 1:
17 sys.exit(0)
18 project = sys.argv[1]
19
20 #Generate basic game class
21 filename = project+'/'+src+project+'.as';
22 try:
23 fo = open(filename, 'w')
24 except IOError:
25 print('Can\'t open '+filename+' for writing.')
26 sys.exit(0)
27 lines = []
28 lines.append('package\r\n')
29 lines.append('{\r\n')
30 lines.append('\timport org.flixel.*;\r\n')
31 lines.append('\t[SWF(width="'+str(width*zoom)+'", height="'+str(height*zoom)+'", backgroundColor="#000000")]\r\n')
32 lines.append('\t[Frame(factoryClass="Preloader")]\r\n')
33 lines.append('\r\n')
34 lines.append('\tpublic class '+project+' extends FlxGame\r\n')
35 lines.append('\t{\r\n')
36 lines.append('\t\tpublic function '+project+'()\r\n')
37 lines.append('\t\t{\r\n')
38 lines.append('\t\t\tsuper('+str(width)+','+str(height)+','+menuState+','+str(zoom)+');\r\n')
39 lines.append('\t\t}\r\n')
40 lines.append('\t}\r\n')
41 lines.append('}\r\n')
42 fo.writelines(lines)
43 fo.close()
44
45 #Generate preloader
46 filename = project+'/'+src+preloader+'.as';
47 try:
48 fo = open(filename, 'w')
49 except IOError:
50 print('Can\'t open '+filename+' for writing.')
51 sys.exit(0)
52 lines = []
53 lines.append('package\r\n')
54 lines.append('{\r\n')
e0b6a32 @AdamAtomic adjusted mouse out/over behavior
AdamAtomic authored
55 lines.append('\timport org.flixel.system.FlxPreloader;\r\n')
b8dcecd @AdamAtomic added flx.py to the flixel project
AdamAtomic authored
56 lines.append('\r\n')
c934035 @AdamAtomic rebuilt preloader, worked on group collisions
AdamAtomic authored
57 lines.append('\tpublic class '+preloader+' extends FlxPreloader\r\n')
b8dcecd @AdamAtomic added flx.py to the flixel project
AdamAtomic authored
58 lines.append('\t{\r\n')
59 lines.append('\t\tpublic function '+preloader+'()\r\n')
60 lines.append('\t\t{\r\n')
61 lines.append('\t\t\tclassName = "'+project+'";\r\n')
62 lines.append('\t\t\tsuper();\r\n')
63 lines.append('\t\t}\r\n')
64 lines.append('\t}\r\n')
65 lines.append('}\r\n')
66 fo.writelines(lines)
67 fo.close()
68
69 #Generate Default.css
70 if flexBuilder:
71 filename = project+'/'+src+'Default.css';
72 try:
73 fo = open(filename, 'w')
74 except IOError:
75 print('Can\'t open '+filename+' for writing.')
76 sys.exit(0)
5ef42e1 @AdamAtomic first commit of v2.0, tons of changes to everything, docs and porting gu...
AdamAtomic authored
77 fo.write('Add this: "-defaults-css-url Default.css"\nto the project\'s additonal compiler arguments.')
b8dcecd @AdamAtomic added flx.py to the flixel project
AdamAtomic authored
78 fo.close()
79
80 #Generate game menu
81 filename = project+'/'+src+menuState+'.as';
82 try:
83 fo = open(filename, 'w')
84 except IOError:
85 print('Can\'t open '+filename+' for writing.')
86 sys.exit(0)
87 lines = []
88 lines.append('package\r\n')
89 lines.append('{\r\n')
90 lines.append('\timport org.flixel.*;\r\n')
91 lines.append('\r\n')
92 lines.append('\tpublic class '+menuState+' extends FlxState\r\n')
93 lines.append('\t{\r\n')
5ef42e1 @AdamAtomic first commit of v2.0, tons of changes to everything, docs and porting gu...
AdamAtomic authored
94 lines.append('\t\toverride public function create():void\r\n')
b8dcecd @AdamAtomic added flx.py to the flixel project
AdamAtomic authored
95 lines.append('\t\t{\r\n')
96 lines.append('\t\t\tvar t:FlxText;\r\n')
97 lines.append('\t\t\tt = new FlxText(0,FlxG.height/2-10,FlxG.width,"'+project+'");\r\n')
98 lines.append('\t\t\tt.size = 16;\r\n')
99 lines.append('\t\t\tt.alignment = "center";\r\n')
100 lines.append('\t\t\tadd(t);\r\n')
101 lines.append('\t\t\tt = new FlxText(FlxG.width/2-50,FlxG.height-20,100,"click to play");\r\n')
102 lines.append('\t\t\tt.alignment = "center";\r\n')
103 lines.append('\t\t\tadd(t);\r\n')
5ef42e1 @AdamAtomic first commit of v2.0, tons of changes to everything, docs and porting gu...
AdamAtomic authored
104 lines.append('\t\t\t\r\n')
105 lines.append('\t\t\tFlxG.mouse.show();\r\n')
b8dcecd @AdamAtomic added flx.py to the flixel project
AdamAtomic authored
106 lines.append('\t\t}\r\n')
107 lines.append('\r\n')
108 lines.append('\t\toverride public function update():void\r\n')
109 lines.append('\t\t{\r\n')
110 lines.append('\t\t\tsuper.update();\r\n')
c5c8369 @AdamAtomic v2.35 - bounding boxes and a few other things
AdamAtomic authored
111 lines.append('\r\n')
b8dcecd @AdamAtomic added flx.py to the flixel project
AdamAtomic authored
112 lines.append('\t\t\tif(FlxG.mouse.justPressed())\r\n')
c5c8369 @AdamAtomic v2.35 - bounding boxes and a few other things
AdamAtomic authored
113 lines.append('\t\t\t{\r\n')
114 lines.append('\t\t\t\tFlxG.mouse.hide();\r\n')
e09658a @AdamAtomic fixed debug visuals for paths and advance node check for path motion
AdamAtomic authored
115 lines.append('\t\t\t\tFlxG.switchState(new PlayState());\r\n')
c5c8369 @AdamAtomic v2.35 - bounding boxes and a few other things
AdamAtomic authored
116 lines.append('\t\t\t}\r\n')
b8dcecd @AdamAtomic added flx.py to the flixel project
AdamAtomic authored
117 lines.append('\t\t}\r\n')
118 lines.append('\t}\r\n')
119 lines.append('}\r\n')
120 fo.writelines(lines)
121 fo.close()
122
123 #Generate basic game state
124 filename = project+'/'+src+playState+'.as';
125 try:
126 fo = open(filename, 'w')
127 except IOError:
128 print('Can\'t open '+filename+' for writing.')
129 sys.exit(0)
130 lines = []
131 lines.append('package\r\n')
132 lines.append('{\r\n')
133 lines.append('\timport org.flixel.*;\r\n')
134 lines.append('\r\n')
135 lines.append('\tpublic class '+playState+' extends FlxState\r\n')
136 lines.append('\t{\r\n')
5ef42e1 @AdamAtomic first commit of v2.0, tons of changes to everything, docs and porting gu...
AdamAtomic authored
137 lines.append('\t\toverride public function create():void\r\n')
b8dcecd @AdamAtomic added flx.py to the flixel project
AdamAtomic authored
138 lines.append('\t\t{\r\n')
139 lines.append('\t\t\tadd(new FlxText(0,0,100,"INSERT GAME HERE"));\r\n')
140 lines.append('\t\t}\r\n')
141 lines.append('\t}\r\n')
142 lines.append('}\r\n')
143 fo.writelines(lines)
144 fo.close()
145
146 print('Successfully generated game class, preloader, menu state, and play state.')
Something went wrong with that request. Please try again.