root/lang/ruby/nario/nario/gamestart.rb @ 20291

Revision 20291, 1.9 kB (checked in by authorNari, 5 years ago)

もっとクリーンなnarioへ...もっとクリーンな日本へ

Line 
1#
2# super nario brother
3# (c)2008, nari
4# http://d.hatena.ne.jp/authorNari/
5#
6
7require 'sdl'
8require 'lib/fpstimer'
9require 'lib/input'
10require 'nario/scene'
11require 'nario/material'
12require 'nario/life'
13require 'nario/map'
14
15# key config(SDL <--> nario)
16class Input
17  define_key SDL::Key::ESCAPE, :exit
18  define_key SDL::Key::Q, :exit
19  define_key SDL::Key::LEFT, :left
20  define_key SDL::Key::RIGHT, :right
21  define_key SDL::Key::UP, :up
22  define_key SDL::Key::DOWN, :down
23  define_key SDL::Key::RETURN, :ok
24  define_key SDL::Key::A, :a
25  define_key SDL::Key::B, :b
26  define_key SDL::Key::S, :start
27  define_key SDL::Key::G, :go
28end
29
30# nario make map
31def creation_nario_world(screen)
32  world = {}
33  world[:title] = ::Scene::Title.new { success :map1_1 }
34  world[:title].build_scene &Map::TITLE
35  world[:map1_1] = ::Scene::FlowWorld.new { success :title; miss :title }
36  world[:map1_1].build_scene &Map::MAP1_1
37  world
38end
39
40def setup_sdl
41  SDL.init(SDL::INIT_JOYSTICK)
42  SDL::TTF.init
43  SDL.set_video_mode(Scene::SCREEN_WIDTH, Scene::SCREEN_HIGHT, 16, SDL::HWSURFACE|SDL::DOUBLEBUF)
44end
45
46def stop?(input, screen)
47  if input.start
48    screen.put(SDL::Surface.load("nario/image/stop.bmp"), 270, 270)
49    screen.update_rect(0, 0, Scene::SCREEN_WIDTH, Scene::SCREEN_HIGHT)
50    @stop = true
51  end
52  if input.go
53    @stop = false
54  end
55  return @stop
56end
57
58def go_nario!
59  screen = setup_sdl()
60  world = creation_nario_world(screen)
61
62  input = Input.new
63  timer = FPSTimerLight.new
64  timer.reset
65  scene = world[:title]
66
67  # main loop
68  loop {
69    input.poll
70    break if input[:exit]
71    redo if stop?(input, screen)
72
73    s_next = scene.act(input)
74    scene.render(screen)
75    scene = world[s_next].rebuild if s_next
76    timer.wait_frame {
77      gc_start if $GC_BURDEN_MODE
78      screen.update_rect(0, 0, Scene::SCREEN_WIDTH, Scene::SCREEN_HIGHT)
79    }
80  }
81end
82
83go_nario!
Note: See TracBrowser for help on using the browser.