[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 | |
---|
[2058] | 18 | #include "player.h" |
---|
[2101] | 19 | #include "stdincl.h" |
---|
| 20 | #include "collision.h" |
---|
[2058] | 21 | |
---|
[1856] | 22 | using namespace std; |
---|
[1853] | 23 | |
---|
| 24 | |
---|
[2096] | 25 | Player::Player(bool isFree) : WorldEntity(isFree) |
---|
| 26 | { |
---|
[1872] | 27 | } |
---|
[1853] | 28 | |
---|
[1896] | 29 | Player::~Player () |
---|
| 30 | { |
---|
| 31 | } |
---|
[1853] | 32 | |
---|
[2096] | 33 | void Player::post_spawn () |
---|
| 34 | { |
---|
[2112] | 35 | travel_speed = 10.0; |
---|
[2096] | 36 | velocity = Vector(); |
---|
| 37 | bUp = bDown = bLeft = bRight = bAscend = bDescend = false; |
---|
| 38 | bFire = false; |
---|
| 39 | acceleration = 10.0; |
---|
[2101] | 40 | set_collision (new CollisionCluster (1.0, Vector(0,0,0))); |
---|
[2096] | 41 | } |
---|
[1853] | 42 | |
---|
[2096] | 43 | void Player::tick (float time) |
---|
[1858] | 44 | { |
---|
[2096] | 45 | // movement |
---|
[2101] | 46 | move (time); |
---|
[1858] | 47 | } |
---|
| 48 | |
---|
[2096] | 49 | void Player::hit (WorldEntity* weapon, Vector loc) |
---|
| 50 | { |
---|
| 51 | } |
---|
[1896] | 52 | |
---|
[2096] | 53 | void Player::destroy () |
---|
[1872] | 54 | { |
---|
| 55 | } |
---|
[1858] | 56 | |
---|
[2096] | 57 | void Player::collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags) |
---|
[1900] | 58 | { |
---|
| 59 | } |
---|
| 60 | |
---|
[2096] | 61 | void Player::command (Command* cmd) |
---|
[1872] | 62 | { |
---|
[2115] | 63 | printf("Player|recieved command [%s]\n", cmd->cmd); |
---|
[2105] | 64 | if( !strcmp( cmd->cmd, "up")) bUp = !cmd->bUp; |
---|
| 65 | else if( !strcmp( cmd->cmd, "down")) bDown = !cmd->bUp; |
---|
| 66 | else if( !strcmp( cmd->cmd, "left")) bLeft = !cmd->bUp; |
---|
| 67 | else if( !strcmp( cmd->cmd, "right")) bRight = !cmd->bUp; |
---|
| 68 | else if( !strcmp( cmd->cmd, "fire")) bFire = !cmd->bUp; |
---|
[1872] | 69 | } |
---|
| 70 | |
---|
[2096] | 71 | void Player::draw () |
---|
[1872] | 72 | { |
---|
[2105] | 73 | glMatrixMode(GL_MODELVIEW); |
---|
[2115] | 74 | glLoadIdentity(); |
---|
[2112] | 75 | float matrix[4][4]; |
---|
[2105] | 76 | |
---|
| 77 | glTranslatef(get_placement()->r.x,get_placement()->r.y,get_placement()->r.z); |
---|
[2115] | 78 | get_placement()->w.matrix (matrix); |
---|
| 79 | glMultMatrixf ((float*)matrix); |
---|
[2105] | 80 | |
---|
| 81 | glBegin(GL_TRIANGLES); |
---|
| 82 | glColor3f(1,0,0); |
---|
[2115] | 83 | glVertex3f(0,0,0.5); |
---|
[2105] | 84 | glColor3f(0,1,0); |
---|
[2115] | 85 | glVertex3f(-0.5,0,-1); |
---|
[2105] | 86 | glColor3f(0,0,1); |
---|
[2115] | 87 | glVertex3f(0.5,0,-1); |
---|
[2105] | 88 | glEnd(); |
---|
[2112] | 89 | |
---|
| 90 | printf("Player@%f/%f/%f\n", get_placement()->r.x, get_placement()->r.y, get_placement()->r.z); |
---|
[1872] | 91 | } |
---|
| 92 | |
---|
[2096] | 93 | void Player::get_lookat (Location* locbuf) |
---|
[1872] | 94 | { |
---|
[2096] | 95 | *locbuf = *get_location(); |
---|
[2112] | 96 | //locbuf->dist += 5.0; |
---|
[1872] | 97 | } |
---|
| 98 | |
---|
[2096] | 99 | void Player::left_world () |
---|
[1896] | 100 | { |
---|
[1872] | 101 | } |
---|
| 102 | |
---|
[2096] | 103 | void Player::move (float time) |
---|
[1858] | 104 | { |
---|
[2096] | 105 | float xAccel, yAccel, zAccel; |
---|
| 106 | xAccel = yAccel = zAccel = 0; |
---|
| 107 | if( bUp) xAccel += acceleration; |
---|
| 108 | if( bDown) xAccel -= acceleration; |
---|
| 109 | if( bLeft) yAccel += acceleration; |
---|
| 110 | if( bRight) yAccel -= acceleration; |
---|
| 111 | if( bAscend) zAccel += acceleration; |
---|
| 112 | if( bDescend) zAccel -= acceleration; |
---|
| 113 | |
---|
| 114 | Vector accel( xAccel, yAccel, zAccel); |
---|
| 115 | |
---|
| 116 | Location* l = get_location(); |
---|
| 117 | |
---|
| 118 | // r(t) = r(0) + v(0)*t + 1/2*a*t^2 |
---|
| 119 | // r = position |
---|
| 120 | // v = velocity |
---|
| 121 | // a = acceleration |
---|
| 122 | |
---|
[2101] | 123 | l->pos = l->pos + velocity*time + (accel*(0.5*time*time)); |
---|
[2096] | 124 | l->dist += travel_speed * time; |
---|
| 125 | |
---|
[2101] | 126 | velocity = velocity + (accel * time); |
---|
[2115] | 127 | printf("Player|velocity %f/%f/%f\n", velocity.x, velocity.y, velocity.z); |
---|
[1896] | 128 | } |
---|
[1879] | 129 | |
---|
| 130 | |
---|
[1896] | 131 | |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | |
---|
| 141 | |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | |
---|
| 146 | |
---|