-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgametemplate.rb
91 lines (65 loc) · 1.43 KB
/
gametemplate.rb
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
# Load Rubygame and include Rubygame and Rubygame::Events
# in the current namespace, for convenience.
#
require "rubygems"
require "rubygame"
require 'loadmap.rb'
require 'character.rb'
require 'state.rb'
require 'states/MainMenu.rb'
include Rubygame
include Rubygame::Events
include Load
TILESIZE = 32
class Game
## Load Content ##
def initialize()
Rubygame.init
at_exit { Rubygame.quit }
make_clock
this_dir = File.dirname( File.expand_path(__FILE__) )
Surface.autoload_dirs << File.join(this_dir, "gfx")
player = Surface["ninja.png"]
ground = Surface["ground.bmp"]
wall = Surface["wall.bmp"]
@tiles = {}
begin
@tiles["@"] = player
@tiles["_"] = ground
@tiles["#"] = wall
@screen = Rubygame::Screen.set_mode [320,240]
@screen.title = 'Battle Sim'
@screen.fill [0,0,0]
@screen.update
@mainState = MainMenu.new(@screen, @tiles)
rescue SDLError, NoMethodError
exit
puts "Failed to load data"
end
end
def update()
@mainState.update(@clock)
end
## Draw ##
def draw()
# Refresh the screen
@screen.fill(:black)
@mainState.draw()
@screen.update
end
def run()
loop do
update()
draw()
end
end
def make_clock
@clock = Clock.new()
@clock.target_framerate = 60
@clock.calibrate
@clock.enable_tick_events
end
end
game = Game.new()
player1 = Character.new()
game.run()