Add a game director #1

Closed
opened 2023-11-06 23:58:50 +01:00 by sacha · 2 comments
Owner

This is the main game loop and it will preserve state, do checks.

Essentially the main function handles initialization of the tool by parsing flags, initializing tcell, and handig off parameters to the game director.

The game director listens for the events:

  • Resize: pause the game, show an error when the terminal dimensions are smaller than 80x24
  • Keypress: space to (un)pause, WASD/^ to handle direction, q to (rage) quit
  • Time-passed: Move the snake into the given direction

This needs some testing.

This is the main game loop and it will preserve state, do checks. Essentially the main function handles initialization of the tool by parsing flags, initializing tcell, and handig off parameters to the game director. The game director listens for the events: * Resize: pause the game, show an error when the terminal dimensions are smaller than 80x24 * Keypress: space to (un)pause, WASD/^<v> to handle direction, q to (rage) quit * Time-passed: Move the snake into the given direction This needs some testing.
Author
Owner

I have added a game director, and it doesn't work. tcell doesn't seem to have a time event I can listen to next to key presses and resizes, so I will need to split this up. There is this https://github.com/gdamore/tcell/blob/v2.6.0/event.go#L30 and *EventTime.SetEventTime(t time.Time), but this doesn't seem to fit the bill.

So this is going to be go routine, channel and a function.

keypresses := make(chan int, 10)
go gameDirector(keypresses)
handleKeyBoardEvents(keypresses)

Line 1: Create the channel to communicate key presses between processes.
Line 2: This controls the direction of the snake, and placement of the apple.
Line 3: intercepts keyboard presses and either pauses, or sets the direction of the snake

I have added a game director, and it doesn't work. `tcell` doesn't seem to have a time event I can listen to next to key presses and resizes, so I will need to split this up. There is this https://github.com/gdamore/tcell/blob/v2.6.0/event.go#L30 and `*EventTime.SetEventTime(t time.Time)`, but this doesn't seem to fit the bill. So this is going to be go routine, channel and a function. ``` keypresses := make(chan int, 10) go gameDirector(keypresses) handleKeyBoardEvents(keypresses) ``` Line 1: Create the channel to communicate key presses between processes. Line 2: This controls the direction of the snake, and placement of the apple. Line 3: intercepts keyboard presses and either pauses, or sets the direction of the snake
Author
Owner

This is working as intended. Now to add tank-controls.

This is working as intended. Now to add tank-controls.
sacha closed this issue 2023-11-12 12:57:42 +01:00
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: golang/snake#1
No description provided.