-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.rb
36 lines (36 loc) · 771 Bytes
/
App.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require 'ruby2d'
require_relative 'Snake.rb'
require_relative 'Apple.rb'
require_relative 'Board.rb'
require_relative 'consts.rb'
set color: 'navy'
set fps_cap: 18
snake = Snake.new
apple = Apple.new
board = Board.new
tick = true
on :key_down do |event|
# A key was pressed
if DIRECTIONS.include? event.key and (event.key != DIRECTIONS[(DIRECTIONS.find_index(snake.looks) + 2) % 4] or snake.body.length == 1) and !tick
snake.looks = event.key
tick = true
end
end
update do
tick = false
clear
snake.move
if apple == snake
apple = Apple.new
snake.grow = true
board.point
end
if snake.check_death?
snake.dead = true
else
apple.draw
end
snake.draw
board.draw
end
show