Skip to content
Snippets Groups Projects
Commit 813d0af8 authored by Frederic Aust's avatar Frederic Aust
Browse files

Je nach Auftreffpunkt am Schläger wird der Abprallwinkel des Balls angepasst;...

Je nach Auftreffpunkt am Schläger wird der Abprallwinkel des Balls angepasst; Die Startrichtung des Balls wird zufällig gewählt aber innerhalb eines sinnvollem Bereichs; Die Schläger haben unterschiedliche Farben, damit sich der Algorithum beim lernen an der Farbe orientieren kann
parent 5262212a
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,7 @@ extends KinematicBody2D ...@@ -4,7 +4,7 @@ extends KinematicBody2D
# Declare member variables here. # Declare member variables here.
export var speed = 300 export var speed = 300
export var speed_max = 600 export var speed_max = 600
export var bounce_degree_max = 100 export var bounce_degree_max = 60
var ball_size var ball_size
var playing = false var playing = false
var velocity = Vector2(100,0) var velocity = Vector2(100,0)
...@@ -38,7 +38,7 @@ func _physics_process(delta): ...@@ -38,7 +38,7 @@ func _physics_process(delta):
# var localCollisionPos = collision.Position - collision.collider.Position; # var localCollisionPos = collision.Position - collision.collider.Position;
func ball_hit_paddle(player_position, shape): func ball_hit_paddle(player_position, player_shape, is_player_one):
# Geschwindigkeitserhöhung # Geschwindigkeitserhöhung
if speed < speed_max: if speed < speed_max:
speed +=20 speed +=20
...@@ -46,7 +46,15 @@ func ball_hit_paddle(player_position, shape): ...@@ -46,7 +46,15 @@ func ball_hit_paddle(player_position, shape):
# Ball geht in die andere Richtung # Ball geht in die andere Richtung
velocity.x*=-1 velocity.x*=-1
var half_player_height = shape.extents.y/2 var half_player_height = player_shape.y/2
if (is_player_one and (player_position.x > position.x-(ball_size.x/2 + player_shape.x/2))):
velocity.y*=-1
velocity.x*=-1
pass
if (not is_player_one and (player_position.x < position.x + (ball_size.x/2 + player_shape.x/2))):
velocity.y*=-1
velocity.x*=-1
pass
var collision_height = player_position.y-position.y var collision_height = player_position.y-position.y
if collision_height<0: if collision_height<0:
...@@ -67,3 +75,8 @@ func start(pos): ...@@ -67,3 +75,8 @@ func start(pos):
show() show()
$CollisionShape2D.disabled = false $CollisionShape2D.disabled = false
ball_size =$CollisionShape2D.shape.extents ball_size =$CollisionShape2D.shape.extents
randomize()
velocity = Vector2(100, rand_range(-200,200))
if rand_range(-1,1)<0:
velocity.x*=-1
print(velocity)
...@@ -107,10 +107,10 @@ func handle_game_end(): ...@@ -107,10 +107,10 @@ func handle_game_end():
func _on_PlayerTwo_hit(): func _on_PlayerTwo_hit():
ball.ball_hit_paddle($PlayerTwo.position, $PlayerTwo/CollisionShape2D.shape) ball.ball_hit_paddle($PlayerTwo.position, $PlayerTwo/CollisionShape2D.shape.extents, false)
pass # Replace with function body. pass # Replace with function body.
func _on_PlayerOne_hit(): func _on_PlayerOne_hit():
ball.ball_hit_paddle($PlayerOne.position, $PlayerOne/CollisionShape2D.shape) ball.ball_hit_paddle($PlayerOne.position, $PlayerOne/CollisionShape2D.shape.extents, true)
pass # Replace with function body. pass # Replace with function body.
...@@ -10,6 +10,8 @@ var player_size ...@@ -10,6 +10,8 @@ var player_size
func _ready(): func _ready():
screen_size = get_viewport_rect().size screen_size = get_viewport_rect().size
player_size =$CollisionShape2D.shape.extents player_size =$CollisionShape2D.shape.extents
if(is_player_one):
$ColorRect.color=Color(0,0,0,1)
#hide() #hide()
pass # Replace with function body. pass # Replace with function body.
......
...@@ -31,7 +31,7 @@ position = Vector2( -1.5, 0 ) ...@@ -31,7 +31,7 @@ position = Vector2( -1.5, 0 )
scale = Vector2( 3, 6 ) scale = Vector2( 3, 6 )
frames = SubResource( 1 ) frames = SubResource( 1 )
animation = "wave" animation = "wave"
frame = 1 frame = 2
speed_scale = 2.0 speed_scale = 2.0
playing = true playing = true
......
...@@ -17,6 +17,7 @@ shape = SubResource( 1 ) ...@@ -17,6 +17,7 @@ shape = SubResource( 1 )
margin_top = -4.0 margin_top = -4.0
margin_right = 1024.0 margin_right = 1024.0
margin_bottom = 4.0 margin_bottom = 4.0
color = Color( 0, 0, 1, 1 )
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment