Advertisement
Guest User

Untitled

a guest
Aug 9th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. require 'Chingu'
  2. include Gosu
  3. include Chingu
  4.  
  5. class Game < Window
  6. def initialize
  7. super 800, 600, false
  8. / Window /
  9. $name = "Fractional's Spaceshooter V. 0.01x"
  10. self.caption = $name
  11. self.input = {esc: :exit}
  12. / Variables /
  13. @counter = 0
  14.  
  15. / Menu /
  16. @menu = Menu.new
  17. @menu.input = {:up => :up, :down => :down, :return => :enter}
  18. $font = Font.new(self, default_font_name, 30)
  19. / Player /
  20. @player = Player.new(:draw => false, :update => false)
  21. @player.input = {:holding_left => :move_left, :holding_right => :move_right}
  22. end
  23.  
  24. def update
  25. if(@menu.state? == true)
  26. @counter += 1
  27. if(@counter == 120)
  28. Meteor.create(x: rand(800)+100, y: 400, velocity_y: rand(5))
  29. @counter = 0
  30. puts "Meteor created"
  31. end
  32. end
  33. end
  34.  
  35. def draw
  36. if(@menu.state? == true)
  37. @menu.draw
  38. end
  39. end
  40. end
  41.  
  42. class Player < GameObject
  43. def setup
  44. @image = Image["assets/player/player.png"]
  45. @y = 575
  46. end
  47.  
  48. def move_left
  49. @x -= 5
  50. end
  51. def move_right
  52. @x += 5
  53. end
  54. end
  55.  
  56. class Meteor < GameObject
  57. has_traits :velocity, :timer, :collision_detection, :bounding_circle
  58. def setup
  59. @y = -30
  60. @image = Image["assets/objects/meteor.png"]
  61. after(2000) {self.destroy}
  62. end
  63. end
  64.  
  65. class Menu < GameObject
  66. def setup
  67. @menu = true
  68. @playermode = 0
  69. @counter = 1
  70. end
  71.  
  72. def state?
  73. @menu
  74. end
  75.  
  76. def playermode
  77. @playermode
  78. end
  79.  
  80. def up
  81. if(@counter >= 1 && @counter <= 3)
  82. @counter -= 1
  83. end
  84. end
  85. def down
  86. if(@counter >= 0 && @counter <= 0)
  87. @counter += 1
  88. end
  89. end
  90.  
  91. def enter
  92. puts @counter
  93. if(@counter == 0)
  94. @menu = false
  95. @playermode = 1
  96. end
  97. if(@counter == 1)
  98. @menu = false
  99. @playermode = 2
  100. end
  101. @menu = false
  102. end
  103.  
  104. def draw
  105. if(@menu == true)
  106. $font.draw_rel($name, 400, 50, 0, 0.5, 1.0, factor_x = 1, factor_y = 1, 0xff00f47d)
  107. $font.draw_rel("SINGLEPLAYER", 400,150, 0, 0.5, 1.0, factor_x = 1, factor_y = 1, 0xff00f47d)
  108. $font.draw_rel("MULTIPLAYER", 400,200, 0, 0.5, 1.0, factor_x = 1, factor_y = 1, 0xff00f47d)
  109. $font.draw_rel("> <", 400, @counter*50+150, 0, 0.5, 1.0, factor_x = 1, factor_y = 1, 0xfff47d20)
  110. end
  111. end
  112. end
  113.  
  114. Game.new.show
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement