Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/chris/src/player.cc @ 2101

Last change on this file since 2101 was 2101, checked in by chris, 20 years ago

orxonox/branches/chris: Finished the "GETITTOCOMPILE" project… compiling should work now, but linking is a different story

File size: 2.1 KB
Line 
1
2
3/*
4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   ### File Specific:
14   main-programmer: Patrick Boenzli
15   co-programmer: Christian Meyer
16*/
17
18#include "player.h"
19#include "stdincl.h"
20#include "collision.h"
21
22using namespace std;
23
24
25Player::Player(bool isFree) : WorldEntity(isFree)
26{
27}
28
29Player::~Player () 
30{
31}
32
33void Player::post_spawn ()
34{
35        travel_speed = 1.0;
36        velocity = Vector();
37        bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
38        bFire = false;
39        acceleration = 10.0;
40        set_collision (new CollisionCluster (1.0, Vector(0,0,0)));
41}
42
43void Player::tick (float time)
44{
45        // movement
46        move (time);
47}
48
49void Player::hit (WorldEntity* weapon, Vector loc)
50{
51}
52
53void Player::destroy ()
54{
55}
56
57void Player::collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags)
58{
59}
60
61void Player::command (Command* cmd)
62{
63        if( strcmp( cmd->cmd, "up")) bUp = !cmd->bUp;
64        else if( strcmp( cmd->cmd, "down")) bDown = !cmd->bUp;
65        else if( strcmp( cmd->cmd, "left")) bLeft = !cmd->bUp;
66        else if( strcmp( cmd->cmd, "right")) bRight = !cmd->bUp;
67        else if( strcmp( cmd->cmd, "fire")) bFire = !cmd->bUp;
68}
69
70void Player::draw ()
71{
72}
73
74void Player::get_lookat (Location* locbuf)
75{
76        *locbuf = *get_location();
77        locbuf->dist += 5.0;
78}
79
80void Player::left_world ()
81{
82}
83
84void Player::move (float time)
85{
86        float xAccel, yAccel, zAccel;
87        xAccel = yAccel = zAccel = 0;
88        if( bUp) xAccel += acceleration;
89        if( bDown) xAccel -= acceleration;
90        if( bLeft) yAccel += acceleration;
91        if( bRight) yAccel -= acceleration;
92        if( bAscend) zAccel += acceleration;
93        if( bDescend) zAccel -= acceleration;
94       
95        Vector accel( xAccel, yAccel, zAccel);
96       
97        Location* l = get_location();
98       
99        // r(t) = r(0) + v(0)*t + 1/2*a*t^2
100        // r = position
101        // v = velocity
102        // a = acceleration
103       
104        l->pos = l->pos + velocity*time + (accel*(0.5*time*time));
105        l->dist += travel_speed * time;
106       
107        velocity = velocity + (accel * time);
108}
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
Note: See TracBrowser for help on using the repository browser.