Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2100 was 2096, checked in by chris, 21 years ago

orxonox/branches/chris: Messed with the Player class, added stuff here and there, debug world now creates a player and bind IO to it. Added some doxygen tags.

File size: 2.1 KB
RevLine 
[1853]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.
[1872]12
13   ### File Specific:
14   main-programmer: Patrick Boenzli
[2096]15   co-programmer: Christian Meyer
[1853]16*/
17
[1858]18#include <iostream>
[1920]19#include <stdlib.h>
[2058]20#include <GL/glut.h>
[1853]21
[2058]22#include "player.h"
23
[1856]24using namespace std;
[1853]25
26
[2096]27Player::Player(bool isFree) : WorldEntity(isFree)
28{
[1872]29}
[1853]30
[1896]31Player::~Player () 
32{
33}
[1853]34
[2096]35void Player::post_spawn ()
36{
37        travel_speed = 1.0;
38        velocity = Vector();
39        bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
40        bFire = false;
41        acceleration = 10.0;
42        set_collision (new CollisionCluster (1.0, Vector(0,0,0));
43}
[1853]44
[2096]45void Player::tick (float time)
[1858]46{
[2096]47        // movement
48        move (float time);
[1858]49}
50
[2096]51void Player::hit (WorldEntity* weapon, Vector loc)
52{
53}
[1896]54
[2096]55void Player::destroy ()
[1872]56{
57}
[1858]58
[2096]59void Player::collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags)
[1900]60{
61}
62
[2096]63void Player::command (Command* cmd)
[1872]64{
[2096]65        if( strcmp( cmd->cmd, "up")) bUp = !cmd->bUp;
66        else if( strcmp( cmd->cmd, "down")) bDown = !cmd->bUp;
67        else if( strcmp( cmd->cmd, "left")) bLeft = !cmd->bUp;
68        else if( strcmp( cmd->cmd, "right")) bRight = !cmd->bUp;
69        else if( strcmp( cmd->cmd, "fire")) bFire = !cmd->bUp;
[1872]70}
71
[2096]72void Player::draw ()
[1872]73{
74}
75
[2096]76void Player::get_lookat (Location* locbuf)
[1872]77{
[2096]78        *locbuf = *get_location();
79        locbuf->dist += 5.0;
[1872]80}
81
[2096]82void Player::left_world ()
[1896]83{
[1872]84}
85
[2096]86void Player::move (float time)
[1858]87{
[2096]88        float xAccel, yAccel, zAccel;
89        xAccel = yAccel = zAccel = 0;
90        if( bUp) xAccel += acceleration;
91        if( bDown) xAccel -= acceleration;
92        if( bLeft) yAccel += acceleration;
93        if( bRight) yAccel -= acceleration;
94        if( bAscend) zAccel += acceleration;
95        if( bDescend) zAccel -= acceleration;
96       
97        Vector accel( xAccel, yAccel, zAccel);
98       
99        Location* l = get_location();
100       
101        // r(t) = r(0) + v(0)*t + 1/2*a*t^2
102        // r = position
103        // v = velocity
104        // a = acceleration
105       
106        l->pos = l->pos + velocity*time + (accel*(0.5*t*t)));
107        l->dist += travel_speed * time;
108       
109        velocity += accel * time;
[1896]110}
[1879]111
112
[1896]113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
Note: See TracBrowser for help on using the repository browser.