Está en la página 1de 3

extends Node2D

# member variables here, example:


# var a=2
# var b="textvar"
#SE
var
var
var

DEFINEN LAS VARIABLES


screenSize
padSize
ball_pos

#speed of the ball (in pixels/second0


var ball_speed
#direction of the ball (normal vector)
var direction
#constant for pad speed (also in pixels/second)
const PAD_SPEED = 150
#TERMINA LA DEFINICION DE VARIABLES
#SE DEFINEN LAS FUNCIONES
func _ready():
# Initalization here
screenSize = get_viewport_rect().size
PosicionInicial()
padSize = get_node("p1").get_texture().get_size()
set_process(true)
func _process(delta):
ball_pos = get_node("ball").get_pos()

ball_pos+=direction*ball_speed*delta
ColisionArribaAbajo()#se llama a la funcion de colision parte superior e
inferior
ColisionPaletas()#se llama ala funcion de colision con paletas (jugadores)
ColisionDerechaIzquierda()#se llama as la funcion de colisiones derecha e
izquierda
get_node("ball").set_pos(ball_pos)
MovimientoPlayer("p1",delta)
MovimientoPlayer("p2",delta)

#---------------------<<<<<<<<<<<<<<<<<<<<<<<SE DEFINE LA FUNCION PARA LA COLISION


CON LA PARTE INFERIOR Y SUPERIOR DEL CAMPO DE JUEGO
func ColisionArribaAbajo():
if ( (ball_pos.y<0 and direction.y <0) or (ball_pos.y>screenSize.y and
direction.y>0)):
direction.y = -direction.y
#---------------------->>>>>>>>>>>>>>>>>>>>>>>TERMINA LA FUNCIION
"ColisionArribaAbajo"

#---------------------<<<<<<<<<<<<<<<<<<<<<<SE DEFINE LA FUNCION QUE DETECTA LA


COLISION DE LA ESFERA CON LAS PALETAS DE LOS JUGADORES
func ColisionPaletas():
var left_rect = Rect2( get_node("p1").get_pos() - padSize/2, padSize )
var right_rect = Rect2( get_node("p2").get_pos() - padSize/2, padSize )
if ( (left_rect.has_point(ball_pos) and direction.x < 0) or
(right_rect.has_point(ball_pos) and direction.x > 0)):
direction.x=-direction.x
ball_speed*=1.1
direction.y=randf()*2.0-1
direction = direction.normalized()
#--------------------->>>>>>>>>>>>>>>>>>>>>>TERMINA LA FUCNION "ColisionPaletas"

#----------------------<<<<<<<<<<<<<<<<<<<<<<SE DEFINE UN METODO ENCARGADO DE


DETECTAR LA COLISION DE LA ESFERA CON LA PARTE DERECHA E IZQUIERDA DEL CAMP DE
JUEGO
func ColisionDerechaIzquierda():
if (ball_pos.x<0 or ball_pos.x>screenSize.x):
PosicionInicial()
#---------------------->>>>>>>>>>>>>>>>>>>>>TERMINA LA FUNCION
"ColisionDerechaIzquierda"

#----------------------<<<<<<<<<<<<<<<<<<<<<SE DEFINE UN METODO PARA UBICAR LA


ESFERA EN UNA POSICION INICIAL
func PosicionInicial():
ball_pos=screenSize*0.5 #ball goes to screen center
ball_speed=100
direction=Vector2(-1,0)

#--------------------------<<<<<<<<se define la funcion para el movimiento de las


paletas
func MovimientoPlayer(playerString,delta):
var pos = get_node(playerString).get_pos()
if (pos.y > 0 and Input.is_action_pressed(playerString+"_Up")):
pos.y+=-PAD_SPEED*delta
if (pos.y < screenSize.y and Input.is_action_pressed(playerString+"_Down")):
pos.y+=PAD_SPEED*delta
get_node(playerString).set_pos(pos)
#-------------------------->>>>>>>>TERMINA LA FUNCION "MovimientoPlayer"
#TERMINA LA DEFINICION DE FUNCIONES

if(Input.is_action_pressed("derecha")):

if(escala.x == 1):
get_node("SonidoCaminar").play("Girar")
_animacionPersonaje("AnimacionVoltear")
#girar = true
if(escala.x == -1):
pos.x += SPEED_IN_PIXELS_PER_SECONDS * delta
if(cambiarAnimacion):
_animacionPersonaje("AnimacionCaminar")
cambiarAnimacion = false
elif(Input.is_action_pressed("izquierda")):
pos.x -= SPEED_IN_PIXELS_PER_SECONDS * delta
escala.x = 1
if(cambiarAnimacion):
_animacionPersonaje("AnimacionCaminar")
cambiarAnimacion = false
else:
if(!cambiarAnimacion):
_animacionPersonaje("AnimacionIdle")
cambiarAnimacion = true
if(frameActual == 9 ):#condicion que detecta cuando el personaje coloca el
pie sobre el suelo
get_node("SonidoCaminar").play("Pasos")
if(frameActual == 27 ):#Condicion que detecta el giro completo del personaje
escala.x = escala.x * -1
_animacionPersonaje("AnimacionIdle")
/usr/adt-bundle-linux-x86-20140702/sdk/platform-tools/adb

También podría gustarte