Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 55 lines (46 sloc) 1.291 kb
1b1eb3c @TomK32 Initial import:
TomK32 authored
1 #
2 # Movable.rb
3 # CtF
4 #
5 # Created by Thomas R. Koll on 10.12.10.
6 # Copyright (c) 2010 ananasblau. All rights reserved.
7 #
8
9 module Movable
10 attr_accessor :speed, :turns, :last_turn, :orientation
11 MIN_SPEED = 2
12 MAX_SPEED = 10
13 MAX_TURN = 5
14 SPEED_FACTOR = 0.001
15
16 def turns_sum
17 self.turns = self.turns[0..(MAX_TURN*3)]
18 return (self.turns||[]).inject {|sum, i| sum + i}
19 end
90d5b9a @beanieboi code style
beanieboi authored
20
1b1eb3c @TomK32 Initial import:
TomK32 authored
21 def turn(val)
22 self.turns.unshift(val)
23 self.last_turn = self.turns_sum.abs > 1 ? val : 0
5f6e710 @TomK32 Making camera angle variable
TomK32 authored
24 old_orientation = self.orientation
1b1eb3c @TomK32 Initial import:
TomK32 authored
25 self.orientation = (self.orientation + self.turns_sum) % 360
5f6e710 @TomK32 Making camera angle variable
TomK32 authored
26 return self.orientation - old_orientation
1b1eb3c @TomK32 Initial import:
TomK32 authored
27 end
d6ec795 @beanieboi code style
beanieboi authored
28
1b1eb3c @TomK32 Initial import:
TomK32 authored
29 def speedUp(val)
30 self.speed = [[self.speed + val, MAX_SPEED].min, MIN_SPEED].max
31 end
d6ec795 @beanieboi code style
beanieboi authored
32
e009321 @TomK32 Refactoring into Visibility
TomK32 authored
33 def radians(angle)
34 (angle * Math::PI / 180) || 0
1b1eb3c @TomK32 Initial import:
TomK32 authored
35 end
36
e1d1fbf @beanieboi added camera orientation
beanieboi authored
37 def camera_orientation
38 (orientation - 90) % 360
39 end
40
1b1eb3c @TomK32 Initial import:
TomK32 authored
41 def move(turn = nil)
42 # First of all rotate
43 glRotatef(self.orientation, 0, 0, 1)
44
45 # Move x and y coords
95e9533 @TomK32 Adding Shot
TomK32 authored
46 if self.turns
47 self.turn(turn || self.last_turn || 0)
48 self.turns.shift if turn.nil?
49 self.turns.unshift(0)
50 end
e009321 @TomK32 Refactoring into Visibility
TomK32 authored
51 self.x += Math.cos(self.radians(self.orientation)) * self.speed * SPEED_FACTOR
52 self.y += Math.sin(self.radians(self.orientation)) * self.speed * SPEED_FACTOR
1b1eb3c @TomK32 Initial import:
TomK32 authored
53 end
54 end
Something went wrong with that request. Please try again.