Haskell Gloss : Making zoom, pan, and all that kind of effects for module Graphics.Gloss.Interface.Pure.Game - haskell

Recently I have been working on making a game with Haskell, and we have been using the library Gloss in order to complete the graphic part. To make a game with Gloss, as you probably know, you have to use Graphics.Gloss.Interface.Pure.Game (or IO game, that's not the main thing to focus here). My doubt is simple. As they say on their description of this module : "Pressing ESC will still abort the program, but you don't get automatic pan and zoom controls like with displayInWindow.". I have been trying to build those two effects but with no sucess. I made an accumulator in my state, called v, that gets the value of 1 when 'reactEvent (EventKey (MouseButton WheelUp) Down _ _) ((px,py),p,mapas,i,players,b,c,d,v) = ((px,py),p,mapas,i,players,b,c,d,1)' and then the function that makes the picture appear would turn it back to 0 after applying the effect needed, creating a cicle. What's the mistake in my logic?
Edit : Added the prints, that's what I am trying to get to work. Also, if anyone has a clue on how to make different camera angles, I would also appreciate some help.
https://imgur.com/3PAqO2x
https://imgur.com/jk93lzQ

Related

Creating graphs using code from Pari-GP, but using Sage's graphing tools

everyone!
I know this is probably a dumb question, but I'm having a lot of trouble with Sage, and it's frustrating the hell out of me. To give a bit of an explanation, I code entirely in pari-gp. I don't have a single problem with my code in pari-gp, I'm just having trouble with interfacing my code with Sage. Which, this is something Sage bolsters, that you can run pari-gp code within sage. I essentially want to run all my processes in pari-gp, but I want to exploit all of Sage's graphing protocols.
What I want to do couldn't be easier. I have a well working function test(x,y), which produces a real number. I don't have any problems running this in pari, everything is kosher. All I want to do is make a graph of test(x,y) = z. Now I know how to run this command in sage, but I don't know how to interface such that test is actually a program running from Pari code.
I'd love to program all my stuff in Sage, but that's just impossible. I need the language Pari, so before you say that I could just translate everything in Sage, it's impossible. I just can't wrap my head around how to interface Pari with Sage. I know it's possible; hell, they advertise it on the main website. I'm just very unclear about how to do the following:
1.) Read a file from my pari-gp root directory: gp.read("myfile.gp").
2.) Inherit the functions, such that gp("test(x,y)"), now runs as though it runs in the GP terminal.
3.) Graph said function test(x,y) using Sage's graphing protocols.
Any help is greatly appreciated. I know I'm just forgetting to do something dumb, or I'm missing a step in how I'm doing it.
Any help is greatly appreciated!
Let us start with:
sage: gp("test(x, y) = sin(x*y)")
(x,y)->sin(x*y)
sage: gp("test(1, 1)")
0.84147098480789650665250232163029899962
sage: type(_)
<class 'sage.interfaces.gp.GpElement'>
So the printed version of gp("test(1, 1)") looks like a number, but it is not a float instance. Note that py3 has some f-strings, so we can easily plug in values of variables x, y inside the gp("test(...)") . I will use f-strings to define the sage function...
And we are not far away from the final plot:
sage: f = lambda x, y: float( gp(f"test({x}, {y})") )
sage: plot3d(f, [0, pi], [0, pi])
Launched html viewer for Graphics3d Object

kivy switch_to screen on if statement doesn't work

I could REALLY use your help with this one.
I'm trying to make a sort-of voice command operated menu for a toddler's learning app and kivy is giving me a headache
all of my screens are correctly defined and load as intended if the buttons are pressed but the voice commands, even though they register correctly and carry over their variables as intended they don't seem to have the desired effect when asked to act upon ScreenManager when the if statement is fulfilled
def on_enter(self):
....
Command.start()
Command.introMenu()
......
if Command.sel == "shapes":
ScreenManager().switch_to = "shapes"
elif Command.sel == "colours":
ScreenManager().switch_to = "colours"
......
else:
pass
the variable Command.sel is captured from a dependency, defined as a string and carried correctly as far as I can tell from the variables view in debugging
yet even though everything seems to be in order (in fact no error messages appear at all) the desired screen is not called when the if condition is met
what am I doing wrong here???
full code here
(please ignore the Greek bits in the code... it's just strings, imagine it's any other language for that matter...)
thank you!
issue resolved
correct command was
self.parent.current = "your_screen_name"
answer (eventually) found here

Making a Map in Gloss

In PL class we were asked to make a pacman clone in Gloss, nevertheless I got stuck at making the map.
My approach was taking a .png of the classical pacman first level, and paste it in the render function so I don't need to draw everything by hand.
Nevertheless by doing so, the games lags horribly, I'm assuming that it's because the game renders the map in every step.
Is there some way to just render the map as a background a single time, or avoid the huge lag? Or am I taking a bad approach and it would it be better if I draw the components by hand using the Picture module?
I append the render function just in case I'm wiring it badly:
render :: PacmanGame -> IO Picture
render game = do
sprite <- fmap (head) (playerSprites $ player game)
let playerOne = uncurry translate (playerPos $ player game) $ sprite
map' <- pacmanMap
return $ pictures [map', playerOne]
Where pacmanMap :: IO Picture
It looks like you’re reloading the file in every call to render. You need to run the pacmanMap :: IO Picture action once, for example at startup in main; then you can just return the resulting static Picture from your render function. For example, you might store the reference to the current background image in the PacmanGame, or pass it as an additional argument to render.

my questions is about code in GDscript (language programing in godot engine)

sprite (attack) is not working in case :
if Input.is_action_just_pressed("ui_attack"):
$Sprite.play("attack")
but in case:
if Input.is_action_pressed("ui_attack"):
$Sprite.play("attack")
it's working !!!!
what is the solution code pleas?!! Because I want one click on the keyboard to work of sprite...
Have you tried using if event.is_action_pressed("ui_attack"): instead?
I've found that event works better than Input if I only want one action after a button press and not multiple.
If it still doesn't work, try adding if event.is_action_released("ui_attack"): afterwards. You may have to put an additional command afterward to make the code acceptable to the engine, such as print("Key Released"). In my case, it never ended up printing anything to console, but it did only give me one action per button press.
I am assuming this is the question you were looking for an answer to. If not, please disregard, I have been awake all night and am prone to confusion.
EDIT: I forgot to add that it must be in a func _input(event) function to work properly. I've included a simple example that prints text to the console once per press of the left button. See below:
extends Node2D
var text = PrintText()
func PrintText():
return("Print Text Once")
func _ready():
pass
func _input(event):
if event.is_action_pressed("ui_left"):
print(text)
(P.S. I only discovered Godot in the last week or so, but have been crash-coursing myself ever since. I love the engine, but if my understanding comes off as "basic", forgive me.)

Disable surround sound with openAL

I'm french so sorry for my english.
I'm currently making a splitscreen 2D game with LWJGL.
I'm using the openAL API which is given with LWJGL. Everything seems to works perfectly. Well, too perfectly to be honest : because I'm making a splitscreen game and because I can't have 2 listener sharing the same context, I want to get rid of the left/right panning.
Sound attenuation work well. I change the position of sound depending on the closest player.
The listener doesn't change, always at (0,0,0). The sound position is (soundPosition - closestPlayerPosition).
So how do I get rid of the surround thing ? I want to keep sound attenuation over distance, of course.
I could simply put the sound on the Z-axis depending on the distance but this seem a bit silly (I have to compute the distance every time I have to update a sound position).
Thanks !
When you calculate the sound's position (soundPosition - closestPlayerPosition) take the length of the vector returned by that and then put that sound directly down the z axis that distance away from the player.
Example:
soundPosition = (1.4,0,1.4)
closestPlayerPosition = (0,0,0)
soundDirection = soundPosition - closestPlayerPosition = (1.4,0,1.4)
soundDistance = soundDirection.Length()
And finally, the final position of your sound:
finalSoundPosition = (0,0,soundDistance) = (0,0,2)
Edit: I didn't notice you already suggested this. To be honest I think this is fine, and its the only way to solve your problem beyond rewriting stuff internal to openAL

Resources