Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 4445893

Browse files
committed
No longer frame locked, should run smoother with varied fps, fixed logger, now using texplay and ashton for RubyGems instead of source.
1 parent dcaedf4 commit 4445893

File tree

19 files changed

+155
-111
lines changed

19 files changed

+155
-111
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ pkg
99
inkscape/*
1010
assets/scal/*
1111
assets/pencil/*
12+
lib/planet-wars/logs/*

Gemfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ gem "humanize"
44
gem "gosu"
55
gem "chingu", "0.9rc9"
66
gem "rake", "0.9.2.2"
7-
gem "texplay", github: "banister/texplay"
8-
gem "ashton", github: "Spooner/ashton"
7+
gem "texplay", "~> 0.4.4.pre"
8+
gem "ashton"
99
gem "chroma"
1010
gem "oj"
1111
gem "excon"
1212
gem "launchy"
1313

1414
group :package do
15+
# gem "libxml-ruby", '~> 2.7.0'
1516
# gem "releasy" # Uncomment when building executable
1617
end
1718

Gemfile.lock

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,35 @@
1-
GIT
2-
remote: git://github.com/Spooner/ashton.git
3-
revision: 313673d8b1b3e1082c9d24e4a166396d1f471634
4-
specs:
5-
ashton (0.1.5)
6-
gosu (~> 0.7)
7-
opengl (~> 0.9.0)
8-
9-
GIT
10-
remote: git://github.com/banister/texplay.git
11-
revision: a7055d39aee332b6ef98327bf6463a10ee1098cb
12-
specs:
13-
texplay (0.4.4.pre)
14-
gosu (>= 0.7.25)
15-
161
GEM
172
remote: https://rubygems.org/
183
specs:
194
addressable (2.4.0)
5+
ashton (0.1.6)
6+
gosu (~> 0.7)
7+
opengl (~> 0.9.0)
208
chingu (0.9rc9)
219
gosu (>= 0.7.45)
2210
chroma (0.0.1)
23-
excon (0.45.4)
24-
gosu (0.10.4)
25-
gosu (0.10.4-x86-mingw32)
26-
humanize (1.1.0)
11+
excon (0.49.0)
12+
gosu (0.10.6)
13+
gosu (0.10.6-x64-mingw32)
14+
gosu (0.10.6-x86-mingw32)
15+
humanize (1.1.1)
2716
launchy (2.4.3)
2817
addressable (~> 2.3)
29-
oj (2.14.3)
18+
oj (2.15.0)
3019
opengl (0.9.2)
20+
opengl (0.9.2-x64-mingw32)
3121
opengl (0.9.2-x86-mingw32)
3222
rake (0.9.2.2)
23+
texplay (0.4.4.pre)
24+
gosu (>= 0.7.25)
3325

3426
PLATFORMS
3527
ruby
28+
x64-mingw32
3629
x86-mingw32
3730

3831
DEPENDENCIES
39-
ashton!
32+
ashton
4033
chingu (= 0.9rc9)
4134
chroma
4235
excon
@@ -45,7 +38,7 @@ DEPENDENCIES
4538
launchy
4639
oj
4740
rake (= 0.9.2.2)
48-
texplay!
41+
texplay (~> 0.4.4.pre)
4942

5043
BUNDLED WITH
51-
1.10.6
44+
1.11.2

lib/planet-wars/ai/ai.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ class AI
55
attr_accessor :game_object, :state, :tick
66
def initialize(game_object)
77
@game_object = game_object
8-
@tick = 0
98
@state = :nil
9+
@last_fired_at = Engine.now
1010
setup
1111
end
1212

@@ -19,6 +19,7 @@ def update
1919
end
2020

2121
def move(object)
22+
speed = game_object.speed*Engine.dt
2223
# TODO: Flock behavior
2324

2425
game_object.dx = object.x - game_object.x
@@ -27,8 +28,8 @@ def move(object)
2728
length = Math.sqrt( game_object.dx*game_object.dx + game_object.dy*game_object.dy )
2829
game_object.dx /= length; game_object.dy /= length
2930

30-
game_object.dx *= game_object.speed
31-
game_object.dy *= game_object.speed
31+
game_object.dx *= speed
32+
game_object.dy *= speed
3233

3334
game_object.x += game_object.dx
3435
game_object.y += game_object.dy

lib/planet-wars/ai/enemy_ai.rb

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ def setup
44
end
55

66
def update
7-
@tick+=1
8-
97
case state
108
when :seek
119
seek
@@ -35,12 +33,10 @@ def seek
3533
def attack
3634
move(game_object.target)
3735

38-
if @tick >= 60
39-
@tick = 0
40-
game_object.fire_bullet!
36+
if (Engine.now-@last_fired_at) >= 1000.0
37+
@last_fired_at = Engine.now
38+
game_object.fire_bullet! if game_object.target_area.in_range
4139
end
42-
43-
@tick += 1
4440
end
4541

4642
def retreat
@@ -57,12 +53,11 @@ def retreat
5753
Logger.log("#{e} - #{game_object.x}|#{game_object.y}", self)
5854
end
5955

60-
if @tick >= 60
61-
@tick = 0
56+
if (Engine.now-@last_fired_at) >= 1000.0
57+
@last_fired_at = Engine.now
6258
game_object.fire_bullet! if game_object.target_area.in_range
6359
end
6460

65-
@tick += 1
6661
move(@portal)
6762
end
6863
end

lib/planet-wars/dev_stats/build.dat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3483
1+
3546

lib/planet-wars/game/data/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
config:
3-
update_check: 2016-01-06 20:13:21 UTC
3+
update_check: 2016-04-08 22:52:33 UTC
44
asset_pack: default
5-
music: true
6-
sounds: true
5+
music: false
6+
sounds: false
77
hazards: true
88
screen:
99
width: max

lib/planet-wars/game/engine.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
class Engine < Chingu::Window
22
attr_accessor :show_cursor
33

4-
def initialize
4+
def self.now
5+
Gosu.milliseconds
6+
end
7+
8+
def self.dt
9+
$window.dt/1000.0
10+
end
11+
12+
def initialize(width = 800, height = 600, fullscreen = false, update_interval = 1000.0/60)
513
@show_cursor = false
614
width = Gosu.screen_width if ConfigManager.config["screen"]["width"] == 'max'
715
width = ConfigManager.config["screen"]["width"] if ConfigManager.config["screen"]["width"].is_a?(Integer)
816

917
height= Gosu.screen_height if ConfigManager.config["screen"]["height"] == 'max'
1018
height= ConfigManager.config["screen"]["height"] if ConfigManager.config["screen"]["height"].is_a?(Integer)
1119

12-
super(width, height, ConfigManager.config["screen"]["fullscreen"])
20+
super(width, height, ConfigManager.config["screen"]["fullscreen"], update_interval)
1321
self.caption = "#{GameInfo::NAME} #{GameInfo::VERSION} [build: #{BUILD}] #{Gosu.language}"
1422
AssetManager.preload_assets if ARGV.join.include?('--debug')
1523

@@ -31,6 +39,8 @@ def initialize
3139
Chingu::Input::CONSTANT_TO_SYMBOL[Gosu::GpButton14] = [:gp_14]
3240
Chingu::Input::CONSTANT_TO_SYMBOL[Gosu::GpButton15] = [:gp_15]
3341

42+
Logger.log("Window: width: #{width}, height: #{height}, fullscreen: #{fullscreen}, update_interval: #{update_interval}", self)
43+
3444
push_game_state(Boot) unless ARGV.join.include?('--debug')
3545
push_game_state(Game) if ARGV.join.include?('--debug')
3646
end

lib/planet-wars/game/state/game.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def setup
1919
[:enter, :return, :gp_3] => :enter,
2020
[:escape, :gp_6] => :escape,
2121
[:p, :gp_4] => :pause_game,
22-
[:gp_2] => :upgrades_menu,
22+
[:u, :gp_2] => :upgrades_menu,
2323
[:c] => :debugging_waves
2424
}
2525

lib/planet-wars/game/state/helpers/game/game_hud.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def draw
3636
def update
3737
@clock_counter+=1
3838
if @clock_counter <= 60
39-
@clock_time+=0.01667
39+
@clock_time+=$window.dt/1000.0
4040
@clock_counter=0
4141
end
4242
@time = Time.at((@clock_time)).gmtime

lib/planet-wars/logger.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
module Logger
22
# Includable
33
def log(string, klass)
4-
write_log("#{Time.now.utc.strftime('%H:%M %d/%m/%Y %Z')} | #{klass.class} wrote> #{string}")
4+
write_log("#{Time.now.utc.strftime('%H:%M:%S %d/%m/%Y %Z')} | #{klass.class} wrote> #{string}")
55
end
66

77
def write_log(string)
8-
open("./lib/planet-wars/logs/#{Time.now.utc.strftime('%d_%Y')}_log.txt", "a") {|f| f.write(string)}
8+
unless File.exists?("./lib/planet-wars/logs") && File.directory?("./lib/planet-wars/logs")
9+
Dir.mkdir("./lib/planet-wars/logs")
10+
end
11+
12+
open("./lib/planet-wars/logs/#{Time.now.utc.strftime('%d_%Y')}_log.txt", "a+") {|f| f.write(string+"\n")}
913
end
1014

1115
# Not includable
1216
def self.log(string, klass)
13-
write_log("#{Time.now.utc.strftime('%H:%M %d/%m/%Y %Z')} | #{klass.class} wrote> #{string}")
17+
write_log("#{Time.now.utc.strftime('%H:%M:%S %d/%m/%Y %Z')} | #{klass.class} wrote> #{string}")
1418
end
1519

1620
def self.write_log(string)
17-
open("./lib/planet-wars/logs/#{Time.now.utc.strftime('%d_%Y')}_log.txt", "a") {|f| f.write(string)}
21+
unless File.exists?("./lib/planet-wars/logs") && File.directory?("./lib/planet-wars/logs")
22+
Dir.mkdir("./lib/planet-wars/logs")
23+
end
24+
25+
open("./lib/planet-wars/logs/#{Time.now.utc.strftime('%d_%Y')}_log.txt", "a+") {|f| f.write(string+"\n")}
1826
end
1927
end

lib/planet-wars/objects/asteroid.rb

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def setup
1212
@image = Gosu::Image["#{AssetManager.asteroids_path}/#{File.basename(asteroid_images[random])}"]
1313
trait_options[:bounding_circle][:scale] = 0.8
1414
@health= 200
15-
@speed = 5
15+
@speed = 5*60
1616
@damage= 50
1717
@rotation = rand(-5..5)
1818
self.zorder = 300
@@ -22,8 +22,10 @@ def setup
2222
end
2323

2424
def update
25-
rotate(@rotation)
25+
rotation = (@rotation*60)*Engine.dt
26+
rotate(rotation)
2627
check_for_collisions
28+
update_velocity
2729
destroy_self?
2830
end
2931

@@ -62,13 +64,18 @@ def destroy_self?
6264
end
6365

6466
def set_velocity
65-
@dx = rand(-1500..1500) - self.x
66-
@dy = rand(-1500..1500) - self.y
67-
length = Math.sqrt( @dx*@dx + @dy*@dy )
68-
@dx /= length; @dy /= length
69-
@dx *= @speed; @dy *= @speed
70-
self.velocity_x += @dx
71-
self.velocity_y += @dy
67+
@dx = rand(-1500..1500) - self.x
68+
@dy = rand(-1500..1500) - self.y
69+
length = Math.sqrt( @dx*@dx + @dy*@dy )
70+
@dx /= length; @dy /= length
71+
end
72+
73+
def update_velocity
74+
dx, dy = @dx, @dy
75+
speed = @speed*Engine.dt
76+
dx *= speed; dy *= speed
77+
self.velocity_x = dx
78+
self.velocity_y = dy
7279
end
7380

7481
def hit(damage, bullet)

0 commit comments

Comments
 (0)