xibe 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/LICENSE +3 -0
  2. data/README +3 -0
  3. data/Rakefile +48 -0
  4. data/lib/xibe.rb +699 -0
  5. metadata +57 -0
data/LICENSE ADDED
@@ -0,0 +1,3 @@
1
+ == Xibe
2
+
3
+ Put appropriate LICENSE for your project here.
data/README ADDED
@@ -0,0 +1,3 @@
1
+ == Xibe
2
+
3
+ You should document your project here.
data/Rakefile ADDED
@@ -0,0 +1,48 @@
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 = 'xibe'
15
+ s.version = '0.0.1'
16
+ s.has_rdoc = true
17
+ s.extra_rdoc_files = ['README', 'LICENSE']
18
+ s.summary = 'Developer Game'
19
+ s.description = s.summary
20
+ s.author = 'Michel Brito'
21
+ s.email = 'micheljunio@gmail.com'
22
+ s.homepage = "http://codesheep.com/xibe/"
23
+ s.rubyforge_project = 'xibe'
24
+ # s.executables = ['your_executable_here']
25
+ s.files = %w(LICENSE README Rakefile) + Dir.glob("{bin,lib,spec}/**/*")
26
+ s.require_path = "lib"
27
+ s.bindir = "bin"
28
+ #s.add_dependency("rubysdl", ">= 1.3.0")
29
+ end
30
+
31
+ Rake::GemPackageTask.new(spec) do |p|
32
+ p.gem_spec = spec
33
+ p.need_tar = true
34
+ p.need_zip = true
35
+ end
36
+
37
+ Rake::RDocTask.new do |rdoc|
38
+ files =['README', 'LICENSE', 'lib/**/*.rb']
39
+ rdoc.rdoc_files.add(files)
40
+ rdoc.main = "README" # page to start on
41
+ rdoc.title = "Xibe Docs"
42
+ rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
43
+ rdoc.options << '--line-numbers'
44
+ end
45
+
46
+ Rake::TestTask.new do |t|
47
+ t.test_files = FileList['test/**/*.rb']
48
+ end
data/lib/xibe.rb ADDED
@@ -0,0 +1,699 @@
1
+ require 'rubygems'
2
+ require 'sdl'
3
+
4
+ class Fixnum
5
+ def seconds
6
+ self * 1000
7
+ end
8
+ end
9
+
10
+ class Float
11
+ def seconds
12
+ self * 1000
13
+ end
14
+ end
15
+
16
+ module Xibe
17
+ module Event
18
+ class Keyboard
19
+ def self.down?
20
+ if $keydown.nil? == false && $keydown == sym(self.name)
21
+ $keydown = nil
22
+ return true
23
+ end
24
+ end
25
+
26
+ def self.up?
27
+ if $keyup.nil? == false && $keyup == sym(self.name)
28
+ $keyup = nil
29
+ return true
30
+ end
31
+ end
32
+
33
+ def self.press?
34
+ k = sym(self.name)
35
+ SDL::Key.press?(k)
36
+ end
37
+
38
+ def self.sym(key)
39
+ k = key.gsub("Xibe::Event::K_", "")
40
+ eval "SDL::Key::" + k
41
+ end
42
+ end
43
+
44
+ def keydown?
45
+ if $any_keydown
46
+ $any_keydown = false
47
+ return true
48
+ end
49
+ end
50
+
51
+ def keyup?
52
+ unless $any_keyup.nil?
53
+ $any_keyup = nil
54
+ return true
55
+ end
56
+ end
57
+
58
+ class K_BACKSPACE < Keyboard; end
59
+ class K_TAB < Keyboard; end
60
+ class K_CLEAR < Keyboard; end
61
+ class K_RETURN < Keyboard; end
62
+ class K_PAUSE < Keyboard; end
63
+ class K_ESCAPE < Keyboard; end
64
+ class K_SPACE < Keyboard; end
65
+ class K_EXCLAIM < Keyboard; end
66
+ class K_QUOTEDBL < Keyboard; end
67
+ class K_HASH < Keyboard; end
68
+ class K_DOLLAR < Keyboard; end
69
+ class K_AMPERSAND < Keyboard; end
70
+ class K_QUOTE < Keyboard; end
71
+ class K_LEFTPAREN < Keyboard; end
72
+ class K_RIGHTPAREN < Keyboard; end
73
+ class K_ASTERISK < Keyboard; end
74
+ class K_PLUS < Keyboard; end
75
+ class K_COMMA < Keyboard; end
76
+ class K_MINUS < Keyboard; end
77
+ class K_PERIOD < Keyboard; end
78
+ class K_SLASH < Keyboard; end
79
+ class K_K0 < Keyboard; end
80
+ class K_K1 < Keyboard; end
81
+ class K_K2 < Keyboard; end
82
+ class K_K3 < Keyboard; end
83
+ class K_K4 < Keyboard; end
84
+ class K_K5 < Keyboard; end
85
+ class K_K6 < Keyboard; end
86
+ class K_K7 < Keyboard; end
87
+ class K_K8 < Keyboard; end
88
+ class K_K9 < Keyboard; end
89
+ class K_COLON < Keyboard; end
90
+ class K_SEMICOLON < Keyboard; end
91
+ class K_LESS < Keyboard; end
92
+ class K_EQUALS < Keyboard; end
93
+ class K_GREATER < Keyboard; end
94
+ class K_QUESTION < Keyboard; end
95
+ class K_AT < Keyboard; end
96
+ class K_LEFTBRACKET < Keyboard; end
97
+ class K_BACKSLASH < Keyboard; end
98
+ class K_RIGHTBRACKET < Keyboard; end
99
+ class K_CARET < Keyboard; end
100
+ class K_UNDERSCORE < Keyboard; end
101
+ class K_BACKQUOTE < Keyboard; end
102
+ class K_A < Keyboard; end
103
+ class K_B < Keyboard; end
104
+ class K_C < Keyboard; end
105
+ class K_D < Keyboard; end
106
+ class K_E < Keyboard; end
107
+ class K_F < Keyboard; end
108
+ class K_G < Keyboard; end
109
+ class K_H < Keyboard; end
110
+ class K_I < Keyboard; end
111
+ class K_J < Keyboard; end
112
+ class K_K < Keyboard; end
113
+ class K_L < Keyboard; end
114
+ class K_M < Keyboard; end
115
+ class K_N < Keyboard; end
116
+ class K_O < Keyboard; end
117
+ class K_P < Keyboard; end
118
+ class K_Q < Keyboard; end
119
+ class K_R < Keyboard; end
120
+ class K_S < Keyboard; end
121
+ class K_T < Keyboard; end
122
+ class K_U < Keyboard; end
123
+ class K_V < Keyboard; end
124
+ class K_W < Keyboard; end
125
+ class K_X < Keyboard; end
126
+ class K_Y < Keyboard; end
127
+ class K_Z < Keyboard; end
128
+ class K_DELETE < Keyboard; end
129
+ class K_KP0 < Keyboard; end
130
+ class K_KP1 < Keyboard; end
131
+ class K_KP2 < Keyboard; end
132
+ class K_KP3 < Keyboard; end
133
+ class K_KP4 < Keyboard; end
134
+ class K_KP5 < Keyboard; end
135
+ class K_KP6 < Keyboard; end
136
+ class K_KP7 < Keyboard; end
137
+ class K_KP8 < Keyboard; end
138
+ class K_KP9 < Keyboard; end
139
+ class K_KP_PERIOD < Keyboard; end
140
+ class K_KP_DIVIDE < Keyboard; end
141
+ class K_KP_MULTIPLY < Keyboard; end
142
+ class K_KP_MINUS < Keyboard; end
143
+ class K_KP_PLUS < Keyboard; end
144
+ class K_KP_ENTER < Keyboard; end
145
+ class K_KP_EQUALS < Keyboard; end
146
+ class K_UP < Keyboard; end
147
+ class K_DOWN < Keyboard; end
148
+ class K_RIGHT < Keyboard; end
149
+ class K_LEFT < Keyboard; end
150
+ class K_INSERT < Keyboard; end
151
+ class K_HOME < Keyboard; end
152
+ class K_END < Keyboard; end
153
+ class K_PAGEUP < Keyboard; end
154
+ class K_PAGEDOWN < Keyboard; end
155
+ class K_F1 < Keyboard; end
156
+ class K_F2 < Keyboard; end
157
+ class K_F3 < Keyboard; end
158
+ class K_F4 < Keyboard; end
159
+ class K_F5 < Keyboard; end
160
+ class K_F6 < Keyboard; end
161
+ class K_F7 < Keyboard; end
162
+ class K_F8 < Keyboard; end
163
+ class K_F9 < Keyboard; end
164
+ class K_F10 < Keyboard; end
165
+ class K_F11 < Keyboard; end
166
+ class K_F12 < Keyboard; end
167
+ class K_F13 < Keyboard; end
168
+ class K_F14 < Keyboard; end
169
+ class K_F15 < Keyboard; end
170
+ class K_NUMLOCK < Keyboard; end
171
+ class K_CAPSLOCK < Keyboard; end
172
+ class K_SCROLLOCK < Keyboard; end
173
+ class K_RSHIFT < Keyboard; end
174
+ class K_LSHIFT < Keyboard; end
175
+ class K_RCTRL < Keyboard; end
176
+ class K_LCTRL < Keyboard; end
177
+ class K_RALT < Keyboard; end
178
+ class K_LALT < Keyboard; end
179
+ class K_RMETA < Keyboard; end
180
+ class K_LMETA < Keyboard; end
181
+ class K_LSUPER < Keyboard; end
182
+ class K_RSUPER < Keyboard; end
183
+ class K_MODE < Keyboard; end
184
+ class K_HELP < Keyboard; end
185
+ class K_PRINT < Keyboard; end
186
+ class K_SYSREQ < Keyboard; end
187
+ class K_BREAK < Keyboard; end
188
+ class K_MENU < Keyboard; end
189
+ class K_POWER < Keyboard; end
190
+ class K_EURO < Keyboard; end
191
+
192
+ class Joystick
193
+ def self.press?
194
+ return false if $joystick.nil?
195
+ result = false
196
+ b = self.name.gsub "Xibe::Event::J_", ""
197
+ if b == "UP"
198
+ result = true if $joystick.axis(1) == 0
199
+ elsif b == "DOWN"
200
+ result = true if $joystick.axis(1) == 255
201
+ elsif b == "LEFT"
202
+ result = true if $joystick.axis(0) == 0
203
+ elsif b == "RIGHT"
204
+ result = true if $joystick.axis(0) == 255
205
+ else
206
+ b = b.delete "B"
207
+ result = $joystick.button(b.to_i)
208
+ end
209
+ result
210
+ end
211
+
212
+ def self.direction_press?
213
+ return false if $joystick.nil?
214
+ $joystick.axis(0) != 127 || $joystick.axis(1) != 127
215
+ end
216
+ end
217
+
218
+ class J_B0 < Joystick; end
219
+ class J_B1 < Joystick; end
220
+ class J_B2 < Joystick; end
221
+ class J_B3 < Joystick; end
222
+ class J_B4 < Joystick; end
223
+ class J_B5 < Joystick; end
224
+ class J_B6 < Joystick; end
225
+ class J_B7 < Joystick; end
226
+ class J_B8 < Joystick; end
227
+ class J_B9 < Joystick; end
228
+ class J_B10 < Joystick; end
229
+ class J_UP < Joystick; end
230
+ class J_RIGHT < Joystick; end
231
+ class J_DOWN < Joystick; end
232
+ class J_LEFT < Joystick; end
233
+
234
+
235
+ QUIT = SDL::Event2::Quit
236
+ end
237
+
238
+ $bg_cmap = []
239
+ $collide_box = []
240
+
241
+ @@window = nil
242
+ class Application
243
+ attr_accessor :x, :y, :width, :height, :fps, :scene
244
+ #width, height: window size; fullscreen: fullscreen mode; fps: frames per seconds
245
+ def initialize(width, height, fullscreen = false, fps=30)
246
+ @width = width
247
+ @height = height
248
+ @fullscreen = fullscreen
249
+ @fps = fps
250
+ @@window = self
251
+
252
+ SDL.init(SDL::INIT_EVERYTHING)
253
+
254
+ if SDL::Joystick.num > 0
255
+ $joystick = SDL::Joystick.open(0)
256
+ end
257
+
258
+ #SDL::Mixer.open(22050)
259
+ SDL::Mouse.hide
260
+ mode = @fullscreen == true ? SDL::FULLSCREEN|SDL::HWSURFACE : SDL::HWSURFACE
261
+ @screen = SDL::setVideoMode @width, @height, 16, mode
262
+ end
263
+
264
+ #Sets the window title
265
+ def title=(title)
266
+ SDL::WM.set_caption title, ''
267
+ end
268
+
269
+ #Sets the window icon
270
+ def icon=(filename)
271
+ SDL::WM.icon = SDL::Surface.load filename
272
+ end
273
+
274
+ #Run application
275
+ def run
276
+ timer = Timer.new
277
+ loop do
278
+ timer.start
279
+ SDL::Key.scan
280
+ while event = SDL::Event2.poll
281
+ case event
282
+ when SDL::Event2::Quit
283
+ exit
284
+ when SDL::Event2::KeyDown
285
+ $keydown = event.sym
286
+ $any_keydown = true
287
+ when SDL::Event2::KeyUp
288
+ $keyup = event.sym
289
+ $any_keyup = true
290
+ end
291
+ end
292
+
293
+ input
294
+ update
295
+ draw
296
+ @screen.flip
297
+ SDL.delay( (1000 / @fps) - timer.ticks ) if timer.ticks < 1000 / @fps
298
+ end
299
+ end
300
+
301
+ def input
302
+ scene_input unless @scene.nil?
303
+ end
304
+
305
+ def update
306
+ scene_update unless @scene.nil?
307
+ end
308
+
309
+ def draw
310
+ scene_draw unless @scene.nil?
311
+ end
312
+
313
+ #Sets the scene to display
314
+ def display(scene)
315
+ @scene = scene
316
+ @screen.set_clip_rect(0,0,@scene.width,@scene.height)
317
+ end
318
+
319
+ private
320
+ def scene_input
321
+ @scene.input
322
+ end
323
+
324
+ def scene_update
325
+ @scene.update
326
+ end
327
+
328
+ def scene_draw
329
+ @screen.fill_rect(0,0,@width,@height,@scene.fill)
330
+ @scene.draw
331
+ end
332
+ end
333
+
334
+ class Layer
335
+ attr_accessor :x, :y, :width, :height, :z, :visible
336
+ def initialize
337
+ @x = 0
338
+ @y = 0
339
+ @width = 0
340
+ @height = 0
341
+ @z = 0
342
+ @visible = true
343
+ end
344
+
345
+ def show
346
+ @visible = true
347
+ end
348
+
349
+ def hide
350
+ @visible = false
351
+ end
352
+
353
+ #Returns the top position
354
+ def top
355
+ @y
356
+ end
357
+
358
+ #Returns the right position
359
+ def right
360
+ @x + @width
361
+ end
362
+
363
+ #Returns the bottom position
364
+ def bottom
365
+ @y + @height
366
+ end
367
+
368
+ #Returns the left position
369
+ def left
370
+ @x
371
+ end
372
+
373
+ #Sets X and Y position
374
+ def pos(x, y)
375
+ @x = x
376
+ @y = y
377
+ end
378
+ end
379
+
380
+ class Scene
381
+ include Event
382
+ attr_accessor :fill, :camera
383
+ attr_reader :width, :height
384
+ def initialize(width, height,fill = 0x00)
385
+ @width = width
386
+ @height = height
387
+ @fill = fill
388
+ @camera = Layer.new
389
+ @camera.width = @@window.width
390
+ @camera.height = @@window.height
391
+ @objects = []
392
+ end
393
+
394
+ def finalize
395
+
396
+ end
397
+
398
+ #Load map from file
399
+ def load_map(filename)
400
+ lines = File.open(filename).readlines.join
401
+ map = eval(lines)
402
+ map[:tilesets].each do |tileset|
403
+ self.instance_variable_set("@#{tileset[:name]}", Image.to_tiles(tileset[:filename], tileset[:width], tileset[:height], tileset[:transparent], tileset[:margin]))
404
+ end
405
+
406
+ map[:tilemaps].each do |tilemap|
407
+ tiles = self.instance_variable_get("@#{tilemap[:tileset]}")
408
+ tlmap = self.instance_variable_set("@#{tilemap[:name]}", Tilemap.new(tiles, tilemap[:obstacle]))
409
+ tlmap.x = tilemap[:x]
410
+ tlmap.y = tilemap[:y]
411
+ tlmap.z = tilemap[:z]
412
+ tlmap.load_map tilemap[:map], tilemap[:width], tilemap[:height]
413
+ add(tlmap)
414
+ end
415
+ end
416
+
417
+ #Sets the scene to display
418
+ def display(scene)
419
+ finalize
420
+ @@window.scene = scene
421
+ SDL.get_video_surface.set_clip_rect(0,0,@width,@height)
422
+ end
423
+
424
+ def update
425
+
426
+ end
427
+
428
+ #Add the object to scene
429
+ def add(object)
430
+ @objects << object
431
+ @objects = @objects.uniq
432
+ end
433
+
434
+ #Delete the object from scene
435
+ def delete(object)
436
+ @objects.delete(object)
437
+ end
438
+
439
+ #Keyboard, Joystick or Mouse
440
+ def input
441
+
442
+ end
443
+
444
+ #Center camera relative to object
445
+ def center_camera_relative_to(object)
446
+ @camera.x = ( object.x + object.width / 2 ) - @camera.width / 2;
447
+ @camera.y = ( object.y + object.height / 2 ) - @camera.height / 2;
448
+
449
+ if @camera.left < 0
450
+ @camera.x = 0
451
+ end
452
+
453
+ if @camera.top < 0
454
+ @camera.y = 0
455
+ end
456
+
457
+ if @camera.right > @width
458
+ @camera.x = @width - @camera.width
459
+ end
460
+
461
+ if @camera.bottom > @height
462
+ @camera.y = @height - @camera.height
463
+ end
464
+ end
465
+
466
+ #Draw scene
467
+ def draw
468
+ objs = @objects.sort_by { |obj| [obj.z] }
469
+ objs.each do |obj|
470
+ obj.draw
471
+ end
472
+ end
473
+ end
474
+
475
+ class Image < Layer
476
+ attr_reader :filename
477
+ attr_accessor :src_x, :src_y
478
+ def initialize(filename, transparent=false)
479
+ super()
480
+ @filename = filename
481
+ @image = Image.create(@filename, transparent)
482
+ @width = @image.w
483
+ @height = @image.h
484
+ @src_x = 0
485
+ @src_y = 0
486
+ end
487
+
488
+ #Create a image
489
+ def self.create(filename, transparent=false)
490
+ img = SDL::Surface.load(filename)
491
+ color_key = img.get_pixel(0,0)
492
+ img.set_color_key(SDL::SRCCOLORKEY ,color_key) if transparent == true
493
+ img.display_format
494
+ end
495
+
496
+ #Create a tiles from a image file
497
+ def self.to_tiles(filename, width, height, transparent = false, margin = 0)
498
+ img = create(filename, false)
499
+ color_key = img.get_pixel(0,0)
500
+ t_width = (img.w-margin) / (width + margin)
501
+ t_height = (img.h-margin) / (height + margin)
502
+ tiles = []
503
+ i = 0
504
+ while i < t_height do
505
+ j = 0;
506
+ while j < t_width do
507
+ tiles << img.copy_rect(j*(width+margin)+margin, i*(height+margin)+margin, width, height)
508
+ tiles[tiles.length - 1].set_color_key(SDL::SRCCOLORKEY, color_key) if transparent == true
509
+ j += 1
510
+ end
511
+ i += 1
512
+ end
513
+ tiles
514
+ end
515
+
516
+ #Draw image
517
+ def draw
518
+ SDL::Surface.blit(@image, @src_x, @src_y, @width, @height, SDL.get_video_surface, @x, @y)
519
+ end
520
+ end
521
+
522
+ class Tilemap < Layer
523
+ attr_accessor :obstacle
524
+ def initialize(tiles, obstacle = false)
525
+ super()
526
+ @tiles = tiles
527
+ @obstacle = obstacle
528
+ @width = 0
529
+ @height = 0
530
+ @map = [[]]
531
+ if @obstacle == true
532
+ @collide_id = $bg_cmap.length
533
+ end
534
+ end
535
+
536
+ #Load map from array
537
+ def load_map(map, width, height)
538
+ @map = map
539
+ @width = width
540
+ @height = height
541
+ if @obstacle == true
542
+ $bg_cmap[@collide_id] = []
543
+ for i in 0..@height - 1
544
+ for j in 0..@width - 1
545
+ $bg_cmap[@collide_id] << {:map => @tiles[@map[i][j]].make_collision_map, :x => j*@tiles[@map[i][j]].w+@x, :y => i*@tiles[@map[i][j]].h+@y}
546
+ end
547
+ end
548
+ end
549
+ end
550
+
551
+ #Draw tilemap
552
+ def draw
553
+ if @visible == true
554
+ for i in 0..@height -1
555
+ for j in 0..@width - 1
556
+ draw_tile(@tiles[@map[i][j]], j*@tiles[@map[i][j]].w+@x, i*@tiles[@map[i][j]].h+@y)
557
+ end
558
+ end
559
+ end
560
+ end
561
+
562
+ private
563
+ #Draw tile
564
+ def draw_tile(image, x, y)
565
+ SDL::Surface.blit(image, 0, 0, image.w, image.h, SDL.get_video_surface, x - @@window.scene.camera.x, y - @@window.scene.camera.y)
566
+ end
567
+ end
568
+
569
+ class Sprite < Layer
570
+ attr_accessor :frames, :delay, :direction
571
+ attr_writer :animate
572
+ def initialize(filename,width,height,transparent=false)
573
+ super()
574
+ @tiles = Image.to_tiles(filename, width, height, transparent)
575
+ @width = width
576
+ @height = height
577
+ @frames = []
578
+ @frame = 0
579
+ @delay = 200
580
+ @last_update = 0
581
+ @direction = :right
582
+ @visible = true
583
+ @animate = true
584
+ @tile
585
+ @cmap
586
+ end
587
+
588
+ #Go to first frame
589
+ def first_frame
590
+ @frame = 0
591
+ end
592
+
593
+ #Go to last frame
594
+ def last_frame
595
+ @frame = @frames.length - 1
596
+ end
597
+
598
+ #Go to next frame
599
+ def next_frame
600
+ @frame += 1
601
+ first_frame if @frame > @frames.length - 1
602
+ end
603
+
604
+ #Go to previous frame
605
+ def prev_frame
606
+ @frame -= 1
607
+ last_frame if @frame < 0
608
+ end
609
+
610
+ #Go to parameter frame
611
+ def go_frame(frame)
612
+ @frame = frame
613
+ end
614
+
615
+ #Draw sprite
616
+ def draw
617
+ animate if @animate == true
618
+ first_frame if @frames[@frame].nil?
619
+ draw_tile(@tiles[@frames[@frame]], @x, @y) if @visible == true
620
+ end
621
+
622
+ private
623
+ #Draw current frame
624
+ def draw_tile(image, x, y)
625
+ SDL::Surface.blit(image, 0, 0, image.w, image.h, SDL.get_video_surface, x - @@window.scene.camera.x, y - @@window.scene.camera.y)
626
+ end
627
+
628
+ #Animate sprite
629
+ def animate
630
+ curtime = SDL.get_ticks
631
+ while curtime >= (@last_update + @delay)
632
+ @last_update += @delay
633
+ next_frame
634
+ end
635
+ end
636
+ end
637
+
638
+ class Timer
639
+ def initialize
640
+ @start_ticks = 0
641
+ @paused_ticks = 0
642
+ @paused = false
643
+ @started = false
644
+ end
645
+
646
+ #Start counter timer
647
+ def start
648
+ @started = true
649
+ @paused = false
650
+ @start_ticks = SDL.get_ticks
651
+ end
652
+
653
+ #Stop counter timer
654
+ def stop
655
+ @started = false
656
+ @paused = false
657
+ end
658
+
659
+ #Pause counter timer
660
+ def pause
661
+ if @started == true && @paused == false
662
+ @paused = true
663
+ @paused_ticks = SDL.get_ticks - @start_ticks
664
+ end
665
+ end
666
+
667
+ #Resume counter timer
668
+ def resume
669
+ if @paused == true
670
+ @paused = false
671
+ @start_ticks = SDL.get_ticks - @paused_ticks
672
+ @paused_ticks = 0
673
+ end
674
+ end
675
+
676
+ #Return current tick
677
+ def ticks
678
+ t = 0
679
+ if @started == true
680
+ if @paused == true
681
+ t = @paused_ticks
682
+ else
683
+ t = SDL.get_ticks - @start_ticks
684
+ end
685
+ end
686
+ t
687
+ end
688
+
689
+ #Return true if started == true
690
+ def started?
691
+ @started
692
+ end
693
+
694
+ #Return true if paused == true
695
+ def paused?
696
+ @paused
697
+ end
698
+ end
699
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xibe
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-04-10 00:00:00 -03:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Developer Game
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/xibe.rb
30
+ has_rdoc: true
31
+ homepage: http://codesheep.com/xibe/
32
+ post_install_message:
33
+ rdoc_options: []
34
+
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: "0"
42
+ version:
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ requirements: []
50
+
51
+ rubyforge_project: xibe
52
+ rubygems_version: 1.3.1
53
+ signing_key:
54
+ specification_version: 2
55
+ summary: Developer Game
56
+ test_files: []
57
+