File: mm.rb

package info (click to toggle)
magicmaze 1.4.3.6%2Bdfsg-3
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 772 kB
  • sloc: ruby: 3,432; makefile: 12
file content (111 lines) | stat: -rwxr-xr-x 3,614 bytes parent folder | download | duplicates (3)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
#!/usr/bin/env ruby

############################################################
# This game is FREE as in both BEER and SPEECH. It is available and can 
# be distributed under the terms of the GPL license (version 2) or 
# alternatively the dual-licensing terms of Ruby itself.
# Please see README.txt and COPYING_GPL.txt for details.
#
#  Magic Maze - a simple and low-tech monster-bashing maze game.
#  Copyright (C) 2004-2008 Kent Dahl
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
############################################################

require 'getoptlong'

options = GetoptLong.new(["--help",     "-h", GetoptLong::NO_ARGUMENT ], 
                         ["--nosound",  "-S", GetoptLong::NO_ARGUMENT ],
                         ["--debug",    "-d", GetoptLong::NO_ARGUMENT ],
                         ["--fullscreen",    "-f", GetoptLong::NO_ARGUMENT ],
                         ["--scale",    "-s", GetoptLong::REQUIRED_ARGUMENT ],
                         ["--level",    "-l", GetoptLong::REQUIRED_ARGUMENT ],
                         ["--loadgame", "-L", GetoptLong::NO_ARGUMENT ],
                         ["--volume",   "-v", GetoptLong::REQUIRED_ARGUMENT ],
                         ["--joystick", "-j", GetoptLong::OPTIONAL_ARGUMENT ],
                         ["--savedir",  "-D", GetoptLong::REQUIRED_ARGUMENT ]

 )


def show_usage
  puts <<-USAGE
Magic Maze, a Ruby/SDL game. 

  usage: ruby mm.rb [--help] [--nosound] [--level #] [--joystick [#]]

    -h --help         Show this message
    -j --joystick     Enable joystick support 
    -l --level 	      Assign a start level (1-10)
    -L --loadgame     Load savegame automatically
    -D --savedir      Specify savegame directory
    -S --nosound      Disables sound
    -v --volume       Set volume (1-10)
    -f --fullscreen   Start in fullscreen mode
    -s --scale        Scale the graphics and resolution up (1-5)
    
    USAGE
end



opt_hash = {
  :sound => true,
}

options.each do |option, argument|  
  case option
  when "--help"
    show_usage
    exit
  when "--nosound"
    opt_hash[ :sound ] = false
  when "--volume"
    opt_hash[ :volume ] = (argument || 5).to_i
  when "--level"
    opt_hash[ :start_level ] = Integer(argument)
  when "--loadgame"
    opt_hash[:loadgame] = true
  when "--joystick"
    opt_hash[ :joystick ] = (argument || 0).to_i
  when "--debug"
    opt_hash[:debug] = true
  when "--fullscreen"
    opt_hash[:fullscreen] = true
  when "--savedir"
    opt_hash[:savedir] = argument
  when "--scale"
    scale = (argument || 1).to_i
    unless ((1..5).include? scale) then 
      raise ArgumentError.new("Invalid scale.") 
    end
    opt_hash[:scale] = scale    
    OVERRIDE_GRAPHICS_SCALE_FACTOR = scale 
    module MagicMaze
      class Graphics
        OVERRIDE_GRAPHICS_SCALE_FACTOR = OVERRIDE_GRAPHICS_SCALE_FACTOR
      end
    end

  end
end			 



require 'magicmaze/magicmaze'

MagicMaze::Game.new( opt_hash ).loop