Permalink
Browse files

Adding Shot

  • Loading branch information...
1 parent f5319e5 commit 95e9533df77eec708a04520b4bcc07c24ca6f674 @TomK32 TomK32 committed Dec 12, 2010
Showing with 69 additions and 8 deletions.
  1. +10 −4 Enemy.rb
  2. +6 −1 GameLoop.rb
  3. +5 −3 Movable.rb
  4. +44 −0 Shot.rb
  5. +4 −0 The Flying Camera.xcodeproj/project.pbxproj
View
@@ -15,7 +15,7 @@ class Enemy
include Visibility
- attr_accessor :team, :view_angle
+ attr_accessor :team, :view_angle, :shots
def initialize(team)
self.team = team
@@ -24,6 +24,7 @@ def initialize(team)
self.orientation = rand(360)
self.speed = 2
self.turns = []
+ self.shots = []
self.view_width = 40
self.view_angle = [self.orientation + view_width / 2.0, self.orientation - view_width / 2.0]
end
@@ -35,8 +36,8 @@ def redraw(tick)
colour
Plane.draw
self.draw
-
glPopMatrix
+ self.shots = self.shots.map(&:redraw).compact
end
def colour
@@ -103,11 +104,16 @@ def circle(radius, segments = 20)
def find_target(enemies)
self.speedUp(rand * 2 - 1)
+ # right
enemy_to_follow = self.objects_in_view(enemies).first
if enemy_to_follow.nil?
- self.turn(rand(self.turns_sum||1) * (rand -0.5))
+ self.turn(rand(self.turns_sum||1) * (rand - 0.5))
else
- a = - [[(self.orientation - enemy_to_follow[1]) / self.view_width.to_f, 0.5].min, -0.5].max
+ if self.shots.size < 20
+ puts enemy_to_follow[1]
+ self.shots << Shot.new(self.x, self.y, (self.orientation - enemy_to_follow[1]) % 360)
+ end
+ a = - [[(self.orientation - enemy_to_follow[1]) / self.view_width.to_f, 0.5].min, -0.5].max
self.turn(a)
end
end
View
@@ -7,7 +7,8 @@
#
class GameLoop
- attr_accessor :view, :timer, :player, :elements, :scene, :teams, :stop
+ attr_accessor :view
+ attr_accessor :timer, :player, :elements, :scene, :teams, :stop, :shots
def initialize(view)
self.view = view
@@ -63,5 +64,9 @@ def set_viewport_rectangle(bounds)
glMatrixMode(GL_PROJECTION)
glLoadIdentity
gluPerspective(30, bounds.size.width / bounds.size.height, 1.0, 1000.0)
+
+# glMatrixMode(GL_MODELVIEW)
+# glLoadIdentity
+
end
end
View
@@ -43,9 +43,11 @@ def move(turn = nil)
glRotatef(self.orientation, 0, 0, 1)
# Move x and y coords
- self.turn(turn || self.last_turn || 0)
- self.turns.shift if turn.nil?
- self.turns.unshift(0)
+ if self.turns
+ self.turn(turn || self.last_turn || 0)
+ self.turns.shift if turn.nil?
+ self.turns.unshift(0)
+ end
self.x += Math.cos(self.radians(self.orientation)) * self.speed * SPEED_FACTOR
self.y += Math.sin(self.radians(self.orientation)) * self.speed * SPEED_FACTOR
end
View
44 Shot.rb
@@ -0,0 +1,44 @@
+#
+# Shot.rb
+# The Flying Camera
+#
+# Created by Thomas R. Koll on 12.12.10.
+# Copyright (c) 2010 ananasblau. All rights reserved.
+#
+
+class Shot
+ include Movable
+ include Placable
+
+ attr_accessor :x, :y, :orientation
+
+
+ def initialize(x,y,orientation)
+ self.x = x
+ self.y = y
+ self.z = 0
+ self.speed = 10
+ self.orientation = orientation
+ end
+
+ def redraw
+ glPushMatrix
+
+ # shot is leaving view field
+ out_of_view = self.x > 1 || self.x < -1 || self.y > 1 || self.y < -1
+
+ place
+ self.move(0)
+ glColor3f(1,1,1)
+ glBegin(GL_QUADS)
+ glVertex3f( 0.0, 0.0, 0.0);
+ glVertex3f( 0.0, 0.002, 0.0);
+ glVertex3f(-0.002, 0.002, 0.0);
+ glVertex3f(-0.002, 0.0, 0.0);
+ glVertex3f( 0.0, 0.0, 0.0);
+ glEnd
+ glPopMatrix
+ return nil if out_of_view
+ return self
+ end
+end
@@ -49,6 +49,7 @@
0EB704E312B39CC2006FF01B /* Visibility.rb in Resources */ = {isa = PBXBuildFile; fileRef = 0EB704E212B39CC2006FF01B /* Visibility.rb */; };
0EB706C812B3B10C006FF01B /* README in Resources */ = {isa = PBXBuildFile; fileRef = 0EB706C712B3B10C006FF01B /* README */; };
0ED0536812B535330095EAC6 /* Score.rb in Resources */ = {isa = PBXBuildFile; fileRef = 0ED0536712B535330095EAC6 /* Score.rb */; };
+ 0ED4F78D12B557E60064E48A /* Shot.rb in Resources */ = {isa = PBXBuildFile; fileRef = 0ED4F78C12B557E60064E48A /* Shot.rb */; };
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 */; };
@@ -87,6 +88,7 @@
0EB704E212B39CC2006FF01B /* Visibility.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = Visibility.rb; sourceTree = "<group>"; };
0EB706C712B3B10C006FF01B /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
0ED0536712B535330095EAC6 /* Score.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = Score.rb; sourceTree = "<group>"; };
+ 0ED4F78C12B557E60064E48A /* Shot.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = Shot.rb; sourceTree = "<group>"; };
0ED8FB4112B24A0700296022 /* Movable.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = Movable.rb; sourceTree = "<group>"; };
0ED8FB9512B24C6100296022 /* Plane.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = Plane.rb; sourceTree = "<group>"; };
0ED8FBAC12B24FAF00296022 /* Enemy.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = Enemy.rb; sourceTree = "<group>"; };
@@ -159,6 +161,7 @@
0EF05DB512B17440009C18E8 /* Placable.rb */,
0ED8FB9512B24C6100296022 /* Plane.rb */,
0EB704E212B39CC2006FF01B /* Visibility.rb */,
+ 0ED4F78C12B557E60064E48A /* Shot.rb */,
);
name = lib;
sourceTree = "<group>";
@@ -316,6 +319,7 @@
0EB706C812B3B10C006FF01B /* README in Resources */,
0E319B1312B3D2AC00D0E514 /* Fullscreen.rb in Resources */,
0ED0536812B535330095EAC6 /* Score.rb in Resources */,
+ 0ED4F78D12B557E60064E48A /* Shot.rb in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

0 comments on commit 95e9533

Please sign in to comment.