7-8-25 6:02pm
This commit is contained in:
25
Gameplay/Main.cs
Normal file
25
Gameplay/Main.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class Main : Node
|
||||
{
|
||||
// Don't forget to rebuild the project so the editor knows about the new export variable.
|
||||
public override void _Ready()
|
||||
{
|
||||
NewGame();
|
||||
}
|
||||
|
||||
public void NewGame()
|
||||
{
|
||||
//_score = 0;
|
||||
|
||||
var player = GetNode<Marble>("Marble");
|
||||
var startPosition = GetNode<Marker2D>("StartPosition");
|
||||
player.Start(startPosition.Position);
|
||||
var player2 = GetNode<Marble>("Marble2");
|
||||
var startPosition2 = GetNode<Marker2D>("StartPosition2");
|
||||
player2.Start(startPosition2.Position);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
1
Gameplay/Main.cs.uid
Normal file
1
Gameplay/Main.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://v6ovq4snxruc
|
||||
181
Gameplay/Marble.cs
Normal file
181
Gameplay/Marble.cs
Normal file
@@ -0,0 +1,181 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class Marble : RigidBody2D
|
||||
{
|
||||
// Don't forget to rebuild the project so the editor knows about the new signal.
|
||||
|
||||
[Signal]
|
||||
public delegate void HitEventHandler();
|
||||
[Signal]
|
||||
public delegate void HoverEventHandler();
|
||||
[Signal]
|
||||
public delegate void HoverFalseEventHandler();
|
||||
[Signal]
|
||||
public delegate void SelectEventHandler();
|
||||
[Signal]
|
||||
public delegate void SelectFalseEventHandler();
|
||||
[Signal]
|
||||
public delegate void AimEventHandler();
|
||||
[Signal]
|
||||
public delegate void AimFalseEventHandler();
|
||||
[Signal]
|
||||
public delegate void LaunchEventHandler();
|
||||
[Signal]
|
||||
public delegate void MoveEventHandler();
|
||||
[Signal]
|
||||
public delegate void StopEventHandler();
|
||||
|
||||
[Export]
|
||||
public int Speed { get; set; } = 400; // How fast the player will move (pixels/sec).
|
||||
|
||||
public bool Hovered = false, Selected = false, Aimed = false, Launched = false, Moving = false;
|
||||
public Vector2 Force = Vector2.Zero, Velocity = Vector2.Zero;
|
||||
public Vector2 ScreenSize; // Size of the game window.
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
ScreenSize = GetViewportRect().Size;
|
||||
//Hide();
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta) //THIS IS LIKE THE UPDATE FUNCTION
|
||||
{
|
||||
TrySelect();
|
||||
TryAim();
|
||||
TryLaunch();
|
||||
TryMovement();
|
||||
}
|
||||
|
||||
public void ProcessOnBump(Node2D body)
|
||||
{
|
||||
GD.Print(body);
|
||||
}
|
||||
|
||||
public void ProcessOnMovement()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Start(Vector2 position)
|
||||
{
|
||||
Position = position;
|
||||
Show();
|
||||
GetNode<CollisionShape2D>("CollisionShape2D").Disabled = false;
|
||||
}
|
||||
|
||||
public void TryAim()
|
||||
{
|
||||
if (Selected && Input.IsActionPressed("left_click") && !Hovered && !Aimed)
|
||||
{
|
||||
Aimed = true;
|
||||
EmitSignal(SignalName.Aim);
|
||||
}
|
||||
|
||||
if (Aimed)
|
||||
{
|
||||
Vector2 mousePosition = GetGlobalMousePosition();
|
||||
Force = Position - mousePosition;
|
||||
|
||||
if (!Input.IsActionPressed("left_click"))
|
||||
{
|
||||
if (!Hovered)
|
||||
{
|
||||
Launched = true;
|
||||
EmitSignal(SignalName.SelectFalse);
|
||||
}
|
||||
else
|
||||
{
|
||||
Aimed = false;
|
||||
EmitSignal(SignalName.AimFalse);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void TryLaunch()
|
||||
{
|
||||
if (Aimed && Input.IsActionJustReleased("left_click"))
|
||||
{
|
||||
Selected = false;
|
||||
EmitSignal(SignalName.SelectFalse);
|
||||
|
||||
Aimed = false;
|
||||
EmitSignal(SignalName.AimFalse);
|
||||
|
||||
Launched = true;
|
||||
EmitSignal(SignalName.Launch);
|
||||
|
||||
ApplyCentralForce(Force * Speed);
|
||||
|
||||
Force = Vector2.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
public void TryMovement()
|
||||
{
|
||||
if (LinearVelocity.Length() > 0 && !Sleeping)
|
||||
{
|
||||
if (!Moving)
|
||||
{
|
||||
Moving = true;
|
||||
EmitSignal(SignalName.Move);
|
||||
}
|
||||
}
|
||||
if (Moving)
|
||||
{
|
||||
ProcessOnMovement();
|
||||
if (Sleeping)
|
||||
{
|
||||
Moving = false;
|
||||
EmitSignal(SignalName.Stop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void TrySelect()
|
||||
{
|
||||
if (Hovered)
|
||||
{
|
||||
if (Input.IsActionJustPressed("left_click") && !Selected)
|
||||
{
|
||||
Selected = true;
|
||||
EmitSignal(SignalName.Select);
|
||||
}
|
||||
}
|
||||
|
||||
if (Selected)
|
||||
{
|
||||
if (!Hovered)
|
||||
{
|
||||
if (Input.IsActionJustPressed("left_click") && Selected)
|
||||
{
|
||||
Selected = false;
|
||||
EmitSignal(SignalName.SelectFalse);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMouseEntered()
|
||||
{
|
||||
Hovered = true;
|
||||
EmitSignal(SignalName.Hover);
|
||||
}
|
||||
|
||||
private void OnMouseExited()
|
||||
{
|
||||
Hovered = false;
|
||||
EmitSignal(SignalName.HoverFalse);
|
||||
}
|
||||
|
||||
private void OnBodyEntered(Node2D body)
|
||||
{
|
||||
if (body.GetType() == typeof(Marble))
|
||||
{
|
||||
Marble marble = (Marble)body;
|
||||
ProcessOnBump(marble);
|
||||
marble.ProcessOnBump(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
1
Gameplay/Marble.cs.uid
Normal file
1
Gameplay/Marble.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b1bipn8tmpggr
|
||||
19
Gameplay/main.tscn
Normal file
19
Gameplay/main.tscn
Normal file
@@ -0,0 +1,19 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://yqtgkxjjexag"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://v6ovq4snxruc" path="res://Gameplay/Main.cs" id="1_0xm2m"]
|
||||
[ext_resource type="PackedScene" uid="uid://c8n4lue2bn25n" path="res://Gameplay/marble.tscn" id="2_h2yge"]
|
||||
|
||||
[node name="Main" type="Node"]
|
||||
script = ExtResource("1_0xm2m")
|
||||
|
||||
[node name="Marble" parent="." instance=ExtResource("2_h2yge")]
|
||||
|
||||
[node name="StartPosition" type="Marker2D" parent="."]
|
||||
position = Vector2(200, 200)
|
||||
|
||||
[node name="Marble2" parent="." instance=ExtResource("2_h2yge")]
|
||||
|
||||
[node name="StartPosition2" type="Marker2D" parent="."]
|
||||
position = Vector2(400, 200)
|
||||
|
||||
[connection signal="Hit" from="Marble" to="." method="GameOver"]
|
||||
83
Gameplay/marble.tscn
Normal file
83
Gameplay/marble.tscn
Normal file
@@ -0,0 +1,83 @@
|
||||
[gd_scene load_steps=14 format=3 uid="uid://c8n4lue2bn25n"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b1bipn8tmpggr" path="res://Gameplay/Marble.cs" id="1_7ritg"]
|
||||
[ext_resource type="Texture2D" uid="uid://bigvacjklr7in" path="res://art/playerGrey_up1.png" id="2_76m5q"]
|
||||
[ext_resource type="Texture2D" uid="uid://dd3s6x86dgxem" path="res://art/checkerboard.png" id="2_fkve3"]
|
||||
[ext_resource type="Texture2D" uid="uid://bskloxogmm7ox" path="res://art/playerGrey_up2.png" id="3_4rms2"]
|
||||
[ext_resource type="Shader" uid="uid://dvpsalh3o60iu" path="res://shaders/red.gdshader" id="3_6v01e"]
|
||||
[ext_resource type="Texture2D" uid="uid://cww2tug20ksn3" path="res://art/playerGrey_walk1.png" id="4_iy80h"]
|
||||
[ext_resource type="Texture2D" uid="uid://csm4ru8wkc2cb" path="res://art/playerGrey_walk2.png" id="5_ryns1"]
|
||||
|
||||
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_803qd"]
|
||||
bounce = 1.0
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_bdlqm"]
|
||||
render_priority = 0
|
||||
shader = ExtResource("3_6v01e")
|
||||
|
||||
[sub_resource type="CapsuleMesh" id="CapsuleMesh_eju0r"]
|
||||
material = SubResource("ShaderMaterial_bdlqm")
|
||||
radius = 1.5
|
||||
height = 3.0
|
||||
|
||||
[sub_resource type="MeshTexture" id="MeshTexture_nbhrg"]
|
||||
mesh = SubResource("CapsuleMesh_eju0r")
|
||||
base_texture = ExtResource("2_fkve3")
|
||||
image_size = Vector2(55, 55)
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_n7ghd"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("2_76m5q")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("3_4rms2")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"up",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("4_iy80h")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("5_ryns1")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"walk",
|
||||
"speed": 5.0
|
||||
}]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_803qd"]
|
||||
radius = 27.0185
|
||||
|
||||
[node name="Marble" type="RigidBody2D"]
|
||||
input_pickable = true
|
||||
mass = 3.0
|
||||
physics_material_override = SubResource("PhysicsMaterial_803qd")
|
||||
gravity_scale = 0.0
|
||||
contact_monitor = true
|
||||
max_contacts_reported = 1
|
||||
linear_damp = 3.0
|
||||
script = ExtResource("1_7ritg")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
position = Vector2(-4.76837e-07, -9.53674e-07)
|
||||
texture = SubResource("MeshTexture_nbhrg")
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||
visible = false
|
||||
position = Vector2(0, 7)
|
||||
scale = Vector2(0.5, 0.5)
|
||||
sprite_frames = SubResource("SpriteFrames_n7ghd")
|
||||
animation = &"walk"
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_803qd")
|
||||
|
||||
[connection signal="body_entered" from="." to="." method="OnBodyEntered"]
|
||||
[connection signal="mouse_entered" from="." to="." method="OnMouseEntered"]
|
||||
[connection signal="mouse_exited" from="." to="." method="OnMouseExited"]
|
||||
Reference in New Issue
Block a user