Class: GamesParadise::Snake
- Inherits:
-
Object
- Object
- GamesParadise::Snake
- Defined in:
- lib/games_paradise/gui/gosu/final_fantasy/snake.rb
Instance Attribute Summary collapse
-
#player_dead ⇒ Object
readonly
Returns the value of attribute player_dead.
Instance Method Summary collapse
-
#chase_checker(player_x, player_y) ⇒ Object
chase_checker.
-
#collision_checker ⇒ Object
collision_checker.
-
#draw ⇒ Object
draw.
-
#initialize(colliders_name) ⇒ Snake
constructor
# === initialize ========================================================================= #.
-
#kill_checker(player_x, player_y, eaten_shroom) ⇒ Object
kill_checker.
-
#move(player_x, player_y, eaten_shroom) ⇒ Object
# === move ========================================================================= #.
-
#reset ⇒ Object
# === reset ========================================================================= #.
-
#warp(x, y) ⇒ Object
# === wrap ========================================================================= #.
Constructor Details
#initialize(colliders_name) ⇒ Snake
#
initialize
#
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/games_paradise/gui/gosu/final_fantasy/snake.rb', line 14 def initialize(colliders_name) @blue_right_anim = Gosu::Image.load_tiles("images/snake_moves_blue_right.png", 32, 32) @blue_left_anim = Gosu::Image.load_tiles("images/snake_moves_blue_left.png", 32, 32) @red_right_anim = Gosu::Image.load_tiles("images/snake_moves_red_right.png", 32, 32) @red_left_anim = Gosu::Image.load_tiles("images/snake_moves_red_left.png", 32, 32) @colliders_name = colliders_name @snake_colliders = Colliders.new("#{@colliders_name}", @buffer, @centre_and_top_gap, @centre_and_bottom_gap, @centre_and_left_gap, @centre_and_right_gap) @line_ranges = @snake_colliders.calculate_lines reset end |
Instance Attribute Details
#player_dead ⇒ Object (readonly)
Returns the value of attribute player_dead.
9 10 11 |
# File 'lib/games_paradise/gui/gosu/final_fantasy/snake.rb', line 9 def player_dead @player_dead end |
Instance Method Details
#chase_checker(player_x, player_y) ⇒ Object
chase_checker
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/games_paradise/gui/gosu/final_fantasy/snake.rb', line 146 def chase_checker(player_x, player_y) @chase_x_range = false @chase_y_range = false @player_x = player_x @player_y = player_y @line_ranges.each do |line| x_min = line[:x_range][0] x_max = line[:x_range][1] y_min = line[:y_range][0] y_max = line[:y_range][1] @chase_x_range = true if @player_x > x_min && @player_x < x_max @chase_y_range = true if @player_y > y_min && @player_y < y_max end @chase_x_range && @chase_y_range ? @chase = true : @chase = false end |
#collision_checker ⇒ Object
collision_checker
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/games_paradise/gui/gosu/final_fantasy/snake.rb', line 126 def collision_checker @snake_colliders.top_collision_check(@x, @y, @speed) @snake_colliders.bottom_collision_check(@x, @y, @speed) @snake_colliders.right_collision_check(@x, @y, @speed) @snake_colliders.left_collision_check(@x, @y, @speed) if @snake_colliders.top_collision @moving_up = false end if @snake_colliders.bottom_collision @moving_up = true end if @snake_colliders.right_collision @moving_right = false end if @snake_colliders.left_collision @moving_right = true end end |
#draw ⇒ Object
draw
177 178 179 |
# File 'lib/games_paradise/gui/gosu/final_fantasy/snake.rb', line 177 def draw @image.draw(@x - @width/2, @y - @height/2, 11) end |
#kill_checker(player_x, player_y, eaten_shroom) ⇒ Object
kill_checker
163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/games_paradise/gui/gosu/final_fantasy/snake.rb', line 163 def kill_checker(player_x, player_y, eaten_shroom) @player_x = player_x @player_y = player_y @eaten_shroom = eaten_shroom if @colliders_name == "snake_red" && Gosu.distance(@x, @y, @player_x, @player_y) < 4 && @eaten_shroom == false @player_dead = true elsif @colliders_name == "snake_blue" && Gosu.distance(@x, @y, @player_x, @player_y) < 4 && @eaten_shroom == false @player_dead = true #else #@player_dead = false end end |
#move(player_x, player_y, eaten_shroom) ⇒ Object
#
move
#
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/games_paradise/gui/gosu/final_fantasy/snake.rb', line 55 def move(player_x, player_y, eaten_shroom) @player_x = player_x @player_y = player_y @eaten_shroom = eaten_shroom kill_checker(@player_x, @player_y, @eaten_shroom) chase_checker(@player_x, @player_y) collision_checker if @move_counter == 1 @move_counter = 0 if @chase == false if @moving_right && @moving_up @x += @speed @y -= @speed if @colliders_name == "snake_blue" @image = @blue_right_anim[Gosu.milliseconds / 200 % @blue_right_anim.size] else @image = @red_right_anim[Gosu.milliseconds / 200 % @red_right_anim.size] end elsif @moving_right && @moving_up == false @x += @speed @y += @speed if @colliders_name == "snake_blue" @image = @blue_right_anim[Gosu.milliseconds / 200 % @blue_right_anim.size] else @image = @red_right_anim[Gosu.milliseconds / 200 % @red_right_anim.size] end elsif @moving_right == false && @moving_up @x -= @speed @y -= @speed if @colliders_name == "snake_blue" @image = @blue_left_anim[Gosu.milliseconds / 200 % @blue_left_anim.size] else @image = @red_left_anim[Gosu.milliseconds / 200 % @red_left_anim.size] end else @x -= @speed @y += @speed if @colliders_name == "snake_blue" @image = @blue_left_anim[Gosu.milliseconds / 200 % @blue_left_anim.size] else @image = @red_left_anim[Gosu.milliseconds / 200 % @red_left_anim.size] end end else if @x > @player_x @x -= @speed*2 unless @snake_colliders.left_collision if @colliders_name == "snake_blue" @image = @blue_left_anim[Gosu.milliseconds / 200 % @blue_left_anim.size] else @image = @red_left_anim[Gosu.milliseconds / 200 % @red_left_anim.size] end elsif @x < @player_x @x += @speed*2 unless @snake_colliders.right_collision if @colliders_name == "snake_blue" @image = @blue_right_anim[Gosu.milliseconds / 200 % @blue_right_anim.size] else @image = @red_right_anim[Gosu.milliseconds / 200 % @red_right_anim.size] end end if @y > @player_y @y -= @speed*2 unless @snake_colliders.top_collision elsif @y < @player_y @y += @speed*2 unless @snake_colliders.bottom_collision end end else @move_counter += 1 end end |
#reset ⇒ Object
#
reset
#
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/games_paradise/gui/gosu/final_fantasy/snake.rb', line 28 def reset @height = 32 @width = 32 @speed = 1 @centre_and_top_gap = 0 @centre_and_bottom_gap = 8 @centre_and_left_gap = 6 @centre_and_right_gap = 6 @buffer = 4 @moving_right = true @moving_up = true @move_counter = 1 @frame_speed = 1 @chase = false end |
#warp(x, y) ⇒ Object
#
wrap
#
47 48 49 50 |
# File 'lib/games_paradise/gui/gosu/final_fantasy/snake.rb', line 47 def warp(x,y) @x = x + (@width/2) @y = y + (@height/2) end |