chingu 0.8rc2 → 0.8rc3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. data/README.rdoc +66 -19
  2. data/benchmarks/arrays_bench.rb +22 -0
  3. data/benchmarks/game_objects_benchmark.rb +29 -35
  4. data/chingu.gemspec +16 -2
  5. data/examples/example18_animation_trait.rb +14 -9
  6. data/examples/example19.yml +305 -561
  7. data/examples/example19_edit_viewport.rb +3 -1
  8. data/examples/example1_basics.rb +4 -4
  9. data/examples/example21.yml +62 -54
  10. data/examples/example21_sidescroller_with_edit.rb +13 -21
  11. data/examples/example4_gamestates.rb +0 -2
  12. data/examples/example7_gfx_helpers.rb +1 -1
  13. data/examples/example8_traits.rb +1 -2
  14. data/examples/example9_collision_detection.rb +1 -1
  15. data/examples/game1.rb +1 -1
  16. data/lib/chingu.rb +1 -2
  17. data/lib/chingu/animation.rb +13 -5
  18. data/lib/chingu/assets.rb +2 -2
  19. data/lib/chingu/basic_game_object.rb +33 -30
  20. data/lib/chingu/game_object.rb +0 -5
  21. data/lib/chingu/game_object_list.rb +34 -21
  22. data/lib/chingu/game_states/edit.rb +2 -5
  23. data/lib/chingu/game_states/fade_to.rb +0 -1
  24. data/lib/chingu/game_states/pause.rb +1 -1
  25. data/lib/chingu/helpers/game_object.rb +0 -1
  26. data/lib/chingu/parallax.rb +3 -9
  27. data/lib/chingu/simple_menu.rb +7 -8
  28. data/lib/chingu/traits/animation.rb +2 -4
  29. data/lib/chingu/traits/sprite.rb +16 -13
  30. data/lib/chingu/window.rb +1 -1
  31. data/spec/chingu/animation_spec.rb +88 -0
  32. data/spec/chingu/assets_spec.rb +58 -0
  33. data/spec/chingu/basic_game_object_spec.rb +111 -0
  34. data/spec/chingu/game_object_list_spec.rb +78 -0
  35. data/spec/chingu/game_object_spec.rb +50 -14
  36. data/spec/chingu/game_state_manager_spec.rb +105 -0
  37. data/spec/chingu/helpers/input_client_spec.rb +4 -0
  38. data/spec/chingu/helpers/input_dispatcher_spec.rb +4 -0
  39. data/spec/chingu/images/droid_11x15.bmp +0 -0
  40. data/spec/chingu/parallax_spec.rb +25 -16
  41. data/spec/chingu/window_spec.rb +55 -0
  42. data/spec/spec_helper.rb +1 -5
  43. metadata +17 -3
@@ -33,7 +33,9 @@ class Example19 < GameState
33
33
  # 1) map 2) stars 3) player
34
34
  # Since we don't give any zorders Chingu automatically increments zorder between each object created, putting player on top
35
35
  #
36
- def setup
36
+ def initialize(options = {})
37
+ super
38
+
37
39
  self.input = { :escape => :exit, :e => :edit }
38
40
 
39
41
  Sound["laser.wav"] # cache sound by accessing it once
@@ -30,10 +30,10 @@ class Game < Chingu::Window
30
30
  end
31
31
 
32
32
  class Player < Chingu::GameObject
33
- def move_left; @x -= 1; end
34
- def move_right; @x += 1; end
35
- def move_up; @y -= 1; end
36
- def move_down; @y += 1; end
33
+ def move_left; @x -= 3; end
34
+ def move_right; @x += 3; end
35
+ def move_up; @y -= 3; end
36
+ def move_down; @y += 3; end
37
37
  end
38
38
 
39
39
 
@@ -2,7 +2,7 @@
2
2
  - CogWheel:
3
3
  :x: 1088.0
4
4
  :y: 352.0
5
- :angle: 238.31818883902704
5
+ :angle: 21.323463353534763
6
6
  :zorder: 95
7
7
  :factor_x: 1.68525252525252
8
8
  :factor_y: 1.68525252525252
@@ -930,7 +930,7 @@
930
930
  - CogWheel:
931
931
  :x: 1792.0
932
932
  :y: 320.0
933
- :angle: 205.68237008923398
933
+ :angle: 62.67709557472743
934
934
  :zorder: 95
935
935
  :factor_x: 1.68525252525252
936
936
  :factor_y: 1.68525252525252
@@ -946,7 +946,7 @@
946
946
  - CogWheel:
947
947
  :x: 2464.0
948
948
  :y: 288.0
949
- :angle: 350.97150938554654
949
+ :angle: 133.9767839000518
950
950
  :zorder: 95
951
951
  :factor_x: 1.68525252525252
952
952
  :factor_y: 1.68525252525252
@@ -954,7 +954,7 @@
954
954
  - CogWheel:
955
955
  :x: 2460.0
956
956
  :y: 960.0
957
- :angle: 207.68237008923398
957
+ :angle: 64.67709557472737
958
958
  :zorder: 95
959
959
  :factor_x: 1.68525252525252
960
960
  :factor_y: 1.68525252525252
@@ -1065,40 +1065,40 @@
1065
1065
  :alpha: 255
1066
1066
  - Saw:
1067
1067
  :x: 2304.0
1068
- :y: 42980.3876971599
1069
- :angle: 41.72555205053806
1068
+ :y: 42982.52618296432
1069
+ :angle: 156.78075709785693
1070
1070
  :zorder: 100
1071
1071
  :factor_x: 0.317794486215539
1072
1072
  :factor_y: 0.320401002506266
1073
1073
  :alpha: 255
1074
1074
  - Saw:
1075
1075
  :x: 2016.0
1076
- :y: 32178.4911927486
1077
- :angle: 72.34574735821182
1076
+ :y: 32179.99471564744
1077
+ :angle: 87.12304982424301
1078
1078
  :zorder: 100
1079
1079
  :factor_x: 0.398395989974937
1080
1080
  :factor_y: 0.401002506265664
1081
1081
  :alpha: 255
1082
1082
  - Saw:
1083
1083
  :x: 1696.0
1084
- :y: 14501.1166797636
1085
- :angle: 226.82001857098814
1084
+ :y: 14501.157370140168
1085
+ :angle: 261.2054788220373
1086
1086
  :zorder: 100
1087
1087
  :factor_x: 0.958395989974934
1088
1088
  :factor_y: 0.961002506265664
1089
1089
  :alpha: 255
1090
1090
  - Saw:
1091
1091
  :x: 1056.0
1092
- :y: 24038.686890917
1093
- :angle: 62.16252750703487
1092
+ :y: 24039.250707326933
1093
+ :angle: 115.75652310590293
1094
1094
  :zorder: 100
1095
1095
  :factor_x: 0.637794486215539
1096
1096
  :factor_y: 0.640401002506266
1097
1097
  :alpha: 255
1098
1098
  - Saw:
1099
1099
  :x: 1344.0
1100
- :y: 24038.686890917
1101
- :angle: 65.16252750703583
1100
+ :y: 24039.250707326933
1101
+ :angle: 118.75652310590394
1102
1102
  :zorder: 100
1103
1103
  :factor_x: 0.637794486215539
1104
1104
  :factor_y: 0.640401002506266
@@ -1353,72 +1353,72 @@
1353
1353
  :alpha: 255
1354
1354
  - Saw:
1355
1355
  :x: 2176.0
1356
- :y: 42820.3876971599
1357
- :angle: 44.725552050538056
1356
+ :y: 42822.52618296432
1357
+ :angle: 159.7807570978569
1358
1358
  :zorder: 100
1359
1359
  :factor_x: 0.317794486215539
1360
1360
  :factor_y: 0.320401002506266
1361
1361
  :alpha: 255
1362
1362
  - Saw:
1363
1363
  :x: 1280.0
1364
- :y: 30827.366022672
1365
- :angle: 300.0776055490816
1364
+ :y: 30828.455270887032
1365
+ :angle: 14.551566069882607
1366
1366
  :zorder: 100
1367
1367
  :factor_x: 0.47739348370927
1368
1368
  :factor_y: 0.48
1369
1369
  :alpha: 255
1370
1370
  - Saw:
1371
1371
  :x: 1055.0
1372
- :y: 91497.8070513121
1373
- :angle: 344.02733176191106
1372
+ :y: 91503.18461541468
1373
+ :angle: 287.05617791584626
1374
1374
  :zorder: 100
1375
1375
  :factor_x: 0.156390977443606
1376
1376
  :factor_y: 0.158997493734336
1377
1377
  :alpha: 255
1378
1378
  - Saw:
1379
1379
  :x: 960.0
1380
- :y: 91561.8070513122
1381
- :angle: 347.02733176190907
1380
+ :y: 91567.18461541476
1381
+ :angle: 290.0561779158443
1382
1382
  :zorder: 100
1383
1383
  :factor_x: 0.156390977443606
1384
1384
  :factor_y: 0.158997493734336
1385
1385
  :alpha: 255
1386
1386
  - Saw:
1387
1387
  :x: 1120.0
1388
- :y: 91561.8070513122
1389
- :angle: 347.02733176190907
1388
+ :y: 91567.18461541476
1389
+ :angle: 290.0561779158443
1390
1390
  :zorder: 100
1391
1391
  :factor_x: 0.156390977443606
1392
1392
  :factor_y: 0.158997493734336
1393
1393
  :alpha: 255
1394
1394
  - Saw:
1395
1395
  :x: 864.0
1396
- :y: 91497.8070513121
1397
- :angle: 350.02733176190907
1396
+ :y: 91503.18461541468
1397
+ :angle: 293.0561779158443
1398
1398
  :zorder: 100
1399
1399
  :factor_x: 0.156390977443606
1400
1400
  :factor_y: 0.158997493734336
1401
1401
  :alpha: 255
1402
1402
  - Saw:
1403
1403
  :x: 1247.0
1404
- :y: 27759.2193277261
1405
- :angle: 320.6743989618843
1404
+ :y: 27760.30945377652
1405
+ :angle: 35.78469307954082
1406
1406
  :zorder: 100
1407
1407
  :factor_x: 0.477192982456137
1408
1408
  :factor_y: 0.479799498746867
1409
1409
  :alpha: 255
1410
1410
  - Saw:
1411
1411
  :x: 1088.0
1412
- :y: 54684.0355932234
1413
- :angle: 146.99443884993184
1412
+ :y: 54687.2512711895
1413
+ :angle: 322.8948625787961
1414
1414
  :zorder: 100
1415
1415
  :factor_x: 0.236591478696738
1416
1416
  :factor_y: 0.239197994987469
1417
1417
  :alpha: 255
1418
1418
  - Saw:
1419
1419
  :x: 960.0
1420
- :y: 54684.0355932234
1421
- :angle: 149.99443884993195
1420
+ :y: 54687.2512711895
1421
+ :angle: 325.89486257879616
1422
1422
  :zorder: 100
1423
1423
  :factor_x: 0.236591478696738
1424
1424
  :factor_y: 0.239197994987469
@@ -1537,88 +1537,88 @@
1537
1537
  :alpha: 255
1538
1538
  - Saw:
1539
1539
  :x: 2272.0
1540
- :y: 1362.6472068444905
1541
- :angle: 237.91947659816137
1540
+ :y: 1465.5598892803227
1541
+ :angle: 252.69677906419255
1542
1542
  :zorder: 100
1543
1543
  :factor_x: 0.398395989974937
1544
1544
  :factor_y: 0.401002506265664
1545
1545
  :alpha: 255
1546
1546
  - Saw:
1547
1547
  :x: 1792.0
1548
- :y: 1415.2943760984278
1549
- :angle: 203.02724077304177
1548
+ :y: 1382.9861913130887
1549
+ :angle: 28.365553602565324
1550
1550
  :zorder: 100
1551
1551
  :factor_x: 0.79859649122807
1552
1552
  :factor_y: 0.801203007518797
1553
1553
  :alpha: 255
1554
1554
  - Saw:
1555
1555
  :x: 2112.0
1556
- :y: 1330.7449409780638
1557
- :angle: 199.5458246302823
1556
+ :y: 1318.1290050590083
1557
+ :angle: 359.9863811226902
1558
1558
  :zorder: 100
1559
1559
  :factor_x: 0.237794486215539
1560
1560
  :factor_y: 0.240401002506266
1561
1561
  :alpha: 255
1562
1562
  - Saw:
1563
1563
  :x: 1504.0
1564
- :y: 1551.27092138629
1565
- :angle: 210.11538461603345
1564
+ :y: 1554.4759087066618
1565
+ :angle: 18.26627219000278
1566
1566
  :zorder: 100
1567
1567
  :factor_x: 0.23719298245614
1568
1568
  :factor_y: 0.239799498746867
1569
1569
  :alpha: 255
1570
1570
  - Saw:
1571
1571
  :x: 1344.0
1572
- :y: 1420.697802197812
1573
- :angle: 213.11538461603647
1572
+ :y: 1424.913778529173
1573
+ :angle: 21.266272190005793
1574
1574
  :zorder: 100
1575
1575
  :factor_x: 0.23719298245614
1576
1576
  :factor_y: 0.239799498746867
1577
1577
  :alpha: 255
1578
1578
  - Saw:
1579
1579
  :x: 1152.0
1580
- :y: 1400.550295858002
1581
- :angle: 216.11538461603348
1580
+ :y: 1404.766272189363
1581
+ :angle: 24.26627219000278
1582
1582
  :zorder: 100
1583
1583
  :factor_x: 0.23719298245614
1584
1584
  :factor_y: 0.239799498746867
1585
1585
  :alpha: 255
1586
1586
  - Saw:
1587
1587
  :x: 992.0
1588
- :y: 1373.3390804597661
1589
- :angle: 223.96232061665756
1588
+ :y: 1379.7088122605323
1589
+ :angle: 149.27841257069542
1590
1590
  :zorder: 100
1591
1591
  :factor_x: 0.156992481203007
1592
1592
  :factor_y: 0.159598997493734
1593
1593
  :alpha: 255
1594
1594
  - Saw:
1595
1595
  :x: 800.0
1596
- :y: 1373.3390804597661
1597
- :angle: 226.96232061665756
1596
+ :y: 1379.7088122605323
1597
+ :angle: 152.27841257069542
1598
1598
  :zorder: 100
1599
1599
  :factor_x: 0.156992481203007
1600
1600
  :factor_y: 0.159598997493734
1601
1601
  :alpha: 255
1602
1602
  - Saw:
1603
1603
  :x: 1248.0
1604
- :y: 1452.2977917981073
1605
- :angle: 77.7519563145171
1604
+ :y: 1404.0892744479506
1605
+ :angle: 192.80716136183597
1606
1606
  :zorder: 100
1607
1607
  :factor_x: 0.317794486215539
1608
1608
  :factor_y: 0.320401002506266
1609
1609
  :alpha: 255
1610
1610
  - Saw:
1611
1611
  :x: 928.0
1612
- :y: 1341.641762452114
1613
- :angle: 229.9623206166576
1612
+ :y: 1348.0114942528803
1613
+ :angle: 155.27841257069545
1614
1614
  :zorder: 100
1615
1615
  :factor_x: 0.156992481203007
1616
1616
  :factor_y: 0.159598997493734
1617
1617
  :alpha: 255
1618
1618
  - Saw:
1619
1619
  :x: 672.0
1620
- :y: 1318.3473818646446
1621
- :angle: 226.96232061665756
1620
+ :y: 1324.7171136654108
1621
+ :angle: 152.27841257069542
1622
1622
  :zorder: 100
1623
1623
  :factor_x: 0.156992481203007
1624
1624
  :factor_y: 0.159598997493734
@@ -2135,3 +2135,11 @@
2135
2135
  :factor_x: 0.071748878923767
2136
2136
  :factor_y: 0.071748878923767
2137
2137
  :alpha: 255
2138
+ - Block:
2139
+ :x: 384.0
2140
+ :y: 352.0
2141
+ :angle: 0
2142
+ :zorder: 100
2143
+ :factor_x: 0.13901345291479816
2144
+ :factor_y: 0.13901345291479816
2145
+ :alpha: 255
@@ -8,14 +8,15 @@ include Chingu
8
8
  #
9
9
  # Press 'E' when demo is running to edit the playfield!
10
10
  #
11
- class Game < Chingu::Window
11
+ class Game < Chingu::Window
12
12
  def initialize
13
- super(1000,700)
13
+ #super(1000,700)
14
+ super(1024,768, true)
14
15
  end
15
16
 
16
17
  def setup
17
- Gosu::enable_undocumented_retrofication
18
- switch_game_state(Example21.new)
18
+ retrofy
19
+ switch_game_state(Example21)
19
20
  end
20
21
  end
21
22
 
@@ -25,14 +26,14 @@ end
25
26
  class Example21 < GameState
26
27
  traits :viewport, :timer
27
28
 
28
- def setup
29
+ def initialize(options = {})
30
+ super
31
+
29
32
  self.input = { :escape => :exit, :e => :edit }
30
33
  self.viewport.game_area = [0, 0, 3500, 2000]
31
34
 
32
- @droid = Droid.create(:x => 100, :y => 400)
33
- #@droid = Droid.create(:x => 400, :y => 1300)
34
-
35
35
  load_game_objects
36
+ @droid = Droid.create(:x => 100, :y => 400)
36
37
 
37
38
  # Reverse the cog wheels in relation to eachother
38
39
  CogWheel.each_collision(CogWheel) do |cog_wheel, cog_wheel_2|
@@ -44,7 +45,7 @@ class Example21 < GameState
44
45
  end
45
46
 
46
47
  def edit
47
- push_game_state(GameStates::Edit.new(:grid => [32,32], :classes => [Tube, CogWheel, Block, Saw, Battery]))
48
+ push_game_state(GameStates::Edit.new(:grid => [32,32], :classes => [Droid, Tube, CogWheel, Block, Saw, Battery]))
48
49
  end
49
50
 
50
51
  def restore_player_position
@@ -58,19 +59,10 @@ class Example21 < GameState
58
59
  def update
59
60
  super
60
61
 
61
- visible_blocks = Block
62
-
63
- #
64
- # Eating a lot of CPU cause our crude collision detection, just kill fireballs after 3 secs instead.
65
- #
66
- # FireBall.each_collision(visible_blocks) do |fire_ball, block|
67
- # fire_ball.destroy
68
- # end
69
-
70
62
  # Makes all saw pendle up and down between Y-coordinate 1000 - 1500
71
63
  # TODO: Not a very flexible sollution, how about setting out circle,rects,lines in editor..
72
64
  # .. when then can be used for this kind of stuff?
73
- Saw.all.select {|saw| saw.y < 1300 || saw.y > 1550 }.each do |saw|
65
+ Saw.select {|saw| saw.y < 1300 || saw.y > 1550 }.each do |saw|
74
66
  saw.velocity_y = -saw.velocity_y
75
67
  saw.y += saw.velocity_y * saw.factor_y
76
68
  end
@@ -124,7 +116,7 @@ class Droid < Chingu::GameObject
124
116
 
125
117
  def die
126
118
  self.collidable = false
127
- @color = Color::RED
119
+ @color = Color::RED.dup
128
120
  between(1,600) { self.velocity_y = 0; self.scale += 0.2; self.alpha -= 5; }.then { resurrect }
129
121
  end
130
122
 
@@ -132,7 +124,7 @@ class Droid < Chingu::GameObject
132
124
  self.alpha = 255
133
125
  self.factor = 3
134
126
  self.collidable = true
135
- @color = Color::WHITE
127
+ @color = Color::WHITE.dup
136
128
  game_state.restore_player_position
137
129
  end
138
130
 
@@ -157,8 +157,6 @@ class Level < Chingu::GameState
157
157
  #
158
158
  def setup
159
159
  # Destroy all created objects of class Bullet
160
- #p Bullet.size
161
- #puts Bullet.all
162
160
  Bullet.destroy_all
163
161
 
164
162
  # Place player in a good starting position
@@ -124,7 +124,7 @@ class Particles < Chingu::GameState
124
124
  :mode => :additive
125
125
  )
126
126
 
127
- Particle.all.each { |particle| particle.y -= 5; particle.x += 2 - rand(4) }
127
+ Particle.each { |particle| particle.y -= 5; particle.x += 2 - rand(4) }
128
128
  game_objects.destroy_if { |object| object.outside_window? || object.color.alpha == 0 }
129
129
  super
130
130
  end
@@ -63,9 +63,8 @@ class Particles < Chingu::GameState
63
63
  Plasma.create(:x => 0, :y => 50 + rand(5), :color => Color.new(0xFF86EFFF), :velocity_x => 14)
64
64
  Plasma.create(:x => 0, :y => 100 + rand(5), :color => Color.new(0xFF86EFFF), :velocity_x => 7)
65
65
  Plasma.create(:x => 0, :y => 200 + rand(5), :color => Color.new(0xFF86EFFF), :velocity_x => 6)
66
- #p pl.mode
67
66
 
68
- Plasma.all.each do |particle|
67
+ Plasma.each do |particle|
69
68
  #
70
69
  # +1 fps
71
70
  #
@@ -62,7 +62,7 @@ class ParticleState < Chingu::GameState
62
62
  def update
63
63
  super
64
64
 
65
- FireCube.all.each do |particle|
65
+ FireCube.each do |particle|
66
66
  if particle.x < 0 || particle.x > $window.width
67
67
  particle.velocity_x = -particle.velocity_x
68
68
  end