@@ -34,187 +34,6 @@ Game build_chai_game(chaiscript::ChaiScript &chai)
34
34
return game;
35
35
}
36
36
37
- Game build_game ()
38
- {
39
- Game game;
40
-
41
- // create the tilemap from the level definition
42
- Tile_Map map (game, " resources/Maps/worldmap.json" , {{2 , Tile_Properties (false )}});
43
- // Tile_Map map(game, "resources/Maps/test.json", {{2, Tile_Properties(false)}});
44
-
45
-
46
- const auto collision_action = [](const float t_game_time, const float t_simulation_time, Game &t_game, Object &t_obj, sf::Sprite &/* t_collision*/ )
47
- {
48
- t_game.show_object_interaction_menu (t_game_time, t_simulation_time, t_obj);
49
- };
50
-
51
- const auto bobby_pinhead_conversation_tree =
52
- Conversation ({
53
- Question (" Pinhead Town?" ,
54
- {Answer (" Bobby Pinhead" , " Pinhead town is where we call home. Be sure to check out the shops." )},
55
- [](const float , const float , Game &t_game, Object &) { return t_game.get_flag (" pinhead_town" ); },
56
- [](const float , const float , Game &, Object &) { }
57
- ),
58
- Question (" Treasure in forest?" ,
59
- {Answer (" Bobby Pinhead" , " I've heard about it...\n but I don't know anyone who has found it yet." ),
60
- Answer (" Random Pinhead" , " Bah, treasure in the forest." )},
61
- [](const float , const float , Game &t_game, Object &) { return t_game.get_flag (" treasure_adventure" ); },
62
- [](const float , const float , Game &, Object &) { }
63
- )
64
- });
65
-
66
-
67
-
68
- const auto random_pinhead_conversation_tree =
69
- Conversation ({
70
- Question (" Where am I?" ,
71
- {Answer (" Random Pinhead" , " You are in the Pinhead Town Center." ),
72
- Answer (" Bobby Pinhead" , " Pinhead Town is a great place, you'll like it here.\n There is lots of adventure." )},
73
- [](const float , const float , Game &, Object &) { return true ; },
74
- [](const float , const float , Game &t_game, Object &) { t_game.set_flag (" pinhead_town" , true ); }
75
- ),
76
- Question (" Treasure In Forest?" ,
77
- {Answer (" Random Pinhead" , " I'm skeptical about that treasure.\n Some people say they have seen it,\n but why haven't they become rich?" ),
78
- Answer (" Random Pinhead" , " I think it's just a pipe dream of that Baker.\n He's the one who likes to talk about it so much." )},
79
- [](const float , const float , Game &t_game, Object &) { return t_game.get_flag (" treasure_adventure" ); },
80
- [](const float , const float , Game &, Object &) { }
81
- ),
82
- });
83
-
84
-
85
- const auto bobby_pinhead_actions = [bobby_pinhead_conversation_tree](const float /* t_game_time*/ , const float /* t_simulation_time*/ , Game &/* t_game*/ , Object &/* t_obj*/ ){
86
- return std::vector<Object_Action>{
87
- { " Look" ,
88
- [](const float , const float , Game &t_game, Object &)
89
- {
90
- t_game.show_message_box (" Bobby Pinhead.\n\n A pinhead youth." );
91
- }
92
- },
93
- { " Talk To" ,
94
- [bobby_pinhead_conversation_tree](const float t_game_time, const float t_simulation_time, Game &t_game, Object &t_obj)
95
- {
96
- t_game.show_conversation (t_game_time, t_simulation_time, t_obj, bobby_pinhead_conversation_tree);
97
- }
98
- },
99
- };
100
- };
101
-
102
- const auto random_pinhead_actions = [random_pinhead_conversation_tree](const float /* t_game_time*/ , const float /* t_simulation_time*/ , Game &/* t_game*/ , Object &/* t_obj*/ ){
103
- return std::vector<Object_Action>{
104
- { " Look" ,
105
- [](const float , const float , Game &t_game, Object &)
106
- {
107
- t_game.show_message_box (" A Random Pinhead.\n\n One of the local pinheads." );
108
- }
109
- },
110
- { " Talk To" ,
111
- [random_pinhead_conversation_tree](const float t_game_time, const float t_simulation_time, Game &t_game, Object &t_obj)
112
- {
113
- t_game.show_conversation (t_game_time, t_simulation_time, t_obj, random_pinhead_conversation_tree);
114
- }
115
- },
116
- };
117
- };
118
-
119
- const auto left_door_actions = [](const float /* t_game_time*/ , const float /* t_simulation_time*/ , Game &/* t_game*/ , Object &/* t_obj*/ ){
120
- return std::vector<Object_Action>{
121
- { " Look" ,
122
- [](const float , const float , Game &t_game, Object &)
123
- {
124
- t_game.show_message_box (" The Bakery" );
125
- }
126
- },
127
- };
128
- };
129
-
130
- const auto path_actions = [](const float /* t_game_time*/ , const float /* t_simulation_time*/ , Game &/* t_game*/ , Object &/* t_obj*/ ){
131
- return std::vector<Object_Action>{
132
- { " Look" ,
133
- [](const float , const float , Game &t_game, Object &)
134
- {
135
- t_game.show_message_box (" Forest Path" );
136
- }
137
- },
138
- };
139
- };
140
-
141
- const auto gate_actions = [](const float /* t_game_time*/ , const float /* t_simulation_time*/ , Game &/* t_game*/ , Object &/* t_obj*/ ){
142
- return std::vector<Object_Action>{
143
- { " Look" ,
144
- [](const float , const float , Game &t_game, Object &)
145
- {
146
- t_game.show_message_box (" Garden Gate" );
147
- }
148
- },
149
- };
150
- };
151
-
152
-
153
- const auto up_door_actions = [](const float /* t_game_time*/ , const float /* t_simulation_time*/ , Game &/* t_game*/ , Object &/* t_obj*/ ){
154
- return std::vector<Object_Action>{
155
- { " Look" ,
156
- [](const float , const float , Game &t_game, Object &)
157
- {
158
- t_game.show_message_box (" The General Store" );
159
- }
160
- },
161
- { " Talk To" ,
162
- [](const float , const float , Game &t_game, Object &)
163
- {
164
- t_game.show_message_box (" You hear a voice from beyond the door:\n 'Come in, we're open!'" );
165
- }
166
- },
167
- };
168
- };
169
-
170
- /*
171
- Object general_store_door("General Store Door", game.get_texture("resources/pinheads_up_door.png"), 48, 26, 0, collision_action, up_door_actions);
172
- general_store_door.setPosition(299,134);
173
- map.add_object(general_store_door);
174
-
175
- Object bakery_door("Bakery Store Door", game.get_texture("resources/pinheads_left_door.png"), 22, 40, 0, collision_action, left_door_actions);
176
- bakery_door.setPosition(138, 191);
177
- map.add_object(bakery_door);
178
-
179
- Object path("Forest Path", game.get_texture("resources/pinheads_path.png"), 22, 11, 0, collision_action, path_actions);
180
- path.setPosition(137, 168);
181
- map.add_object(path);
182
-
183
- Object gate("Garden Gate", game.get_texture("resources/pinheads_gate.png"), 39, 12, 0, collision_action, gate_actions);
184
- gate.setPosition(344, 148);
185
- map.add_object(gate);
186
-
187
- Object bobby_pinhead("Bobby Pinhead", game.get_texture("resources/pinheads_pinhead.png"), 26, 26, 0, collision_action, bobby_pinhead_actions);
188
- bobby_pinhead.setPosition(270,220);
189
- map.add_object(bobby_pinhead);
190
-
191
- Object random_pinhead("Random Pinhead", game.get_texture("resources/pinheads_pinhead.png"), 26, 26, 0, collision_action, random_pinhead_actions);
192
- random_pinhead.setPosition(240,250);
193
- map.add_object(random_pinhead);
194
- */
195
-
196
- map.add_enter_action (
197
- [](Game &t_game){
198
- t_game.teleport_to (200 , 200 );
199
- t_game.show_message_box (" Welcome to Pinhead Town." );
200
- }
201
- );
202
-
203
- game.add_map (" town" , map);
204
- game.set_avatar (game.get_texture (" resources/pinheads_marble.png" ));
205
-
206
-
207
- game.add_start_action (
208
- [](Game &t_game) {
209
- t_game.show_message_box (" Welcome to\n Pinheads:\n Everything You Need." );
210
- t_game.add_queued_action ([](const float , const float , Game &t_t_game) {
211
- t_t_game.enter_map (" town" );
212
- });
213
- }
214
- );
215
-
216
- return game;
217
- }
218
37
219
38
int main ()
220
39
{
@@ -223,6 +42,7 @@ int main()
223
42
// create the window
224
43
sf::RenderWindow window (sf::VideoMode (800 , 600 ), " Tilemap" );
225
44
45
+ window.setVerticalSyncEnabled (true );
226
46
auto chaiscript = create_chaiscript ();
227
47
228
48
auto game = build_chai_game (*chaiscript);
@@ -246,7 +66,9 @@ int main()
246
66
247
67
if (frame_count % 100 == 0 )
248
68
{
249
- std::cout << 1 /time_elapsed << " fps avg fps: " << frame_count / game_time << ' \n ' ;
69
+ const auto avgfps = frame_count / game_time;
70
+ const auto curfps = 1 / time_elapsed;
71
+ std::cout << curfps << " fps avg fps: " << avgfps << ' \n ' ;
250
72
}
251
73
252
74
last_frame = cur_frame;
@@ -262,7 +84,7 @@ int main()
262
84
{
263
85
// update the view to the new size of the window
264
86
window.setSize (sf::Vector2u (event.size .width , event.size .height ));
265
- fixed = sf::View (sf::FloatRect (0 ,0 ,event.size .width , event.size .height ));
87
+ fixed = sf::View (sf::FloatRect (0 ,0 , float ( event.size .width ), float ( event.size .height ) ));
266
88
}
267
89
}
268
90
0 commit comments