-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBall.cs
More file actions
60 lines (47 loc) · 1.24 KB
/
Ball.cs
File metadata and controls
60 lines (47 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using Godot;
using System;
public class Ball : RigidBody2D
{
private bool Fixed = false;
private bool Hit = false;
private Vector2 FixPosition;
private AudioStreamPlayer2D hitSound;
private float t;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
hitSound = GetNode<AudioStreamPlayer2D>("HitSound");
ContactMonitor = true;
ContactsReported = 1;
}
public void Fire(float xVelocity, float yVelocity) {
GD.Print("FIREEE! with velocity: " + xVelocity + ", "+ yVelocity);
this.LinearVelocity = new Vector2(xVelocity, yVelocity);
this.GravityScale = 1;
this.Fixed = false;
t = 0;
}
public void Reset(Vector2 position) {
this.GravityScale = 0;
this.LinearVelocity = new Vector2(0, 0);
this.Position = position;
this.Fixed = true;
this.Hit = false;
this.FixPosition = position;
}
public override void _IntegrateForces(Physics2DDirectBodyState physicsState) {
if (Fixed) {
physicsState.Transform = new Transform2D(0, FixPosition);
}
Fixed = false;
if (Hit || Fixed)
{
return;
}
// check collision with prefab
if (physicsState.GetContactCount() == 0) return;
GD.Print("[Ball] Hit first time");
hitSound.Playing = true;
Hit = true;
}
}