From 49e4957c844fb32dc4937488f0e487564f1c9349 Mon Sep 17 00:00:00 2001 From: KingGurke Date: Sat, 30 Sep 2023 18:37:41 +0200 Subject: [PATCH] Added player car with janky controls and janky camera --- assets/spracer.png | Bin 0 -> 14436 bytes assets/spracer.png.import | 34 +++++++++++++++++++ project.godot | 30 +++++++++++++++- src/game/level1.tscn | 6 +++- src/game/player.tscn | 32 ++++++++++++++++++ src/game/player_controller.gd | 62 ++++++++++++++++++++++++++++++++++ 6 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 assets/spracer.png create mode 100644 assets/spracer.png.import create mode 100644 src/game/player.tscn create mode 100644 src/game/player_controller.gd diff --git a/assets/spracer.png b/assets/spracer.png new file mode 100644 index 0000000000000000000000000000000000000000..85f14b179a00830431c6aa54b94fb3498869b552 GIT binary patch literal 14436 zcmeHu2UL?w*KQD{D8+V^W>5&ANJm73fYJj3L6i;w=|w;yEmRK(M^TVB6zN6;W1$~< zRpel#DIi@yiNpYcKKZ?@QI4!Gm`n05+lq?K( zJi#xa^Q5Nn!4@_7*YU^PB_tjZ>=j-eFD~X;y=>lgXWm18p*Gc6etdBx{nUWCmDa7h zm_3_2%HLR?5E8NKeZ_*L1epk@VwIOeW|l{=)yvjCI^BAI9iNT9(A(3Lb8NJ2I-_v@ zmb>M*v0Q~boEY1+gr&W6-vSgY&GlYb+Wa#&bf3c<@yM&i?;<&zojb7f00N)+(e!0$+%=D zBC2WT^oTS>-x@L#e#d|PXhX}q0>Q75djW?Fma}lPQI!c>2K8Jn@KMa(lU5pu%j@P=J`v38DBpH{dv{JhB7rf z_*mcYtorK<8fFBA>&LE(=bO_G_V-G$CQAmsv-@LMd%0K)5a?vOcG1JycTm2|#~ zE~Ku_HKRrn$%$R1FpmBigtw&?{uWvc1!NhZM$*W4K>Iy;sP^jBtMJ+vG1XHoTjHc4 ze1=WnL710sI%3w`Du?yzTf)rRTo7s`f$X2_!eo~@BpT$>7vCw3)I~*d`T^<<&2X&) zbd3>b5~-(GEOJ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0tVLsOXD3%$CRpo)p-vaO7qc-coMFUP`Pbky?E-Auv77za@nTe4~@gY@!>-hqx zVx3^zw#l^4B2&NbrpGST+T3YqqdF;4q4U_#Nm$YsP+!7eaQFDw77fBwNy7M$0@_g+ z^HMyjUb0&um2L4O002}`w)e?}(6qENSL4y?&g<==_IV!Pf?MNEQoiQ065nPaIx*`m zW_g%X%NI&=$mo`muFPU(lD=LiQ;$=w^0)c@_#0B8|K(z2pI|OP&T; zn9E;#4maW|!1csJun>NSDgOV1w___^BDh9hGu2{b@hW>4xFifHfJn?}ZCLPgfqU}a z+2l}Eeen1=?A(ERWm0fWSV+y?&GY=bL0^LcxHUEGof8Q==P;8^76!OP^4*PNVgiht z^k^tROvy!<8FsFz12vxoTE=c|G7VAaoB-!cCf`J51wY)n2;;eziLxD891j)?+63^8 zPu8eP-x0>VNo3A_Zm|1(3s7x6SaaJ#x-&zc*<>;^3a&`8gEjVy<3ox7%9XjO*me+1 zsU}Kd#ShbWvNFT+X0pf{0E41QG_2fb{B;0vszoh{+>Y`pi}(nOa5EVlUL1Gvrw3kt zjtT5R2han}pcK&{QgPT3n2&n7$Z9@9`s>JaKI$n9;ym=1qurh)O0QUeZF^z&OFbUfRNE09= zhIBnhBlj`b8(;1L7^RMD06fWYjE~#@;iD=Cw0-{wO67owJ2OJ+?>;8t021?$4<|VQ z&g6UlCm+fT=;r%J3JLb$N_joNYyR$Ih5_V!|F9Kh{za{SYWbfk`0uCDf3VxXse-*j zj9B=m%P0QMpZ~QNH!pI*i2a1G7Hvls%^($J(x~)U=Z*-cfMtZVo^J=sR))q<>74SU zn&G?&1AgV-z``EU@1RMo<@57$!E_mzCSJww z>&#j%$}9X1CTv)Fa#Y_}8VqZ;^q8uX`>Y?I%g20!x?>RT86e8sOC%0c!-9 zuwW7Z`iJL=wkB faster turns +@export var turn_speed := 1. +## affects how fast the brakes, higher value -> quicker to stand still +@export var brake_strength := 30. +## regulates how much more you can turn while breaking, values below 1 mean you can turn worse while drifting +@export var drift_factor := 1.5 +## regulates how far the camera looks ahead of the player (affected by speed) +@export var camera_offset_factor = 20. + +# references +@export var camera : Camera2D + +# variables +var momentum: Vector2 + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + var acc_d = acc * delta + var dec_d = dec * delta + var turn_d = turn_speed * delta + var brake_d = brake_strength * delta + var turn_factor = 1 + + if momentum.length() > dec_d: + momentum -= momentum.normalized()*dec_d + else: + momentum = Vector2(0,0) + + if Input.is_action_pressed("accelerate"): + momentum += acc_d * Vector2(1,0).rotated(rotation) + + if Input.is_action_pressed("brake"): + turn_factor = drift_factor + if momentum.length() > brake_d: + momentum -= momentum.normalized() * brake_d + else: + momentum = Vector2(0,0) + + if Input.is_action_pressed("left"): + rotate(turn_d*turn_factor*-1) + if Input.is_action_pressed("right"): + rotate(turn_d*turn_factor) + + camera.position = Vector2(momentum.length() * camera_offset_factor, 0) + camera.rotation_degrees = momentum.angle() + 90 + + if momentum.length() > max_speed: + momentum = momentum.normalized() * max_speed + move_and_collide(momentum)