Re: issue with multiple variables in if statement
To hopefully help, and not make things more of a mess, I've made some changes to Lucia's bass_example.py found in examples/3D. All you need to run this are Lucia, a file called audio.ogg and paste this into a file. If you have lucia from git, you can just plop this in if you want, but change the name so you can study them side by side to see what I did.
There are probably some better practices than what I've done here, so maybe some critique from others and we can fabricobble something together here. I'm really not much of a coder but this seemed more sensible than what they had.
# note> This example needs an @audio.ogg@ file placed in the same directory to run.
import sys, os
sys.path.append(".") from math import radians import time import lucia import lucia.utils class Player(): """ Represents the player in this example. """ def __init__(self): self.direction = 0 # north if this shit ain't weird self.vector = lucia.utils.rotation.Vector() def get_coords(self): return self.vector.coords def get_direction(self): return self.direction def turn_left(self, amt): """ Turns the player left the specified amount. """ self.direction = lucia.utils.rotation.turnleft(self.get_direction(), amt) def turn_right(self, amt): """ Turns the player right the specified amount. """ self.direction = lucia.utils.rotation.turnright(self.get_direction(), amt) def move(self, desired_direction): """ Move player. Call this as you would lucia.utils.rotation.move() but without the tuple representing the current coordinates. """ self.vector = lucia.utils.rotation.move(self.get_coords(), desired_direction) player = Player() def main(): lucia.initialize(audiobackend=lucia.AudioBackend.BASS) window = lucia.show_window() current_direction = 0 pool = lucia.audio_backend.SoundPool() s = pool.play_3d( os.path.join(os.getcwd(), "audio.ogg"), 5, 5, 0, 10, 10, 0, looping=True ) # Main Loop while True: lucia.process_events() handle_inputs(current_direction) listener_x, listener_y, listener_z = player.get_coords() pool.update_listener_3d(listener_x, listener_y, listener_z, player.get_direction()) time.sleep(0.005) def handle_inputs(dir): if lucia.key_pressed(lucia.K_LEFT): player.turn_left(5) if lucia.key_pressed(lucia.K_RIGHT): player.turn_right(5) if lucia.key_pressed(lucia.K_w): player.move(player.get_direction()) if lucia.key_pressed(lucia.K_a): player.move(player.get_direction() - 90) if lucia.key_pressed(lucia.K_s): player.move(player.get_direction() + 180) if lucia.key_pressed(lucia.K_d): player.move(player.get_direction()+ 90) if lucia.key_pressed(lucia.K_ESCAPE): lucia.quit() if lucia.key_pressed(lucia.K_c): lucia.output.output(str(player.get_coords())) if lucia.key_pressed(lucia.K_x): lucia.output.output(f"facing {player.get_direction()}") if __name__ == "__main__": main()
-- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector