mirror of
https://git.kittycat.homes/zoe/pegchamp.git
synced 2024-08-15 03:15:39 +00:00
first commit
This commit is contained in:
commit
fafcbd1530
223 changed files with 107395 additions and 0 deletions
96
Ball/Ball.gd
Normal file
96
Ball/Ball.gd
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
extends RigidBody2D
|
||||
|
||||
export var shotspeed = 100
|
||||
|
||||
onready var cameraTransform = $CameraTransform
|
||||
onready var trajectoryTimer = $TrajectoryTimer
|
||||
onready var animation = $AnimationPlayer
|
||||
|
||||
enum {FALL, AIM, RESPAWN}
|
||||
var state = RESPAWN
|
||||
|
||||
var can_spawn_trajectory_dot = false
|
||||
|
||||
func _ready():
|
||||
cameraTransform.position = Vector2.ZERO
|
||||
animation.play("reset")
|
||||
GameStats.balls_left = GameStats.max_balls
|
||||
|
||||
func _physics_process(_delta):
|
||||
match state:
|
||||
FALL: fall()
|
||||
AIM: aim()
|
||||
RESPAWN: spawn_trajectory_dots()
|
||||
|
||||
func fall():
|
||||
handle_collisions()
|
||||
|
||||
func handle_collisions():
|
||||
# get an array with objects the ball is colliding with
|
||||
var collider_array = get_colliding_bodies()
|
||||
if (collider_array):
|
||||
for collider in collider_array:
|
||||
set_particle_direction(collider)
|
||||
bounce_of(collider)
|
||||
turn_pegs_green(collider)
|
||||
|
||||
func turn_pegs_green(collider):
|
||||
# check if pegs can be turned green
|
||||
if (collider.has_method("make_green")):
|
||||
#if yes then do it
|
||||
collider.make_green()
|
||||
|
||||
func set_particle_direction(collider):
|
||||
if (collider.has_method("set_particle_direction")):
|
||||
collider.set_particle_direction(linear_velocity.normalized() * -1)
|
||||
|
||||
func bounce_of(collider):
|
||||
if (collider.has_method("bouncy")):
|
||||
apply_central_impulse(linear_velocity.normalized() * shotspeed / 6)
|
||||
|
||||
func aim():
|
||||
cameraTransform.position = Vector2.ZERO + get_local_mouse_position().normalized() * 10
|
||||
spawn_trajectory_dots()
|
||||
if(Input.is_action_just_released("shoot")):
|
||||
cameraTransform.position = Vector2.ZERO + linear_velocity.normalized() * 10
|
||||
set_mode(RigidBody2D.MODE_RIGID)
|
||||
|
||||
state = FALL
|
||||
|
||||
# calculate shot speed and direction
|
||||
var direction = get_local_mouse_position().normalized()
|
||||
var speed = position.distance_to(get_global_mouse_position())
|
||||
speed *= shotspeed / 100
|
||||
speed = clamp(speed, 0, 125)
|
||||
apply_central_impulse(speed * direction)
|
||||
trajectoryTimer.stop()
|
||||
func _on_TrajectoryTimer_timeout():
|
||||
can_spawn_trajectory_dot = true
|
||||
func spawn_trajectory_dots():
|
||||
# spawn trajectory dots
|
||||
if (can_spawn_trajectory_dot):
|
||||
var Trajectory = load("res://Ball/Trajectory.tscn")
|
||||
var trajectory = Trajectory.instance()
|
||||
trajectory.position = position
|
||||
var main = get_tree().current_scene
|
||||
main.add_child(trajectory)
|
||||
# stop infinite dots from spawning
|
||||
can_spawn_trajectory_dot = false
|
||||
|
||||
if (Input.is_action_just_pressed("shoot")):
|
||||
can_spawn_trajectory_dot = true
|
||||
trajectoryTimer.start()
|
||||
func reset_ball():
|
||||
# delete the ball when the level is won, so it doesn't respawn
|
||||
if GameStats.level_won:
|
||||
queue_free()
|
||||
# reset ball
|
||||
else:
|
||||
rotation = 0
|
||||
call_deferred("set", "mode", RigidBody2D.MODE_STATIC)
|
||||
call_deferred("set", "position", Vector2(192, 8))
|
||||
cameraTransform.position = Vector2.ZERO
|
||||
state = RESPAWN
|
||||
animation.play("reset")
|
||||
func reset_done():
|
||||
state = AIM
|
||||
6
Ball/Ball.tres
Normal file
6
Ball/Ball.tres
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[gd_resource type="PhysicsMaterial" format=2]
|
||||
|
||||
[resource]
|
||||
resource_name = "Ball"
|
||||
friction = 0.8
|
||||
bounce = 0.5
|
||||
63
Ball/Ball.tscn
Normal file
63
Ball/Ball.tscn
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
[gd_scene load_steps=6 format=2]
|
||||
|
||||
[ext_resource path="res://Ball/sprite.png" type="Texture" id=1]
|
||||
[ext_resource path="res://Ball/Ball.gd" type="Script" id=2]
|
||||
[ext_resource path="res://Ball/Ball.tres" type="PhysicsMaterial" id=3]
|
||||
[ext_resource path="res://Ball/BallCollision.tscn" type="PackedScene" id=4]
|
||||
|
||||
[sub_resource type="Animation" id=1]
|
||||
resource_name = "reset"
|
||||
length = 1.5
|
||||
step = 0.05
|
||||
tracks/0/type = "method"
|
||||
tracks/0/path = NodePath(".")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/keys = {
|
||||
"times": PoolRealArray( 1.5 ),
|
||||
"transitions": PoolRealArray( 1 ),
|
||||
"values": [ {
|
||||
"args": [ ],
|
||||
"method": "reset_done"
|
||||
} ]
|
||||
}
|
||||
tracks/1/type = "bezier"
|
||||
tracks/1/path = NodePath("Sprite:position:y")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/keys = {
|
||||
"points": PoolRealArray( -10, -0.25, 0, 0.25, 0, 0, -0.25, 0, 0.25, 0 ),
|
||||
"times": PoolRealArray( 0, 1.5 )
|
||||
}
|
||||
|
||||
[node name="Ball" type="RigidBody2D"]
|
||||
collision_layer = 4
|
||||
mass = 90.0
|
||||
physics_material_override = ExtResource( 3 )
|
||||
continuous_cd = 2
|
||||
contacts_reported = 4
|
||||
contact_monitor = true
|
||||
linear_velocity = Vector2( 0, -10 )
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="CameraTransform" type="RemoteTransform2D" parent="."]
|
||||
remote_path = NodePath("../../../Camera2D")
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
position = Vector2( 0, -10 )
|
||||
texture = ExtResource( 1 )
|
||||
|
||||
[node name="BallCollision" parent="." instance=ExtResource( 4 )]
|
||||
visible = true
|
||||
|
||||
[node name="TrajectoryTimer" type="Timer" parent="."]
|
||||
wait_time = 0.1
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
anims/reset = SubResource( 1 )
|
||||
|
||||
[connection signal="timeout" from="TrajectoryTimer" to="." method="_on_TrajectoryTimer_timeout"]
|
||||
8
Ball/BallCollision.tscn
Normal file
8
Ball/BallCollision.tscn
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[sub_resource type="CircleShape2D" id=2]
|
||||
radius = 8.23541
|
||||
|
||||
[node name="BallCollision" type="CollisionShape2D"]
|
||||
visible = false
|
||||
shape = SubResource( 2 )
|
||||
27
Ball/Trajectory.gd
Normal file
27
Ball/Trajectory.gd
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
extends RigidBody2D
|
||||
|
||||
export var shotspeed = 200
|
||||
|
||||
func _on_Kill_Timer_timeout():
|
||||
queue_free()
|
||||
|
||||
func _ready():
|
||||
var direction = get_local_mouse_position().normalized()
|
||||
var speed = position.distance_to(get_global_mouse_position())
|
||||
speed *= shotspeed / 100
|
||||
speed = clamp(speed, 0, 200)
|
||||
apply_central_impulse(speed * direction)
|
||||
|
||||
|
||||
func _physics_process(_delta):
|
||||
if (get_colliding_bodies()):
|
||||
queue_free()
|
||||
|
||||
|
||||
func _process(_delta):
|
||||
if (Input.is_action_just_released("shoot")):
|
||||
queue_free()
|
||||
|
||||
func bounce_of(collider):
|
||||
if (collider.has_method("bouncy")):
|
||||
apply_central_impulse(linear_velocity.normalized() * shotspeed / 5)
|
||||
28
Ball/Trajectory.tscn
Normal file
28
Ball/Trajectory.tscn
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
[gd_scene load_steps=5 format=2]
|
||||
|
||||
[ext_resource path="res://Ball/Trajectory.gd" type="Script" id=1]
|
||||
[ext_resource path="res://Ball/trajectory.png" type="Texture" id=2]
|
||||
[ext_resource path="res://Ball/Ball.tres" type="PhysicsMaterial" id=3]
|
||||
[ext_resource path="res://Ball/BallCollision.tscn" type="PackedScene" id=4]
|
||||
|
||||
[node name="Trajectory" type="RigidBody2D"]
|
||||
z_index = -1
|
||||
collision_layer = 0
|
||||
mass = 90.0
|
||||
physics_material_override = ExtResource( 3 )
|
||||
continuous_cd = 2
|
||||
contacts_reported = 1
|
||||
contact_monitor = true
|
||||
linear_velocity = Vector2( 0, -10 )
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="BallCollision" parent="." instance=ExtResource( 4 )]
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
texture = ExtResource( 2 )
|
||||
|
||||
[node name="Kill Timer" type="Timer" parent="."]
|
||||
wait_time = 0.5
|
||||
autostart = true
|
||||
|
||||
[connection signal="timeout" from="Kill Timer" to="." method="_on_Kill_Timer_timeout"]
|
||||
BIN
Ball/sprite.png
Normal file
BIN
Ball/sprite.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 313 B |
34
Ball/sprite.png.import
Normal file
34
Ball/sprite.png.import
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/sprite.png-06fb0593a7d59b4a8e86f4e1f0b64ea8.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://Ball/sprite.png"
|
||||
dest_files=[ "res://.import/sprite.png-06fb0593a7d59b4a8e86f4e1f0b64ea8.stex" ]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=1
|
||||
flags/filter=false
|
||||
flags/mipmaps=false
|
||||
flags/anisotropic=false
|
||||
flags/srgb=2
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=false
|
||||
svg/scale=1.0
|
||||
BIN
Ball/trajectory.png
Normal file
BIN
Ball/trajectory.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 90 B |
34
Ball/trajectory.png.import
Normal file
34
Ball/trajectory.png.import
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/trajectory.png-8a9d7730bd69d51efb2903d6ef85458a.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://Ball/trajectory.png"
|
||||
dest_files=[ "res://.import/trajectory.png-8a9d7730bd69d51efb2903d6ef85458a.stex" ]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=0
|
||||
flags/filter=false
|
||||
flags/mipmaps=false
|
||||
flags/anisotropic=false
|
||||
flags/srgb=2
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=false
|
||||
svg/scale=1.0
|
||||
Loading…
Add table
Add a link
Reference in a new issue