Skip to content

Commit 8d387c2

Browse files
fix joystick example
1 parent cfc777d commit 8d387c2

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

14_joystick_input.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,34 @@
11
"""
2-
Some game controllers have different inputs and some are not be compatible so don'tbe surprised if this doesnt quite work properly! Use joystick_tester.py to test yours.
2+
Raylib has a game controller API that is a bit different from Pygame's
3+
TODO for Richard: Might simplify this a bit more
34
"""
45
from richlib import *
56

6-
import pygame
7-
8-
joystick = pygame.joystick.Joystick(0)
9-
joystick.init()
10-
117
alien = Actor('trooper')
12-
alien.size = (20,20,20)
8+
alien.size = (20, 20, 20)
139
alien.pos = (0, 10, 10)
1410

11+
1512
def draw():
1613
clear()
1714
alien.draw()
1815

1916

2017
def update():
21-
print(joystick.get_axis(0))
22-
# if pyray.is_gamepad_available(0):
23-
# print(pyray.is_gamepad_button_down(0,0))
24-
# cd = pyray.get_gamepad_name(0)
25-
#print(ffi.string(cd))
26-
27-
# print(pyray.get_gamepad_axis_movement(0, 0))
28-
if (keyboard.right):
29-
alien.x = alien.x + 1
30-
elif (keyboard.left):
31-
alien.x = alien.x - 1
32-
33-
run()
18+
if pyray.is_gamepad_available(0):
19+
if pyray.is_gamepad_button_down(0, rl.GAMEPAD_BUTTON_LEFT_FACE_UP):
20+
print("up")
21+
if pyray.is_gamepad_button_down(0, rl.GAMEPAD_BUTTON_RIGHT_FACE_UP):
22+
print("Y")
23+
if pyray.get_gamepad_axis_movement(0, rl.GAMEPAD_AXIS_LEFT_X) > 0.3:
24+
alien.x = alien.x + 1
25+
elif pyray.get_gamepad_axis_movement(0, rl.GAMEPAD_AXIS_LEFT_X) < -0.3:
26+
alien.x = alien.x - 1
3427

3528

3629

30+
run()
3731

3832
"""TODO
39-
make the alien move up and down as well as left and right
33+
make the alien move up/down and forward/back as well as left/right
4034
"""

0 commit comments

Comments
 (0)