Scripts for character / collection / and point management



ALL THE CODE IS WRITTEN IN  GDSCRIPT


CHARACTER SCRIPT

extends CharacterBody2D

const SPEED = 400.0

const JUMP_VELOCITY = -900.0

@onready var sprite_2d: AnimatedSprite2D = $Sprite2D

func _physics_process(delta: float) -> void:

# Running Animations

if (velocity.x > 1 || velocity.x < -1):

sprite_2d.animation = "running"

else:

sprite_2d.animation = "default"

# Add the gravity.

if not is_on_floor():

velocity += get_gravity() * delta

# Handle jump.

if Input.is_action_just_pressed("jump") and is_on_floor():

velocity.y = JUMP_VELOCITY

# Creating the animation for jumping

sprite_2d.animation = "jumping"

# Using the keyboard to press left or right

var direction := Input.get_axis("left", "right")

if direction:

velocity.x = direction * SPEED

else:

velocity.x = move_toward(velocity.x, 12, SPEED)

move_and_slide()

#changing the characters to face left r right based on movement

var isLeft = velocity.x < 0

sprite_2d.flip_h = isLeft


WATERMELLON COLLECTION SCRIPT

extends Area2D

@onready var game_manager: Node = %GameManager

func _on_body_entered(body):

queue_free()

game_manager.add_point()


POINT COLLECTION 

extends Node

var points = 0

func add_point():

points += 1

print(points)

Files

2dgameeee.zip Play in browser
Dec 04, 2024

Leave a comment

Log in with itch.io to leave a comment.