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