This commit is contained in:
indigoapples 2024-09-09 21:08:24 -04:00
parent aebca85f4d
commit 7696ff9773
7 changed files with 161 additions and 23 deletions

BIN
indigogameone/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -14,3 +14,16 @@ config/name="indigogameone"
run/main_scene="res://scenes/game.tscn"
config/features=PackedStringArray("4.3", "Forward Plus")
config/icon="res://icon.svg"
[input]
Shove={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":90,"key_label":0,"unicode":122,"location":0,"echo":false,"script":null)
]
}
shoot={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":88,"key_label":0,"unicode":120,"location":0,"echo":false,"script":null)
]
}

View File

@ -0,0 +1,16 @@
[gd_scene load_steps=3 format=3 uid="uid://ctn52om1wdpb5"]
[ext_resource type="Script" path="res://scripts/bullet.gd" id="1_5y5v0"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_qu5ok"]
size = Vector2(20, 4)
[node name="Area2D" type="Area2D"]
script = ExtResource("1_5y5v0")
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_qu5ok")
debug_color = Color(0, 0.909804, 0.541176, 0.419608)
[connection signal="body_entered" from="." to="." method="_on_body_entered"]

View File

@ -1,7 +1,7 @@
[gd_scene load_steps=7 format=3 uid="uid://bpvxf6b1pgvw1"]
[gd_scene load_steps=6 format=3 uid="uid://bpvxf6b1pgvw1"]
[ext_resource type="PackedScene" uid="uid://d4lcu5l7nqd2f" path="res://scenes/crate.tscn" id="1_5062r"]
[ext_resource type="Script" path="res://scripts/player.gd" id="2_u8ltq"]
[ext_resource type="PackedScene" uid="uid://b06r6vtllw0b7" path="res://scenes/player.tscn" id="1_fdutd"]
[ext_resource type="PackedScene" uid="uid://ckvtpjm5q2t0d" path="res://scenes/trigger.tscn" id="3_bhtcy"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_by4gc"]
@ -9,8 +9,6 @@ size = Vector2(25.75, 20)
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_7qxn5"]
[sub_resource type="CircleShape2D" id="CircleShape2D_gwwau"]
[node name="World" type="Node2D"]
[node name="platform" type="StaticBody2D" parent="."]
@ -43,21 +41,16 @@ metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="Floor"]
shape = SubResource("WorldBoundaryShape2D_7qxn5")
[node name="RigidBody2D" parent="." instance=ExtResource("1_5062r")]
[node name="RigidBody2D2" parent="." instance=ExtResource("1_5062r")]
position = Vector2(424, 370)
[node name="RigidBody2D3" parent="." instance=ExtResource("1_5062r")]
position = Vector2(603, 416)
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
position = Vector2(555, 322)
script = ExtResource("2_u8ltq")
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
shape = SubResource("CircleShape2D_gwwau")
debug_color = Color(0.858824, 0.227451, 0.4, 0.909804)
[node name="CharacterBody2D" parent="." instance=ExtResource("1_fdutd")]
rotation = -0.00098838
[node name="Area2D" parent="." instance=ExtResource("3_bhtcy")]
[node name="RigidBody2D" parent="." groups=["pushables"] instance=ExtResource("1_5062r")]
position = Vector2(455, 407)
[node name="RigidBody2D2" parent="." groups=["pushables"] instance=ExtResource("1_5062r")]
position = Vector2(453, 166)
[node name="RigidBody2D3" parent="." groups=["pushables"] instance=ExtResource("1_5062r")]
position = Vector2(605, 250)

View File

@ -0,0 +1,25 @@
[gd_scene load_steps=3 format=3 uid="uid://b06r6vtllw0b7"]
[ext_resource type="Script" path="res://scripts/player.gd" id="1_5gbgu"]
[sub_resource type="CircleShape2D" id="CircleShape2D_gwwau"]
[node name="CharacterBody2D" type="CharacterBody2D"]
script = ExtResource("1_5gbgu")
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_gwwau")
debug_color = Color(0.858824, 0.227451, 0.4, 0.909804)
[node name="RightRay" type="RayCast2D" parent="."]
target_position = Vector2(20, 0)
[node name="LeftRay" type="RayCast2D" parent="."]
target_position = Vector2(-19, 0)
[node name="MarkerRight" type="Node2D" parent="."]
position = Vector2(12, -5)
[node name="MarkerLeft" type="Node2D" parent="."]
position = Vector2(-12, -5)

View File

@ -0,0 +1,18 @@
extends Area2D
var speed := 700 #implied type colon equal it looks at what you're trying to store in memory and put similar things together which is much faster for your operating system to process
signal hit(bullet, body)
#make signal that when it hits something gonna send a bit of info
func setSpeed(speedVal):
#by default will be 700, but can change here if we want
speed = speedVal
func _physics_process(delta: float) -> 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")

View File

@ -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