@@ -138,11 +138,8 @@ bool MyEventReceiver::OnEvent(const SEvent &event)
138
138
#endif
139
139
140
140
} else if (event.EventType == irr::EET_JOYSTICK_INPUT_EVENT) {
141
- /* TODO add a check like:
142
- if (event.JoystickEvent != joystick_we_listen_for)
143
- return false;
144
- */
145
- return joystick->handleEvent (event.JoystickEvent );
141
+ // joystick may be nullptr if game is launched with '--random-input' parameter
142
+ return joystick && joystick->handleEvent (event.JoystickEvent );
146
143
} else if (event.EventType == irr::EET_MOUSE_INPUT_EVENT) {
147
144
// Handle mouse events
148
145
KeyPress key;
@@ -243,4 +240,39 @@ void RandomInputHandler::step(float dtime)
243
240
}
244
241
}
245
242
mousepos += mousespeed;
243
+ static bool useJoystick = false ;
244
+ {
245
+ static float counterUseJoystick = 0 ;
246
+ counterUseJoystick -= dtime;
247
+ if (counterUseJoystick < 0.0 ) {
248
+ counterUseJoystick = 5.0 ; // switch between joystick and keyboard direction input
249
+ useJoystick = !useJoystick;
250
+ }
251
+ }
252
+ if (useJoystick) {
253
+ static float counterMovement = 0 ;
254
+ counterMovement -= dtime;
255
+ if (counterMovement < 0.0 ) {
256
+ counterMovement = 0.1 * Rand (1 , 40 );
257
+ movementSpeed = Rand (0 ,100 )*0.01 ;
258
+ movementDirection = Rand (-100 , 100 )*0.01 * M_PI;
259
+ }
260
+ } else {
261
+ bool f = keydown[keycache.key [KeyType::FORWARD]],
262
+ l = keydown[keycache.key [KeyType::LEFT]];
263
+ if (f || l) {
264
+ movementSpeed = 1 .0f ;
265
+ if (f && !l)
266
+ movementDirection = 0.0 ;
267
+ else if (!f && l)
268
+ movementDirection = -M_PI_2;
269
+ else if (f && l)
270
+ movementDirection = -M_PI_4;
271
+ else
272
+ movementDirection = 0.0 ;
273
+ } else {
274
+ movementSpeed = 0.0 ;
275
+ movementDirection = 0.0 ;
276
+ }
277
+ }
246
278
}
0 commit comments