forked from bubby2002/Kirby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 430788a
Showing
6 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class Ball | ||
def initialize(game_window) | ||
@game_window = game_window | ||
@icon = Gosu::Image.new(@game_window, "images/ball.png", true) | ||
reset! | ||
end | ||
|
||
def update | ||
if @y > @game_window.height | ||
reset! | ||
else | ||
@y = @y +20 | ||
# @x = @x + 5 | ||
# hey Tom... if you uncomment the above line...diagonal balls | ||
end | ||
end | ||
|
||
def draw | ||
@icon.draw(@x,@y, 2) | ||
end | ||
|
||
def x | ||
@x | ||
end | ||
|
||
def y | ||
@y | ||
end | ||
|
||
def reset! | ||
@y = 0 | ||
@x = rand(@game_window.width) | ||
end | ||
end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# $: << File.expand_path(File.dirname(__FILE__)) | ||
|
||
require 'rubygems' | ||
require 'gosu' | ||
require 'player' | ||
require 'ball' | ||
|
||
class MyGame < Gosu::Window | ||
def initialize | ||
super(1200, 1000, false) | ||
@player1 = Player.new(self) | ||
@balls = 6.times.map {Ball.new(self)} | ||
@running = true | ||
@pause = false | ||
end | ||
|
||
def button_down(id) | ||
if id == Gosu::Button::KbP | ||
if @pause == false | ||
@pause = true | ||
else | ||
@pause = false | ||
end | ||
end | ||
end | ||
|
||
def update | ||
if @pause == false | ||
|
||
if @running | ||
if button_down? Gosu::Button::KbLeft | ||
@player1.move_left | ||
end | ||
|
||
if button_down? Gosu::Button::KbRight | ||
@player1.move_right | ||
end | ||
|
||
if button_down? Gosu::Button::KbUp | ||
@player1.move_up | ||
end | ||
|
||
if button_down? Gosu::Button::KbDown | ||
@player1.move_down | ||
end | ||
|
||
@balls.each {|ball| ball.update} | ||
|
||
if @player1.hit_by? @balls | ||
stop_game! | ||
end | ||
|
||
else | ||
#the game is currently stopped | ||
if button_down? Gosu::Button::KbEscape | ||
restart_game | ||
end | ||
end | ||
end | ||
end | ||
|
||
|
||
def draw | ||
@player1.draw | ||
@balls.each {|ball| ball.draw} | ||
end | ||
|
||
def stop_game! | ||
@running = false | ||
end | ||
|
||
def restart_game | ||
@running = true | ||
@balls.each {|ball| ball.reset!} | ||
end | ||
|
||
end | ||
game = MyGame.new | ||
game.show | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
class Player | ||
|
||
def initialize(game_window) | ||
@game_window = game_window | ||
@icon = Gosu::Image.new(@game_window, "images/kirby.png", true) | ||
@x = 50 | ||
@y = 800 | ||
@z = 90 | ||
end | ||
|
||
def draw | ||
@icon.draw(@x,@y, 1) | ||
end | ||
|
||
def move_left | ||
if @x < 0 | ||
@x = 0 | ||
else | ||
@x = @x - 10 | ||
end | ||
end | ||
|
||
def move_right | ||
if @x > (@game_window.width - @z) | ||
@x = @game_window.width - @z | ||
else | ||
@x = @x + 10 | ||
end | ||
end | ||
|
||
def move_up | ||
if @y < 0 | ||
@y = 0 | ||
else | ||
@y = @y - 10 | ||
end | ||
end | ||
|
||
def move_down | ||
if @y > (@game_window.height - @z) | ||
@y = @game_window.height - @z | ||
else | ||
@y = @y + 10 | ||
end | ||
end | ||
|
||
def hit_by?(balls) | ||
balls.any? {|ball| Gosu::distance(@x, @y, ball.x, ball.y) < 50} | ||
end | ||
|
||
|
||
end |