0% found this document useful (0 votes)
43 views1 page

Jumping Script

This document contains a simple Pygame script for a 2D game that allows player movement and jumping. It initializes the game window, sets up player controls for left and right movement, and implements jumping mechanics with gravity. The game loop continuously updates the screen and handles user input until the game is closed.

Uploaded by

amine. exeyt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views1 page

Jumping Script

This document contains a simple Pygame script for a 2D game that allows player movement and jumping. It initializes the game window, sets up player controls for left and right movement, and implements jumping mechanics with gravity. The game loop continuously updates the screen and handles user input until the game is closed.

Uploaded by

amine. exeyt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import pygame

import sys

# Initialize Pygame
[Link]()

# Screen setup
width, height = 800, 600
screen = [Link].set_mode((width, height))
[Link].set_caption("2D Movement with Jumping")

# Colors
white = (255, 255, 255)
blue = (0, 0, 255)

# Player setup
player_size = 50
player_x = width // 2
player_y = height - player_size
player_speed = 5
velocity_y = 0
gravity = 1
jump_force = -15
on_ground = True

# Game loop
clock = [Link]()
running = True
while running:
[Link](white)

for event in [Link]():


if [Link] == [Link]:
running = False

# Key press handling


keys = [Link].get_pressed()
if keys[pygame.K_LEFT]:
player_x -= player_speed
if keys[pygame.K_RIGHT]:
player_x += player_speed

# Jumping
if keys[pygame.K_SPACE] and on_ground:
velocity_y = jump_force
on_ground = False

# Apply gravity
velocity_y += gravity
player_y += velocity_y

# Ground collision
if player_y >= height - player_size

You might also like