Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: a24be0d4cfda87a435d1bc796a351e276798293d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* 	ship.cc
	This file is part of the Osirion project
*/

// C++ headers
#include <iostream>

// project headers
#include "common/functions.h"
#include "common/osirion.h"

#include "ship.h"

Ship::Ship()
{
	speed = 0;
	yaw = 0;
	yaw_offset = 0;

	thrust = 0;
	
	// ship specs
	acceleration = 6 * GAMESCALE;
	max_speed = 16.0f * GAMESCALE;
	
	max_yaw_offset = 45;
	yaw_speed = 4;
}

Ship::~Ship() 
{
}

void Ship::update(float elapsed) 
{
	// update yaw
	float d = yaw_speed * elapsed * yaw_offset;
	yaw_offset -= d;
	yaw +=d;

	// update thrust
	if (speed < thrust * max_speed) {
		speed += acceleration * elapsed;
		if (speed > thrust * max_speed) {
			speed = thrust * max_speed;
		}
	} else if(speed > thrust * max_speed) {
		speed -= acceleration * elapsed;
		if (speed < 0) speed = 0;
	}

	// location TODO avoid sin/cos calculations
	location.x += cosf(yaw * M_PI / 180) * speed * elapsed;
	location.z -= sinf(yaw * M_PI / 180) * speed * elapsed;
}


void Ship::thrust_increase()
{
	thrust += 0.05;
	if (thrust > 1) thrust = 1;
}

void Ship::thrust_decrease()
{
	thrust -= 0.08;
	if (thrust < 0) thrust = 0;
}

void Ship::turn_left() 
{
	//yaw = degreesf(yaw + 2);
	yaw_offset += 2;
	if (yaw_offset > max_yaw_offset)
		yaw_offset = max_yaw_offset;
}

void Ship::turn_right() 
{
	//yaw = degreesf(yaw - 2);
	yaw_offset -= 2;
	if (yaw_offset < -max_yaw_offset)
		yaw_offset = - max_yaw_offset;
}