From 7696ff977344c1f5e3b2fcf9be4ac536c346afb7 Mon Sep 17 00:00:00 2001 From: indigoapples Date: Mon, 9 Sep 2024 21:08:24 -0400 Subject: [PATCH] bullets --- indigogameone/.DS_Store | Bin 0 -> 6148 bytes indigogameone/project.godot | 13 +++++ indigogameone/scenes/bullets.tscn | 16 ++++++ indigogameone/scenes/game.tscn | 33 +++++-------- indigogameone/scenes/player.tscn | 25 ++++++++++ indigogameone/scripts/bullet.gd | 18 +++++++ indigogameone/scripts/player.gd | 79 ++++++++++++++++++++++++++++-- 7 files changed, 161 insertions(+), 23 deletions(-) create mode 100644 indigogameone/.DS_Store create mode 100644 indigogameone/scenes/bullets.tscn create mode 100644 indigogameone/scenes/player.tscn create mode 100644 indigogameone/scripts/bullet.gd diff --git a/indigogameone/.DS_Store b/indigogameone/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..d1da8a42a8a8b4dbfbbe2aaeb199c9eba7516ad2 GIT binary patch literal 6148 zcmeHKL2uJA6n^f?>S~(k0i<1!B5|EYx1vdiOIF5V*9E}=P-&W~1Twoy()CbP${BtP zSANO<3n%tH+e2+SI3mRSr036meqS7aPU4t|M1PhX5_O13!WkQF6t@`nvu{|#MOr{% zu5myGUDD(%)1!@SANUs);I)&K(ug!ET3Nq1(=qz^!8m~*{4|Cd(fxWpcqv`b6xYb9 zXa)o~{vC3SO*_BEJ49H=Y+$cSqmjX_gjc zw|gZTTg`jhE!mPg@_qDC&!ci!&Wippf6J{`T4(W1eHgz^$MZqw!3(X*VXDTtA*9I| zDevB-D$(=4o~fiT+{kvwwrmeNdyBkI z3}NYr2QDvkSXs1m67KLJ+{nV6P=pyB*AGlOiO`}iy#ii=bp^I;v%~xU%io{>*GazR z74QoDR|<&cX>{7hl-%CBF*)9A1Na9x8|PIPe^F2|TQPEZE8c?}Lp void: + position += transform.x * speed * delta + #we directly manipulating that transform but only on the x.. then we are multiplying it by speed and this physics process func will be called over and over again ..delta is the amt of time that has passed between physics process being called.. it's our fps basically..so person on low frame rate will move a bit farther.. variance between frame rates.. + + + +func _on_body_entered(body: Node2D) -> void: + print("I done some hittin") diff --git a/indigogameone/scripts/player.gd b/indigogameone/scripts/player.gd index 13ed12d..1bfc99b 100644 --- a/indigogameone/scripts/player.gd +++ b/indigogameone/scripts/player.gd @@ -3,6 +3,22 @@ extends CharacterBody2D const SPEED = 300.0 const JUMP_VELOCITY = -400.0 +const PUSH_FORCE = 700 + +var faceLeft = false +#can i push right or left +var pushLeftEnabled = false +var pushRightEnabled = false +@onready var right_ray: RayCast2D = $RightRay #wait for one full game tick to happen before you boot this up +@onready var left_ray: RayCast2D = $LeftRay +@onready var marker_right: Node2D = $MarkerRight +@onready var marker_left: Node2D = $MarkerLeft + + +var pushTarget +#what we are leveraging our pushforce against +var bullet = preload("res://scenes/bullets.tscn") #how we make with code any of the scenes we created +#goes into resources and goes to bullet and puts on standby. ready to make the bullet.. func _physics_process(delta: float) -> void: @@ -13,19 +29,76 @@ func _physics_process(delta: float) -> void: # Handle jump. if Input.is_action_just_pressed("ui_accept") and is_on_floor(): velocity.y = JUMP_VELOCITY + + if Input.is_action_just_pressed("Shove") && pushLeftEnabled && faceLeft: + print("shove a box on the left") + pushTarget.apply_central_impulse(Vector2(-1,0) * PUSH_FORCE * 1.5) #-1 in game grid is left direction + pushLeftEnabled = false + + + if Input.is_action_just_pressed("Shove") && pushRightEnabled && not faceLeft: + print("shove a box on the right") + pushTarget.apply_central_impulse(Vector2(1,0) * PUSH_FORCE * 1.5) #1 is right direction + pushRightEnabled = false + + if Input.is_action_just_pressed("shoot"): + print("I will shoot") + var mybullet = bullet.instantiate() #will make bullet but won't position or put bullet on screen + if faceLeft: + print("shoot left") + mybullet.setSpeed(-700) + mybullet.transform = marker_left.global_transform + else: + print("shoot right") + #position bullet + mybullet.transform = marker_right.global_transform #saying give me global coordinates for .. + #put bullet on screen + owner.add_child(mybullet) #adds bullet when facing both directions + # Get the input direction and handle the movement/deceleration. # As good practice, you should replace UI actions with custom gameplay actions. - var direction := Input.get_axis("ui_left", "ui_right") + var direction := Input.get_axis("ui_left", "ui_right") + #code tells us whether we are facing left or right + if direction <0: + faceLeft = true + if direction >0: + faceLeft = false if direction: velocity.x = direction * SPEED else: velocity.x = move_toward(velocity.x, 0, SPEED) - - move_and_slide() +#blue text is part of the engine!!!! + move_and_slide() #this is where all the collisions are recorded for i in get_slide_collision_count(): var c = get_slide_collision(i) if c.get_collider() is RigidBody2D: #checking if its a crate c.get_collider().apply_central_impulse(-c.get_normal()*100) #i is gonna be increased by one by every colision as I move + if left_ray.is_colliding(): #tells if leftray has something hitting it + print("left ray collision") + var collider = left_ray.get_collider() #get me what it is colliding with on left + if collider is Node: #might not be game object like light, camera... + if collider.is_in_group("pushables"): + pushLeftEnabled = true + pushTarget = collider + else: + #do something else + pushLeftEnabled = false + + + + + if right_ray.is_colliding(): + print("right ray collision") + var collider = right_ray.get_collider() + if collider is Node: + if collider.is_in_group("pushables"): + pushRightEnabled = true + pushTarget = collider + + else: + pushRightEnabled = false + +