chronus 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,3 @@
1
+ == Chronos
2
+
3
+ Put appropriate LICENSE for your project here.
data/README ADDED
@@ -0,0 +1,3 @@
1
+ == Chronos
2
+
3
+ You should document your project here.
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ #
2
+ # To change this template, choose Tools | Templates
3
+ # and open the template in the editor.
4
+
5
+
6
+ require 'rubygems'
7
+ require 'rake'
8
+ require 'rake/clean'
9
+ require 'rake/gempackagetask'
10
+ require 'rake/rdoctask'
11
+ require 'rake/testtask'
12
+
13
+ spec = Gem::Specification.new do |s|
14
+ s.name = 'chronus'
15
+ s.version = '0.0.1'
16
+ s.has_rdoc = true
17
+ s.extra_rdoc_files = ['README', 'LICENSE']
18
+ s.summary = 'Chronus is a MVC Game Framework.'
19
+ s.description = s.summary
20
+ s.author = 'Michel Brito'
21
+ s.email = 'micheljunio@gmail.com'
22
+ # s.executables = ['your_executable_here']
23
+ s.files = %w(LICENSE README Rakefile) + Dir.glob("{bin,lib,spec}/**/*")
24
+ s.require_path = "lib"
25
+ s.bindir = "bin"
26
+ end
27
+
28
+ Rake::GemPackageTask.new(spec) do |p|
29
+ p.gem_spec = spec
30
+ p.need_tar = true
31
+ p.need_zip = true
32
+ end
33
+
34
+ Rake::RDocTask.new do |rdoc|
35
+ files =['README', 'LICENSE', 'lib/**/*.rb']
36
+ rdoc.rdoc_files.add(files)
37
+ rdoc.main = "README" # page to start on
38
+ rdoc.title = "Chronos Docs"
39
+ rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
40
+ rdoc.options << '--line-numbers'
41
+ end
42
+
43
+ Rake::TestTask.new do |t|
44
+ t.test_files = FileList['test/**/*.rb']
45
+ end
data/lib/chronus.rb ADDED
@@ -0,0 +1,25 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ min_version = '1.3.0'
5
+ require 'sdl'
6
+ unless SDL::VERSION >= min_version
7
+ raise %(Chronus require SDL > #{min_version}. Please install SDL and try again.)
8
+ end
9
+
10
+ require 'yaml'
11
+
12
+ #TODO remover 'lib' from path
13
+ require 'chronus/timer'
14
+ require 'chronus/event'
15
+ require 'chronus/key'
16
+ require 'chronus/mouse'
17
+ require 'chronus/constantes'
18
+ require 'chronus/image'
19
+ require 'chronus/game_model'
20
+ require 'chronus/game_controller'
21
+ require 'chronus/game_view'
22
+ require 'chronus/game'
23
+
24
+ #inclui chronus
25
+ include Chronus
@@ -0,0 +1,163 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ module Chronus
5
+ VERSION = "0.7.0"
6
+
7
+ #Types
8
+ ACTIVE = Event::Active
9
+ KEYDOWN = Event::KeyDown
10
+ KEYUP = Event::KeyUp
11
+ MOUSEMOTION = Event::MouseMotion
12
+ MOUSEBUTTONDOWN = Event::MouseButtonDown
13
+ MOUSEBUTTONUP = Event::MouseButtonUp
14
+ JOYAXIS = Event::JoyAxis
15
+ JOYBALL = Event::JoyBall
16
+ JOYHAT = Event::JoyHat
17
+ JOYBUTTONDOWN = Event::JoyButtonDown
18
+ JOYBUTTONUP = Event::JoyButtonUp
19
+ QUIT = Event::Quit
20
+ SYSWM = Event::SysWM
21
+ VIDEORESIZE = Event::VideoResize
22
+ #VIDEOEXPOSE = Event::VideoExpose
23
+
24
+ #Keyboard
25
+ K_BACKSPACE = Key::BACKSPACE
26
+ K_TAB = Key::TAB
27
+ K_CLEAR = Key::CLEAR
28
+ K_RETURN = Key::RETURN
29
+ K_PAUSE = Key::PAUSE
30
+ K_ESCAPE = Key::ESCAPE
31
+ K_SPACE = Key::SPACE
32
+ K_EXCLAIM = Key::EXCLAIM
33
+ K_QUOTEDBL = Key::QUOTEDBL
34
+ K_HASH = Key::HASH
35
+ K_DOLLAR = Key::DOLLAR
36
+ K_AMPERSAND = Key::AMPERSAND
37
+ K_QUOTE = Key::QUOTE
38
+ K_LEFTPAREN = Key::LEFTPAREN
39
+ K_RIGHTPAREN = Key::RIGHTPAREN
40
+ K_ASTERISK = Key::ASTERISK
41
+ K_PLUS = Key::PLUS
42
+ K_COMMA = Key::COMMA
43
+ K_MINUS = Key::MINUS
44
+ K_PERIOD = Key::PERIOD
45
+ K_SLASH = Key::SLASH
46
+ K_0 = Key::K0
47
+ K_1 = Key::K1
48
+ K_2 = Key::K2
49
+ K_3 = Key::K3
50
+ K_4 = Key::K4
51
+ K_5 = Key::K5
52
+ K_6 = Key::K6
53
+ K_7 = Key::K7
54
+ K_8 = Key::K8
55
+ K_9 = Key::K9
56
+ K_COLON = Key::COLON
57
+ K_SEMICOLON = Key::SEMICOLON
58
+ K_LESS = Key::LESS
59
+ K_EQUALS = Key::EQUALS
60
+ K_GREATER = Key::GREATER
61
+ K_QUESTION = Key::QUESTION
62
+ K_AT = Key::AT
63
+ K_LEFTBRACKET = Key::LEFTBRACKET
64
+ K_BACKSLASH = Key::BACKSLASH
65
+ K_RIGHTBRACKET = Key::RIGHTBRACKET
66
+ K_CARET = Key::CARET
67
+ K_UNDERSCORE = Key::UNDERSCORE
68
+ K_BACKQUOTE = Key::BACKQUOTE
69
+ K_A = Key::A
70
+ K_B = Key::B
71
+ K_C = Key::C
72
+ K_D = Key::D
73
+ K_E = Key::E
74
+ K_F = Key::F
75
+ K_G = Key::G
76
+ K_H = Key::H
77
+ K_I = Key::I
78
+ K_J = Key::J
79
+ K_K = Key::K
80
+ K_L = Key::L
81
+ K_M = Key::M
82
+ K_N = Key::N
83
+ K_O = Key::O
84
+ K_P = Key::P
85
+ K_Q = Key::Q
86
+ K_R = Key::R
87
+ K_S = Key::S
88
+ K_T = Key::T
89
+ K_U = Key::U
90
+ K_V = Key::V
91
+ K_W = Key::W
92
+ K_X = Key::X
93
+ K_Y = Key::Y
94
+ K_Z = Key::Z
95
+ K_DELETE = Key::DELETE
96
+ K_KP0 = Key::KP0
97
+ K_KP1 = Key::KP1
98
+ K_KP2 = Key::KP2
99
+ K_KP3 = Key::KP3
100
+ K_KP4 = Key::KP4
101
+ K_KP5 = Key::KP5
102
+ K_KP6 = Key::KP6
103
+ K_KP7 = Key::KP7
104
+ K_KP8 = Key::KP8
105
+ K_KP9 = Key::KP9
106
+ K_KP_PERIOD = Key::KP_PERIOD
107
+ K_KP_DIVIDE = Key::KP_DIVIDE
108
+ K_KP_MULTIPLY = Key::KP_MULTIPLY
109
+ K_KP_MINUS = Key::KP_MINUS
110
+ K_KP_PLUS = Key::KP_PLUS
111
+ K_KP_ENTER = Key::KP_ENTER
112
+ K_KP_EQUALS = Key::KP_EQUALS
113
+ K_UP = Key::UP
114
+ K_DOWN = Key::DOWN
115
+ K_RIGHT = Key::RIGHT
116
+ K_LEFT = Key::LEFT
117
+ K_INSERT = Key::INSERT
118
+ K_HOME = Key::HOME
119
+ K_END = Key::END
120
+ K_PAGEUP = Key::PAGEUP
121
+ K_PAGEDOWN = Key::PAGEDOWN
122
+ K_F1 = Key::F1
123
+ K_F2 = Key::F2
124
+ K_F3 = Key::F3
125
+ K_F4 = Key::F4
126
+ K_F5 = Key::F5
127
+ K_F6 = Key::F6
128
+ K_F7 = Key::F7
129
+ K_F8 = Key::F8
130
+ K_F9 = Key::F9
131
+ K_F10 = Key::F10
132
+ K_F11 = Key::F11
133
+ K_F12 = Key::F12
134
+ K_F13 = Key::F13
135
+ K_F14 = Key::F14
136
+ K_F15 = Key::F15
137
+ K_NUMLOCK = Key::NUMLOCK
138
+ K_CAPSLOCK = Key::CAPSLOCK
139
+ K_SCROLLOCK = Key::SCROLLOCK
140
+ K_RSHIFT = Key::RSHIFT
141
+ K_LSHIFT = Key::LSHIFT
142
+ K_RCTRL = Key::RCTRL
143
+ K_LCTRL = Key::LCTRL
144
+ K_RALT = Key::RALT
145
+ K_LALT = Key::LALT
146
+ K_RMETA = Key::RMETA
147
+ K_LMETA = Key::LMETA
148
+ K_LSUPER = Key::LSUPER
149
+ K_RSUPER = Key::RSUPER
150
+ K_MODE = Key::MODE
151
+ K_HELP = Key::HELP
152
+ K_PRINT = Key::PRINT
153
+ K_SYSREQ = Key::SYSREQ
154
+ K_BREAK = Key::BREAK
155
+ K_MENU = Key::MENU
156
+ K_POWER = Key::POWER
157
+ K_EURO = Key::EURO
158
+
159
+ #Mouse
160
+ MOUSE_LEFT = Mouse::BUTTON_LEFT
161
+ MOUSE_MIDDLE = Mouse::BUTTON_MIDDLE
162
+ MOUSE_RIGHT = Mouse::BUTTON_RIGHT
163
+ end
@@ -0,0 +1,12 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ module Chronus
5
+ class Event < SDL::Event2
6
+ def self.get
7
+ poll
8
+ end
9
+ end
10
+
11
+ SDL::Event2.class_eval{alias :type :class}
12
+ end
@@ -0,0 +1,64 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ module Chronus
5
+ class Game
6
+ def self.run
7
+ load
8
+ config = load_config
9
+ SDL.putenv("SDL_VIDEO_CENTERED=1") #center window
10
+ SDL.init(SDL::INIT_EVERYTHING) #TODO Load from file app.yml
11
+ mode = enabled?(config['fullscreen']) ? SDL::FULLSCREEN|SDL::HWSURFACE : SDL::HWSURFACE
12
+ $screen = SDL::setVideoMode config['width'], config['height'], config['fps'], mode
13
+ Mouse.hide unless enabled?(config['mouse'])
14
+ self.title = config['name'] unless config['name'].nil?
15
+ self.icon = 'chronus.png'
16
+ timer = Timer.new
17
+ set_controller ApplicationController.new
18
+ loop do
19
+ timer.start
20
+ while event = Event::get
21
+ $controller.input
22
+ stop if event.type == QUIT
23
+ end
24
+ $controller.update
25
+ $screen.flip
26
+ SDL.delay( (1000 / config['fps']) - timer.ticks ) if timer.ticks < 1000 / config['fps']
27
+ end
28
+ end
29
+
30
+ def self.title=(title)
31
+ SDL::WM.set_caption title, ''
32
+ end
33
+
34
+ #Sets the window icon
35
+ def self.icon=(filename)
36
+ SDL::WM.icon = SDL::Surface.load(File.join(CHRONUS_ROOT, 'resources', 'images', filename))
37
+ end
38
+
39
+ def self.load
40
+ Dir["#{CHRONUS_ROOT}/app/models/*.rb","#{CHRONUS_ROOT}/app/controllers/*.rb","#{CHRONUS_ROOT}/app/views/*.rb"].each{|file| require file}
41
+ end
42
+
43
+ def self.load_config
44
+ file_path = File.join(CHRONUS_ROOT,'config','app.yml')
45
+ YAML::load(File.open(file_path))
46
+ end
47
+
48
+ def self.enabled?(param)
49
+ param == 'enabled'
50
+ end
51
+
52
+ def self.set_controller(controller)
53
+ if controller.is_a? GameController
54
+ $controller = controller
55
+ else
56
+ raise %(#{controller.class} isn't a GameController)
57
+ end
58
+ end
59
+
60
+ def self.stop
61
+ exit
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,10 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ module Chronus
5
+ class GameBackground < GameObject
6
+ def initialize
7
+
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ module Chronus
5
+ class GameController
6
+ def initialize
7
+
8
+ end
9
+
10
+ def input
11
+
12
+ end
13
+
14
+ def update
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,10 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ module Chronus
5
+ class GameModel
6
+ def initialize
7
+
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,51 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ module Chronus
5
+ class GameObject < GameModel
6
+ attr_accessor :x, :y, :z, :width, :height, :visible
7
+ def initialize
8
+ @x = 0
9
+ @y = 0
10
+ @width = 0
11
+ @height = 0
12
+ @z = 0
13
+ @visible = true
14
+ @last_update = 0
15
+ end
16
+
17
+ def show
18
+ @visible = true
19
+ end
20
+
21
+ def hide
22
+ @visible = false
23
+ end
24
+
25
+ #Returns the top position
26
+ def top
27
+ @y
28
+ end
29
+
30
+ #Returns the right position
31
+ def right
32
+ @x + @width
33
+ end
34
+
35
+ #Returns the bottom position
36
+ def bottom
37
+ @y + @height
38
+ end
39
+
40
+ #Returns the left position
41
+ def left
42
+ @x
43
+ end
44
+
45
+ #Sets X and Y position
46
+ def pos(x, y)
47
+ @x = x
48
+ @y = y
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,10 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ module Chronus
5
+ class GameRecord < GameModel
6
+ def initialize
7
+
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ module Chronus
5
+ class GameSprite < GameObject
6
+ def initialize
7
+
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ module Chronus
5
+ class GameView
6
+ def initialize(width, height, fill= 0x00)
7
+
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,32 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ module Chronus
5
+ class Image
6
+ def self.create(filename, transparent=false)
7
+ img = load(filename)
8
+ color_key = img.get_pixel(0,0)
9
+ img.set_color_key(SDL::SRCCOLORKEY ,color_key) if transparent == true
10
+ img.display_format
11
+ end
12
+
13
+ def self.to_tiles(filename, width, height, transparent = false, margin = 0)
14
+ img = create(filename, false)
15
+ color_key = img.get_pixel(0,0)
16
+ t_width = (img.w-margin) / (width + margin)
17
+ t_height = (img.h-margin) / (height + margin)
18
+ tiles = []
19
+ i = 0
20
+ while i < t_height do
21
+ j = 0;
22
+ while j < t_width do
23
+ tiles << img.copy_rect(j*(width+margin)+margin, i*(height+margin)+margin, width, height)
24
+ tiles[tiles.length - 1].set_color_key(SDL::SRCCOLORKEY, color_key) if transparent == true
25
+ j += 1
26
+ end
27
+ i += 1
28
+ end
29
+ tiles
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,30 @@
1
+ module Chronus
2
+
3
+ class Key
4
+ include SDL::Key
5
+ def self.scan
6
+ SDL::Key.scan
7
+ end
8
+
9
+ def self.press?(key)
10
+ SDL::Key.press?(key)
11
+ end
12
+
13
+ def self.mod_state
14
+ SDL::Key.mod_state
15
+ end
16
+
17
+ def self.name(key)
18
+ SDL::Key.get_key_name(key)
19
+ end
20
+
21
+ def self.enable_key_repeat(delay,interval)
22
+ SDL::Key.enable_key_repeat(delay,interval)
23
+ end
24
+
25
+ def self.disable_key_repeat
26
+ SDL::Key.disable_key_repeat
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,40 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ module Chronus
5
+ class Mouse
6
+ include SDL::Mouse
7
+
8
+ def self.state
9
+ SDL::Mouse.state
10
+ end
11
+
12
+ def self.show
13
+ SDL::Mouse.show
14
+ end
15
+
16
+ def self.hide
17
+ SDL::Mouse.hide
18
+ end
19
+
20
+ def self.show?
21
+ SDL::Mouse.show?
22
+ end
23
+
24
+ def self.pos(x,y)
25
+ SDL::Mouse.warp(x,y)
26
+ end
27
+
28
+ def self.button_pressed?(button)
29
+ case button
30
+ when BUTTON_LEFT
31
+ return state[2]
32
+ when BUTTON_MIDDLE
33
+ return state[3]
34
+ when BUTTON_RIGHT
35
+ return state[4]
36
+ end
37
+ false
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,66 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ module Chronus
5
+ class Timer
6
+ def initialize
7
+ @start_ticks = 0
8
+ @paused_ticks = 0
9
+ @paused = false
10
+ @started = false
11
+ end
12
+
13
+ #Start counter timer
14
+ def start
15
+ @started = true
16
+ @paused = false
17
+ @start_ticks = SDL.get_ticks
18
+ end
19
+
20
+ #Stop counter timer
21
+ def stop
22
+ @started = false
23
+ @paused = false
24
+ end
25
+
26
+ #Pause counter timer
27
+ def pause
28
+ if @started == true && @paused == false
29
+ @paused = true
30
+ @paused_ticks = SDL.get_ticks - @start_ticks
31
+ end
32
+ end
33
+
34
+ #Resume counter timer
35
+ def resume
36
+ if @paused == true
37
+ @paused = false
38
+ @start_ticks = SDL.get_ticks - @paused_ticks
39
+ @paused_ticks = 0
40
+ end
41
+ end
42
+
43
+ #Return current tick
44
+ def ticks
45
+ t = 0
46
+ if @started == true
47
+ if @paused == true
48
+ t = @paused_ticks
49
+ else
50
+ t = SDL.get_ticks - @start_ticks
51
+ end
52
+ end
53
+ t
54
+ end
55
+
56
+ #Return true if started == true
57
+ def started?
58
+ @started
59
+ end
60
+
61
+ #Return true if paused == true
62
+ def paused?
63
+ @paused
64
+ end
65
+ end
66
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chronus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michel Brito
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-06 00:00:00 -03:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Chronus is a MVC Game Framework.
17
+ email: micheljunio@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ - LICENSE
25
+ files:
26
+ - LICENSE
27
+ - README
28
+ - Rakefile
29
+ - lib/chronus.rb
30
+ - lib/chronus/event.rb
31
+ - lib/chronus/game_controller.rb
32
+ - lib/chronus/image.rb
33
+ - lib/chronus/game_view.rb
34
+ - lib/chronus/game_sprite.rb
35
+ - lib/chronus/mouse.rb
36
+ - lib/chronus/key.rb
37
+ - lib/chronus/game_model.rb
38
+ - lib/chronus/game_record.rb
39
+ - lib/chronus/constantes.rb
40
+ - lib/chronus/game.rb
41
+ - lib/chronus/game_object.rb
42
+ - lib/chronus/game_background.rb
43
+ - lib/chronus/timer.rb
44
+ has_rdoc: true
45
+ homepage:
46
+ licenses: []
47
+
48
+ post_install_message:
49
+ rdoc_options: []
50
+
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ requirements: []
66
+
67
+ rubyforge_project:
68
+ rubygems_version: 1.3.5
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Chronus is a MVC Game Framework.
72
+ test_files: []
73
+