Skip to content

Commit

Permalink
fix joystick example
Browse files Browse the repository at this point in the history
  • Loading branch information
electronstudio committed Jun 26, 2019
1 parent cfc777d commit 8d387c2
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions 14_joystick_input.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,34 @@
"""
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.
Raylib has a game controller API that is a bit different from Pygame's
TODO for Richard: Might simplify this a bit more
"""
from richlib import *

import pygame

joystick = pygame.joystick.Joystick(0)
joystick.init()

alien = Actor('trooper')
alien.size = (20,20,20)
alien.size = (20, 20, 20)
alien.pos = (0, 10, 10)


def draw():
clear()
alien.draw()


def update():
print(joystick.get_axis(0))
# if pyray.is_gamepad_available(0):
# print(pyray.is_gamepad_button_down(0,0))
# cd = pyray.get_gamepad_name(0)
#print(ffi.string(cd))

# print(pyray.get_gamepad_axis_movement(0, 0))
if (keyboard.right):
alien.x = alien.x + 1
elif (keyboard.left):
alien.x = alien.x - 1

run()
if pyray.is_gamepad_available(0):
if pyray.is_gamepad_button_down(0, rl.GAMEPAD_BUTTON_LEFT_FACE_UP):
print("up")
if pyray.is_gamepad_button_down(0, rl.GAMEPAD_BUTTON_RIGHT_FACE_UP):
print("Y")
if pyray.get_gamepad_axis_movement(0, rl.GAMEPAD_AXIS_LEFT_X) > 0.3:
alien.x = alien.x + 1
elif pyray.get_gamepad_axis_movement(0, rl.GAMEPAD_AXIS_LEFT_X) < -0.3:
alien.x = alien.x - 1



run()

"""TODO
make the alien move up and down as well as left and right
make the alien move up/down and forward/back as well as left/right
"""

0 comments on commit 8d387c2

Please sign in to comment.