diff --git a/Movable.rb b/Movable.rb index 48addbf..ccd8888 100644 --- a/Movable.rb +++ b/Movable.rb @@ -21,7 +21,9 @@ def turns_sum def turn(val) self.turns.unshift(val) self.last_turn = self.turns_sum.abs > 1 ? val : 0 + old_orientation = self.orientation self.orientation = (self.orientation + self.turns_sum) % 360 + return self.orientation - old_orientation end def speedUp(val) diff --git a/Player.rb b/Player.rb index 24982cd..e130094 100644 --- a/Player.rb +++ b/Player.rb @@ -25,8 +25,8 @@ def initialize self.score = 0 self.score_history = {} - self.view_width = 55 - self.view_angle = [270 - view_width / 2, 270 + view_width / 2] + self.view_width = 70 + self.view_angle = [90 + view_width / 2, 90 - view_width / 2] end def redraw(tick) @@ -45,25 +45,24 @@ def draw_camera glBegin(GL_LINE_STRIP) glColor3f(0,0,0) - puts [radians(view_angle[0]), radians(view_angle[1])].inspect - c_x = Math.cos(radians(view_angle[0])) / 5.0 - c_y = Math.cos(radians(view_angle[1])) / 5.0 - puts [c_x, c_y].inspect + c_x = Math.cos(radians(self.orientation - view_angle[0] + 180)) / 3.0 + c_y = Math.sin(radians(self.orientation - view_angle[0] + 180)) / 3.0 glVertex2f(c_x, c_y) glColor3f(1,1,1) glVertex2f(-0.03, 0) glColor3f(0,0,0) - glVertex2f(-c_x, c_y) + c_x = Math.cos(radians(self.orientation - view_angle[1] + 180)) / 3.0 + c_y = Math.sin(radians(self.orientation - view_angle[1] + 180)) / 3.0 + glVertex2f(c_x, c_y) glEnd glPopMatrix glFlush end def turn_with_camera(direction) - orientation_before = self.orientation - self.turn_without_camera(direction) - self.view_angle[0] += orientation_before - self.orientation - self.view_angle[1] += orientation_before - self.orientation + difference = self.turn_without_camera(direction) + self.view_angle[0] = (self.view_angle[0] + difference) % 360 + self.view_angle[1] = (self.view_angle[1] + difference) % 360 end alias_method :turn_without_camera, :turn alias_method :turn, :turn_with_camera @@ -85,7 +84,7 @@ def keyDown(key) # count planes in view def make_picture(planes) - score_history.map{|k, history| score_history[k] = history[0..10] } + score_history.map{|k, history| score_history[k] = history[0..20] } # TODO set planes that are not in view to [] objects_in_view(planes).each do |hit| @@ -94,6 +93,7 @@ def make_picture(planes) self.score += score_history[hit.object_id].inject {|sum, i| sum + i} end score_history.map{|k, history| history.unshift(0); } + puts score end diff --git a/README b/README index d3059a3..c6b1452 100644 --- a/README +++ b/README @@ -3,5 +3,5 @@ The Flying Camera It's 1929 and Howard Houghes is making his movie about the Great War: Hell's Angels. You are assigned to one of the planes equipped with a camera and your mission -is to film the planes around you as they simulate their dog-fights. +is to film the planes around you as they simulate their dogfights. Capture as many scenes as you can and always keep a watch for the Red Baron! diff --git a/The Flying Camera.xcodeproj/project.pbxproj b/The Flying Camera.xcodeproj/project.pbxproj index 0d3f626..0216463 100755 --- a/The Flying Camera.xcodeproj/project.pbxproj +++ b/The Flying Camera.xcodeproj/project.pbxproj @@ -46,6 +46,7 @@ 0E2BDBC112B267D400D634EE /* Team.rb in Resources */ = {isa = PBXBuildFile; fileRef = 0E2BDBC012B267D400D634EE /* Team.rb */; }; 0E2BDC1012B26E8B00D634EE /* GLUT.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E2BDC0F12B26E8B00D634EE /* GLUT.framework */; }; 0EB704E312B39CC2006FF01B /* Visibility.rb in Resources */ = {isa = PBXBuildFile; fileRef = 0EB704E212B39CC2006FF01B /* Visibility.rb */; }; + 0EB706C812B3B10C006FF01B /* README in Resources */ = {isa = PBXBuildFile; fileRef = 0EB706C712B3B10C006FF01B /* README */; }; 0ED8FB4212B24A0700296022 /* Movable.rb in Resources */ = {isa = PBXBuildFile; fileRef = 0ED8FB4112B24A0700296022 /* Movable.rb */; }; 0ED8FB9612B24C6100296022 /* Plane.rb in Resources */ = {isa = PBXBuildFile; fileRef = 0ED8FB9512B24C6100296022 /* Plane.rb */; }; 0ED8FBAD12B24FAF00296022 /* Enemy.rb in Resources */ = {isa = PBXBuildFile; fileRef = 0ED8FBAC12B24FAF00296022 /* Enemy.rb */; }; @@ -81,6 +82,7 @@ 0E2BDBC012B267D400D634EE /* Team.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = Team.rb; sourceTree = ""; }; 0E2BDC0F12B26E8B00D634EE /* GLUT.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLUT.framework; path = System/Library/Frameworks/GLUT.framework; sourceTree = SDKROOT; }; 0EB704E212B39CC2006FF01B /* Visibility.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = Visibility.rb; sourceTree = ""; }; + 0EB706C712B3B10C006FF01B /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = ""; }; 0ED8FB4112B24A0700296022 /* Movable.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = Movable.rb; sourceTree = ""; }; 0ED8FB9512B24C6100296022 /* Plane.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = Plane.rb; sourceTree = ""; }; 0ED8FBAC12B24FAF00296022 /* Enemy.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = Enemy.rb; sourceTree = ""; }; @@ -128,6 +130,7 @@ 0EF05CB612B14A4A009C18E8 /* GameLoop.rb */, 0EF05D5F12B1703A009C18E8 /* GameWindowController.rb */, 0EF05CB112B14956009C18E8 /* GameView.rb */, + 0EB706C712B3B10C006FF01B /* README */, ); name = Classes; sourceTree = ""; @@ -304,6 +307,7 @@ 0ED8FBAD12B24FAF00296022 /* Enemy.rb in Resources */, 0E2BDBC112B267D400D634EE /* Team.rb in Resources */, 0EB704E312B39CC2006FF01B /* Visibility.rb in Resources */, + 0EB706C812B3B10C006FF01B /* README in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Visibility.rb b/Visibility.rb index 845f9e8..047a917 100644 --- a/Visibility.rb +++ b/Visibility.rb @@ -15,14 +15,15 @@ def objects_in_view(objects) if view_angle.nil? || view_angle.empty? || view_angle.size != 2 raise 'Missing view angle for %s' % self end - objects.collect do |object| + return objects.collect do |object| # nur im Rückschritt liegt die Zukunft a = self.x - object.x b = self.y - object.y + gamma = Math.atan2(b,a) - gamma = (gamma / Math::PI * 180) + 180 - puts view_angle.inspect + gamma = ((gamma / Math::PI * 180) + 180) % 360 + n = view_angle[0] m = view_angle[1] if m < n && gamma > m && gamma < n