# # This script defines the player entity # func Player:constructor {ent type} { set global player $ent set global player-firstperson 0 set global player-rotation 0 set global player-lookrot 0 set global player-rotspeed 0 set global player-turnmul 1 set global player-movexmul 1 set global player-moveymul 1 camera-chase $player 128 camera-offset 0 16 0 entity-model $ent [get-model rob.rtm] entity-cspheres $ent {{0 12 0 12} {0 -12 0 12}} entity-blocking $ent 1 {{-1 0 -1} {1 0 1}} capture mouse 1 } func toggle-perspective {v} { if not $v return if $player-firstperson { set global player-firstperson 0 set global player-lookrot 0 camera-chase $player 128 camera-smooth 0.2 entity-visible $player 1 entity-rotation $player yxz 0 $player-rotation 0 } { set global player-firstperson 1 camera-fpp $player entity-visible $player 0 } } func key:t {v} { if not $v return eset $player stop-light [expr ![eget $player stop-light]] } func toggle-flashlight {v} { if not $v return local light set light [eget $player light] if $light { dlight-remove $light eset $player light {} } { set light [dlight-new spot] dlight-radius $light 768 dlight-inner-radius $light 600 dlight-shadow $light 1 dlight-color $light {1.3 1.0 0.9} eset $player light $light eset $player stop-light 0 } } foreach {forward backward strafe-left strafe-right turn-left turn-right} { func $i {v} "set global go-$i \$v" } func turn {delta} { if not $player return set global player-rotation [expr $player-rotation - $delta * 0.0035 * $turnspeed ] entity-rotation $player yxz $player-lookrot $player-rotation 0 if $player-firstperson { camera-smooth 1 } } func look {delta} { if $player-firstperson { set global player-lookrot [expr $player-lookrot + $delta * 0.0035 * $turnspeed ] if [expr $player-lookrot < -1.55] { set global player-lookrot -1.55 } if [expr $player-lookrot > 1.55] { set global player-lookrot 1.55 } entity-rotation $player yxz $player-lookrot $player-rotation 0 } { set global player-lookrot 0 } } func joy-turn {delta} { set delta [expr $delta / 32000.0] set global go-turn-left 0 set global go-turn-right 0 set global player-turnmul 1 if [expr $delta > 0.25] { set global player-turnmul $delta set global go-turn-right 1 } if [expr $delta < -0.25] { set global player-turnmul [expr - $delta] set global go-turn-left 1 } } func joy-look {delta} { set delta [expr $delta / 2400.0] if [expr $delta > 3 || $delta < -3] { set global player-look-delta $delta } { set global player-look-delta 0 } } func joy-move {delta} { set delta [expr $delta / 30000.0] set global go-forward 0 set global go-backward 0 set global player-moveymul 1 set global player-look-forward 0 if [expr $delta > 0.25] { set global player-moveymul $delta set global go-backward 1 } if [expr $delta < -0.25] { set global player-moveymul [expr - $delta] set global go-forward 1 if [expr $player-moveymul > 0.8] { set global player-look-forward 1 } } } func joy-strafe {delta} { set delta [expr $delta / 30000.0] set global go-strafe-left 0 set global go-strafe-right 0 set global player-movexmul 1 if [expr $delta > 0.25] { set global player-movexmul $delta set global go-strafe-right 1 } if [expr $delta < -0.25] { set global player-movexmul [expr - $delta] set global go-strafe-left 1 } } updater player-updater { local doemx emx emz if $go-forward { set doemx 1 set emz $player-moveymul } if $go-backward { set doemx 1 set emz [expr - $player-moveymul] } if $go-strafe-left { set doemx 1 set emx [expr 0.7 * $player-movexmul] } if $go-strafe-right { set doemx 1 set emx [expr -0.7 * $player-movexmul] } if $doemx { entity-rotation $player yxz 0 $player-rotation 0 entity-move $player {$emx 0 $emz} 6 entity-rotation $player yxz $player-lookrot $player-rotation 0 } if $go-turn-left { if [expr $player-rotspeed < 0.15] { set global player-rotspeed [expr $player-rotspeed + 0.03 * $player-turnmul] } } if $go-turn-right { if [expr $player-rotspeed > -0.15] { set global player-rotspeed [expr $player-rotspeed - 0.03 * $player-turnmul] } } if $player-look-delta { look $player-look-delta } if $player-look-forward { set global player-lookrot [expr $player-lookrot * 0.9] } if [expr $player-rotspeed > 0.01 || $player-rotspeed < -0.01] { set global player-rotation [expr $player-rotation + $player-rotspeed] entity-rotation $player yxz $player-lookrot $player-rotation 0 set global player-rotspeed [expr $player-rotspeed * 0.65] } local light local stop-light set light [eget $player light] set stop-light [eget $player stop-light] if [streq $light {}] { set light 0 } if [streq $stop-light {}] { set stop-light 0 } if [expr $light && !$stop-light] { dlight-to-entity $light $player {0 8 6} {0 -0.5 1} } }