-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simple game with Julia #162
Comments
I think makie should work nicely :) using Makie
res = 500
game = Scene(resolution = (res, res))
campixel!(game)
cell = 10
cells = res ÷ 10
snakelen = 5
middle = cells ÷ 2
snakestart = middle - (snakelen ÷ 2)
segments = Point2f0.(middle, range(snakestart, step = cell, length = snakelen))
snake = scatter!(game, segments, markersize = cell, raw = true, color = :blue)[end]
speed = 1/5
global last_dir = (0, 1)
dir = lift(game.events.keyboardbuttons) do but
global last_dir
ispressed(but, Keyboard.left) && return (last_dir = (-1, 0))
ispressed(but, Keyboard.up) && return (last_dir = (0, 1))
ispressed(but, Keyboard.right) && return (last_dir = (1, 0))
ispressed(but, Keyboard.down) && return (last_dir = (0, -1))
last_dir
end
display(game)
newsnake = copy(segments)
while isopen(game)
curr_snake = snake[1][]
circshift!(newsnake, curr_snake, 1)
newsnake[1] = newsnake[2] .+ Point2f0(dir[] .* cell)
snake[1] = newsnake
newsnake = curr_snake
sleep(speed)
end
|
This snake is impressively neatly coded (and works)! :) Although, after looking at it and trying to understand, I am starting to think Makie might be to "high level" for my intent. I'll open a new issue to clarify. Thanks a lot. |
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey guys,
I am slowly getting back to Julia, with the same longterm aim that I had a few years ago (creating a module for psychological experiment creation, see this issue).
However, in order to start really slowly, I'd like to get familiar with openGL and the related Julia modules by creating a small game, why not a snake-like thing, just to get familiar with how to create windows, move shapes and images and display text.
Do you think that Makie.jl would be a good choice for implementing such a game? Or should I look for lower level API?
Thanks a lot for your answers
The text was updated successfully, but these errors were encountered: