first commit
This commit is contained in:
commit
f87514862f
14 files changed
+356
No files matched your search
@@ -0,0 +1,101 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
|
||||
@export var SPEED = 300.0
|
||||
@export var JUMP_VELOCITY = -300.0
|
||||
@export var PUSH_FORCE = 700
|
||||
|
||||
var faceLeft = false
|
||||
# can i push right or left
|
||||
|
||||
var pushLeftEnabled = false
|
||||
var pushRightEnabled = false
|
||||
@onready var right_ray: RayCast2D = $RightRay
|
||||
@onready var left_ray: RayCast2D = $LeftRay
|
||||
@onready var marker_left: Node2D = $MarkerLeft
|
||||
@onready var marker_right: Node2D = $MarkerRight
|
||||
|
||||
|
||||
|
||||
var pushTarget
|
||||
|
||||
var bullet = preload("res://scenes/bullets.tscn")
|
||||
|
||||
|
||||
|
||||
|
||||
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
|
||||
|
||||
func _physics_process(delta):
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
velocity.y += gravity * delta
|
||||
|
||||
# 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 * 15)
|
||||
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 * 15)
|
||||
pushRightEnabled = false
|
||||
|
||||
if Input.is_action_just_pressed("shoot"):
|
||||
print("i will shoot")
|
||||
var mybullet = bullet.instantiate()
|
||||
|
||||
if faceLeft:
|
||||
print("shoot left")
|
||||
mybullet.setSpeed(-700)
|
||||
mybullet.transform = marker_left.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:
|
||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||
|
||||
move_and_slide()
|
||||
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()*100)
|
||||
|
||||
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
|
||||
@@ -0,0 +1,8 @@
|
||||
extends Area2D
|
||||
|
||||
@export var effect = "alert"
|
||||
signal areatrigger(effect, Object)
|
||||
|
||||
func _on_body_entered(body):
|
||||
print("detected a body")
|
||||
areatrigger.emit(effect, body)
|
||||
@@ -0,0 +1,14 @@
|
||||
extends Area2D
|
||||
|
||||
var speed := 700
|
||||
signal hit(bullet, body)
|
||||
|
||||
func setSpeed(speedVal):
|
||||
speed = speedVal
|
||||
print("js;ajfd")
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
position += transform.x * speed * delta
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
print("i done hit something")
|
||||
@@ -0,0 +1,15 @@
|
||||
extends Node2D
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
pass
|
||||
|
||||
|
||||
func _on_area_2d_areatrigger(effect, Object):
|
||||
print("Game Controller sees the trigger")
|
||||
Reference in new issue
Block a user