I need help with Pong

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By anthony_svarcbergs

Hi guys, still very new to GDScripting and this has me stumped. I have been working on the step by step pong tutorial; (Simple 2D game — Godot Engine (2.1) documentation in English)
I am hitting some dead ends. Can anyone help me where I’m going wrong, code to follow.

extends Node2D

var screen_size
var pad_size
const PAD_SPEED = 150
var ball_speed = 80
var ball_direction = Vector2(-1, 0)

func _ready():
screen_size = get_viewport_rect().size
pad_size = get_node(“left”).get_texture().get_size()
set_process(true)

func _process(delta):
var ball_pos = get_node(“ball”).get_pos()
var left_rect = Rect2( get_node(“left”).get_pos() - pad_size0.5, pad_size )
var right_rect = Rect2( get_node(“right”).get_pos() - pad_size
0.5, pad_size )

# Flip when touching roof or floor
if ((ball_pos.y < 0 and direction.y < 0) or (ball_pos.y > screen_size.y and direction.y > 0)):
	direction.y = -direction.y
if (( left_rect.has_point(ball_pos) and ball_direction.x < 0 ) or ( right_rect.has_point(ball_pos) and ball_direction.x > 0)):
	ball_direction.x = -ball_direction.x
	ball_speed *= 1.1
	ball_direction.y  = randf() * 2.0 -1
	ball_direction = ball_direction.normalized()

if (ball_pos.x < 0 or ball_pos.x > screen_size.x):
	ball_pos = screen_size * 0.5 
	ball_speed = 80
	ball_direction = Vector2(-1,0)

get_node("ball").set_pos(ball_pos)


var left_pos = get_node("left").get_pos()
if (left_pos.y > 0 and Input.is_action_pressed("left_move_up")):
	left_pos.y += - PAD_SPEED * delta

if (left_pos.y < screen_size.y and Input.is_action_pressed("left_move_down")):
	left_pos.y += PAD_SPEED * delta

get_node("left").set_pos(left_pos)

var right_pos = get_node("right").get_pos()
if ( right_pos.y > 0 and Input.is_action_pressed("right_move_up")):
	right_pos.y  += - PAD_SPEED * delta

if ( right_pos.y < screen_size.y and Input.is_action_pressed("right_move_down")):
	right_pos.y += PAD_SPEED * delta

get_node("right").set_pos(right_pos)

A couple of comments:

  1. This is a very old tutorial, based on Godot 2.1. Are you using Godot 2.1? If so why? If not, you should follow the much improved 3.1 docs version. Most people are using 3.1 these days, so it’s going to be harder to find help.

  2. You just pasted code but didn’t include anything about what went wrong.

kidscancode | 2019-07-15 03:25

Yes using 3.1 but I just googled it and found that tutorial so I will look for a newer one.

Thanks for the tip on the What went wrong. my apologies,
this I copied from the errors dialogue box:
E 0:00:00:0280 Condition ’ _debug_parse_err_line >= 0 ’ is true. returned: __null
modules/gdscript/gdscript_editor.cpp:330 @ debug_get_stack_level_instance()

What other info can I get to help you see my mistakes?

and thanks so much

anthony_svarcbergs | 2019-07-15 06:12