Added changes from week 2 videoa

This commit is contained in:
KevinGorman committed 2025-01-19 21:04:07 -05:00
1 parent 90bdd35020
commit 3b09af598b
7 files changed
+156 -29

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
extends Area2D
@export var speed := 700
signal hit(bullet, body)
func set_speed(speedval):
speed = speedval
func _physics_process(delta):
position += transform.x * speed * delta
func _on_body_entered(body):
print ("Hit a thing") # Replace with function body.
+69 -2
View File
@@ -3,7 +3,21 @@ extends CharacterBody2D
const SPEED = 500.0
const JUMP_VELOCITY = -600.0
@export var PUSH_FORCE = 90
@export var BUMP_FORCE = 90
@export var PUSH_FORCE = 700
var faceLeft = false
var pushLeftEnabled = false
var pushRightEnabled = false
var pushTarget
var bullet = preload("res://scenes/bullet.tscn")
@onready var right_ray = $RightRay
@onready var left_ray = $LeftRay
@onready var marker_right = $MarkerRight
@onready var marker_left = $MarkerLeft
func _physics_process(delta: float) -> void:
@@ -14,10 +28,42 @@ 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 pushTarget:
if Input.is_action_just_pressed("Shove") && pushLeftEnabled && faceLeft:
print("shove left")
pushTarget.apply_central_impulse(Vector2(-1,0) * PUSH_FORCE * 10)
pushLeftEnabled = false
if Input.is_action_just_pressed("Shove") && pushRightEnabled && not faceLeft:
print("shove right")
pushTarget.apply_central_impulse(Vector2(1,0) * PUSH_FORCE * 15)
pushRightEnabled = false
if Input.is_action_just_pressed("Shoot"):
var mybullet = bullet.instantiate()
print("I will shoot")
if faceLeft:
print("shoot left")
mybullet.set_speed(-700)
mybullet.transform = marker_right.global_transform
else:
print("shoot right")
mybullet.transform = marker_right.global_transform
owner.add_child(mybullet)
# 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")
if direction < 0:
faceLeft = true
if direction > 0:
faceLeft = false
if direction:
velocity.x = direction * SPEED
else:
@@ -27,4 +73,25 @@ func _physics_process(delta: float) -> void:
for i in (get_slide_collision_count()):
var c = get_slide_collision(i)
if c.get_collider() is RigidBody2D:
c.get_collider().apply_central_impulse(-c.get_normal()*PUSH_FORCE)
c.get_collider().apply_central_impulse(-c.get_normal()*BUMP_FORCE)
pushTarget = false
if left_ray.is_colliding():
print("Left ray collision")
var collider = left_ray.get_collider()
if collider is Node:
if collider.is_in_group("pushables"):
pushLeftEnabled = true
pushTarget = collider
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
+1 -1
View File
@@ -1,6 +1,6 @@
extends Node2D
var boxTotal = 4
var boxTotal = 3
var timer:= Timer.new()
@export var secondCount= 15