Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'Chingu'
- include Gosu
- include Chingu
- class Game < Window
- def initialize
- super 800, 600, false
- / Window /
- $name = "Fractional's Spaceshooter V. 0.01x"
- self.caption = $name
- self.input = {esc: :exit}
- / Variables /
- @counter = 0
- / Menu /
- @menu = Menu.new
- @menu.input = {:up => :up, :down => :down, :return => :enter}
- $font = Font.new(self, default_font_name, 30)
- / Player /
- @player = Player.new(:draw => false, :update => false)
- @player.input = {:holding_left => :move_left, :holding_right => :move_right}
- end
- def update
- if(@menu.state? == true)
- @counter += 1
- if(@counter == 120)
- Meteor.create(x: rand(800)+100, y: 400, velocity_y: rand(5))
- @counter = 0
- puts "Meteor created"
- end
- end
- end
- def draw
- if(@menu.state? == true)
- @menu.draw
- end
- end
- end
- class Player < GameObject
- def setup
- @image = Image["assets/player/player.png"]
- @y = 575
- end
- def move_left
- @x -= 5
- end
- def move_right
- @x += 5
- end
- end
- class Meteor < GameObject
- has_traits :velocity, :timer, :collision_detection, :bounding_circle
- def setup
- @y = -30
- @image = Image["assets/objects/meteor.png"]
- after(2000) {self.destroy}
- end
- end
- class Menu < GameObject
- def setup
- @menu = true
- @playermode = 0
- @counter = 1
- end
- def state?
- @menu
- end
- def playermode
- @playermode
- end
- def up
- if(@counter >= 1 && @counter <= 3)
- @counter -= 1
- end
- end
- def down
- if(@counter >= 0 && @counter <= 0)
- @counter += 1
- end
- end
- def enter
- puts @counter
- if(@counter == 0)
- @menu = false
- @playermode = 1
- end
- if(@counter == 1)
- @menu = false
- @playermode = 2
- end
- @menu = false
- end
- def draw
- if(@menu == true)
- $font.draw_rel($name, 400, 50, 0, 0.5, 1.0, factor_x = 1, factor_y = 1, 0xff00f47d)
- $font.draw_rel("SINGLEPLAYER", 400,150, 0, 0.5, 1.0, factor_x = 1, factor_y = 1, 0xff00f47d)
- $font.draw_rel("MULTIPLAYER", 400,200, 0, 0.5, 1.0, factor_x = 1, factor_y = 1, 0xff00f47d)
- $font.draw_rel("> <", 400, @counter*50+150, 0, 0.5, 1.0, factor_x = 1, factor_y = 1, 0xfff47d20)
- end
- end
- end
- Game.new.show
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement