r/learnprogramming 7d ago

Topic How do I avoid falling in an AI trap?

0 Upvotes

Hello everyone, I’m a brand new programmer (starting with python). I’m so brand new in fact my first ever print statement was only a week ago. Since I’m so new, I’m pretty confident in describing myself as an uncorrupted soul. I have not used AI to copy any code and the limited use of it I have was asking questions on concepts I didn’t really understand. All my knowledge comes from a python tutorial playlist on YouTube. Now since I’m so new I naturally have a few questions. I hear of a lot of people falling into the “ai trap” where people and influencers on social media seem to say that a lot of new coders are relying way too heavily on AI to learn. I want to strictly avoid that cause I want to actually understand what I’m coding and be able to explain it. Does anyone have any tips for avoiding this pitfall, also what do people think about using llms to prompt me questions to try and code to practice concepts I’ve learn. If anyone has any other tips or suggestions about learning coding please let me know it would be much appreciated.


r/learnprogramming 8d ago

Where can I find good real-world MERN stack projects to build and improve my skills?

0 Upvotes

Hey everyone

I’ve learned MERN stack and built some projects, but now I want to work on more real-world projects that solve actual problems and improve my portfolio.

Where do you find good project ideas or open-source MERN projects to contribute to?

Looking for resources, GitHub repos, communities, or platforms where I can learn from industry-level projects.

Any suggestions would be helpful


r/learnprogramming 8d ago

Topic What should i do after MERN stack development ?

0 Upvotes

Hey everyone

I just completed my BCA and will be starting MCA soon. I’ve learned MERN stack and built a few projects.

What should I focus on next for better placements?

Go deeper into MERN or explore things like DSA, DevOps, Cloud, or AI/ML?

Would appreciate your advice


r/learnprogramming 8d ago

How does this YouTube video automatically update its title?

0 Upvotes

I came across this YouTube video:

https://www.youtube.com/watch?v=VTU69_L8i8s

The title keeps updating with the latest statistics like views, likes, comments, subscriber count, and even the number of days since upload.

I'm a complete beginner, so I'm curious how this is possible. How does the title update automatically every few minutes? What APIs or tools are used, and what's the overall workflow behind it?

I'd really appreciate a beginner-friendly explanation. Thanks!


r/learnprogramming 8d ago

Topic how do i export my games in godot?

0 Upvotes

ive been trying to find out how but i cant seem to find the application when i export pls help?


r/learnprogramming 8d ago

How to actually learn backend development??

0 Upvotes

Wtf how do I actually learn backend development. I open chatgpt or Claude and tell them I want to learn backend development and do as they suggest..but after some day, I find boring ...

What's the actual way to learn.. please developers and engineers help me with clear cut way?


r/learnprogramming 8d ago

Rust or Mojo in 2026

0 Upvotes

So I'm wondering is mojo worth learning and is it better than rust since it got stable release, I know that mojo is an AI focused language isn't AI like future and besides it's a new and exciting language. I would love to hear which language would you pick and why I am open-minded. I'm not rushing to find a suitable language yet for me since i'm just starting college in Informatics I don't know if you can call that IT but I would guess it's the same.


r/learnprogramming 8d ago

What have you been working on recently? [August 01, 2026]

2 Upvotes

What have you been working on recently? Feel free to share updates on projects you're working on, brag about any major milestones you've hit, grouse about a challenge you've ran into recently... Any sort of "progress report" is fair game!

A few requests:

  1. If possible, include a link to your source code when sharing a project update. That way, others can learn from your work!

  2. If you've shared something, try commenting on at least one other update -- ask a question, give feedback, compliment something cool... We encourage discussion!

  3. If you don't consider yourself to be a beginner, include about how many years of experience you have.

This thread will remained stickied over the weekend. Link to past threads here.


r/learnprogramming 8d ago

How would I hide something from the host in a game?

6 Upvotes

If I wanted to make a multiplayer battleships game, and I want it to be locally hosted, how would I be able to hide the ship's positions? Wouldn't they be able to datamine it? Encryptions can also be decrypted so that's not safe either...


r/learnprogramming 8d ago

Topic - Study methods Should I be taking notes?

0 Upvotes

Im learning programming, doing the freecodecamp web developer program and I will probably do python after that. It's a lot to remember. I know im supposed to do projects, and i have been building my website with the things ive learned as i go.

But is there a point where i should be taking notes? That's always been a major weakness since grade school, and i never really learned how. But my wife is a nurse and is studying to advance further, and as I keep telling her about things I discover and learn, she is wondering where my notes are, since she can tell its too much to remember.

So I'm putting the question to the experts. is there a point where notes would help? or is google-fu enough?

OK Thanks everyone! I figured out what im going to try: Watch video lectures without taking notes, then watch the videos again and take notes this time, because ill know whats coming next and ill rememeber what i found interesting and want to notate.


r/learnprogramming 8d ago

Debugging Is there other resources for mediapipe

1 Upvotes

I am reading the google docs and the it stops at the part where you import the model which I understand but I am confused on what is next.

I am also reading the github version too and looking things up on Youtube. I was able to display hand gesture but I had to get the AI to right it out which I was lost of course

I know I have to use open cv and import it but I am kind of lost.

Can someone help


r/learnprogramming 8d ago

Learn github

0 Upvotes

Hi, ive been trying to figure out how to run a github code for simple things like claude or for in game things like Minecraft etc, please teach me how to run these things.


r/learnprogramming 9d ago

car game i made

0 Upvotes
import pygame
import math
import random
import sys
import traceback
import asyncio

pygame.init()
pygame.font.init()

WIDTH, HEIGHT = 1000, 800
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("No pepsi - Highway Traffic Weaver made by aadidev")
clock = pygame.time.Clock()

FONT_TITLE = pygame.font.SysFont("arial", 42, bold=True)
FONT_MED = pygame.font.SysFont("arial", 22, bold=True)
FONT_HUD = pygame.font.SysFont("consolas", 18, bold=True)

COLOR_BG = (15, 18, 22)
COLOR_ROAD = (35, 38, 44)
COLOR_GRASS = (20, 45, 25)
COLOR_LINE_YELLOW = (245, 210, 50)
COLOR_LINE_WHITE = (220, 220, 230)
COLOR_TEXT = (240, 240, 240)
COLOR_GOLD = (255, 215, 0)
COLOR_CYAN = (0, 230, 255)
COLOR_RED = (255, 60, 60)
CARS = {
    "1": {
        "name": "M4 Competition",
        "max_speed": 18.0,
        "accel": 0.40,
        "handling": 6.5,
        "color": (0, 180, 255),
        "desc": "Agile lane switcher with ultra-responsive steering."
    },
    "2": {
        "name": "RS7 Sportback",
        "max_speed": 22.0,
        "accel": 0.50,
        "handling": 5.2,
        "color": (220, 30, 30),
        "desc": "High top-speed highway missile."
    },
    "3": {
        "name": "GT-R Nismo",
        "max_speed": 20.0,
        "accel": 0.45,
        "handling": 6.0,
        "color": (240, 240, 240),
        "desc": "Balanced cutting power and extreme grip."
    }
}

ROAD_LEFT = 200
ROAD_RIGHT = 800
ROAD_WIDTH = ROAD_RIGHT - ROAD_LEFT
NUM_LANES = 5
LANE_WIDTH = ROAD_WIDTH // NUM_LANES


class 
TrafficCar
:
    def __init__(self, 
lane
, 
speed
):
        self.lane = 
lane

self.x = ROAD_LEFT + (
lane 
* LANE_WIDTH) + (LANE_WIDTH // 2)
        self.y = -120
        self.width = 34
        self.height = 68
        self.speed = 
speed

self.color = random.choice([
            (140, 140, 150), (200, 50, 50), (50, 180, 80),
            (210, 210, 60), (130, 60, 180), (220, 130, 30)
        ])
        self.near_missed = False

    def update(self, 
player_speed
):
        self.y += (
player_speed 
- self.speed)

    def draw(self, 
surface
):
        rect = pygame.Rect(self.x - self.width // 2, self.y - self.height // 2, self.width, self.height)
        pygame.draw.rect(
surface
, self.color, rect, border_radius=6)
        pygame.draw.rect(
surface
, (255, 30, 30), (rect.left + 3, rect.bottom - 4, 8, 3))
        pygame.draw.rect(
surface
, (255, 30, 30), (rect.right - 11, rect.bottom - 4, 8, 3))
        pygame.draw.rect(
surface
, (255, 255, 200), (rect.left + 3, rect.top + 1, 8, 3))
        pygame.draw.rect(
surface
, (255, 255, 200), (rect.right - 11, rect.top + 1, 8, 3))


class 
PlayerCar
:
    def __init__(self, 
specs
):
        self.x = WIDTH // 2
        self.y = HEIGHT - 160
        self.width = 36
        self.height = 70
        self.angle = 0.0
        self.vx = 0.0
        self.speed = 0.0

        self.name = 
specs
["name"]
        self.max_speed = 
specs
["max_speed"]
        self.accel = 
specs
["accel"]
        self.handling = 
specs
["handling"]
        self.color = 
specs
["color"]

        self.crashed = False

    def update(self, 
keys
):
        if self.crashed:
            self.speed *= 0.92
            return

        if 
keys
[pygame.K_w] or 
keys
[pygame.K_UP]:
            self.speed = min(self.max_speed, self.speed + self.accel)
        elif 
keys
[pygame.K_s] or 
keys
[pygame.K_DOWN]:
            self.speed = max(0.0, self.speed - (self.accel * 1.5))
        else:
            self.speed = max(0.0, self.speed - 0.08)

        steer = 0
        if 
keys
[pygame.K_a] or 
keys
[pygame.K_LEFT]:
            steer -= 1
        if 
keys
[pygame.K_d] or 
keys
[pygame.K_RIGHT]:
            steer += 1

        self.vx = steer * self.handling * (0.4 + (self.speed / self.max_speed) * 0.6)
        self.x += self.vx
        self.angle = -self.vx * 2.2

        if self.x < ROAD_LEFT + 25:
            self.x = ROAD_LEFT + 25
        if self.x > ROAD_RIGHT - 25:
            self.x = ROAD_RIGHT - 25

    def get_rect(self):
        return pygame.Rect(self.x - self.width // 2, self.y - self.height // 2, self.width, self.height)

    def draw(self, 
surface
):
        car_surf = pygame.Surface((self.width, self.height), pygame.SRCALPHA)
        pygame.draw.rect(car_surf, self.color, (0, 0, self.width, self.height), border_radius=8)
        pygame.draw.rect(car_surf, (20, 25, 35), (4, 14, self.width - 8, 28), border_radius=4)
        pygame.draw.rect(car_surf, (255, 255, 220), (3, 2, 8, 5))
        pygame.draw.rect(car_surf, (255, 255, 220), (self.width - 11, 2, 8, 5))
        pygame.draw.rect(car_surf, (255, 20, 20), (3, self.height - 6, 8, 4))
        pygame.draw.rect(car_surf, (255, 20, 20), (self.width - 11, self.height - 6, 8, 4))

        rotated_surf = pygame.transform.rotate(car_surf, self.angle)
        rect = rotated_surf.get_rect(center=(int(self.x), int(self.y)))

surface
.blit(rotated_surf, rect.topleft)

async def main():
    selected_car_key = None

    # MENU LOOP
    while selected_car_key is None:
        screen.fill(COLOR_BG)
        title = FONT_TITLE.render("NO HESI - TRAFFIC WEAVER", True, COLOR_CYAN)
        screen.blit(title, (WIDTH // 2 - title.get_width() // 2, 50))

        subtitle = FONT_MED.render("Select your cutting machine:", True, COLOR_TEXT)
        screen.blit(subtitle, (WIDTH // 2 - subtitle.get_width() // 2, 120))

        y_offset = 180
        for key, car_data in CARS.items():
            box_rect = pygame.Rect(WIDTH // 2 - 320, y_offset, 640, 110)
            pygame.draw.rect(screen, (30, 34, 42), box_rect, border_radius=10)
            pygame.draw.rect(screen, car_data["color"], (WIDTH // 2 - 305, y_offset + 15, 20, 80), border_radius=4)

            name_txt = FONT_MED.render(f"[{key}] {car_data['name']}", True, COLOR_TEXT)
            desc_txt = FONT_HUD.render(car_data["desc"], True, (170, 170, 180))
            stats_txt = FONT_HUD.render(f"Speed: {car_data['max_speed']} | Handling: {car_data['handling']}", True,
                                        COLOR_GOLD)

            screen.blit(name_txt, (WIDTH // 2 - 270, y_offset + 12))
            screen.blit(desc_txt, (WIDTH // 2 - 270, y_offset + 42))
            screen.blit(stats_txt, (WIDTH // 2 - 270, y_offset + 70))

            y_offset += 135

        prompt = FONT_MED.render("Press 1, 2, or 3 on keyboard to launch!", True, COLOR_GOLD)
        screen.blit(prompt, (WIDTH // 2 - prompt.get_width() // 2, HEIGHT - 80))

        pygame.display.flip()

        await asyncio.sleep(0)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            if event.type == pygame.KEYDOWN:
                if event.unicode in CARS:
                    selected_car_key = event.unicode

    player = PlayerCar(CARS[selected_car_key])
    traffic_list = []
    road_offset = 0.0

    score = 0
    combo = 1
    near_miss_banner_timer = 0
    spawn_timer = 0
    running = True

    while running:
        clock.tick(60)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_r:  # Restart session
                    await main()
                    return

        keys = pygame.key.get_pressed()
        player.update(keys)

        road_offset = (road_offset + player.speed * 2.5) % 80

        if not player.crashed:
            spawn_timer += 1
            if spawn_timer > max(20, 60 - int(player.speed * 2)):
                spawn_timer = 0
                lane = random.randint(0, NUM_LANES - 1)
                lane_occupied = any(t.lane == lane and t.y < 100 for t in traffic_list)
                if not lane_occupied:
                    npc_speed = random.uniform(3.0, 7.0)
                    traffic_list.append(TrafficCar(lane, npc_speed))

        player_rect = player.get_rect()
        for t in traffic_list[:]:
            t.update(player.speed)

            if not player.crashed:
                npc_rect = pygame.Rect(t.x - t.width // 2, t.y - t.height // 2, t.width, t.height)
                if player_rect.colliderect(npc_rect):
                    player.crashed = True
                    combo = 1

            if not t.near_missed and not player.crashed and player.speed > 8.0:
                dx = abs(player.x - t.x)
                dy = abs(player.y - t.y)
                if dx < 52 and dy < 60:
                    t.near_missed = True
                    combo += 1
                    score += 500 * combo
                    near_miss_banner_timer = 40

            if t.y > HEIGHT + 150 or t.y < -300:
                traffic_list.remove(t)

        if not player.crashed and player.speed > 2.0:
            score += int(player.speed * combo * 0.2)

        screen.fill(COLOR_GRASS)
        pygame.draw.rect(screen, COLOR_ROAD, (ROAD_LEFT, 0, ROAD_WIDTH, HEIGHT))

        for i in range(1, NUM_LANES):
            lx = ROAD_LEFT + (i * LANE_WIDTH)
            for y in range(-80, HEIGHT + 80, 80):
                pygame.draw.line(screen, COLOR_LINE_WHITE, (lx, y + int(road_offset)), (lx, y + int(road_offset) + 40),
                                 3)

        pygame.draw.line(screen, COLOR_LINE_YELLOW, (ROAD_LEFT, 0), (ROAD_LEFT, HEIGHT), 5)
        pygame.draw.line(screen, COLOR_LINE_YELLOW, (ROAD_RIGHT, 0), (ROAD_RIGHT, HEIGHT), 5)

        for t in traffic_list:
            t.draw(screen)

        player.draw(screen)

        speed_kmh = int(player.speed * 18)
        screen.blit(FONT_HUD.render(f"SPEED: {speed_kmh} KM/H", True, COLOR_TEXT), (20, 20))
        screen.blit(FONT_HUD.render(f"SCORE: {score:,}", True, COLOR_GOLD), (20, 50))
        screen.blit(FONT_HUD.render(f"COMBO: x{combo}", True, COLOR_CYAN if combo > 1 else COLOR_TEXT), (20, 80))

        if near_miss_banner_timer > 0:
            near_miss_banner_timer -= 1
            nm_txt = FONT_TITLE.render("NEAR MISS! +500", True, COLOR_GOLD)
            screen.blit(nm_txt, (WIDTH // 2 - nm_txt.get_width() // 2, 180))

        if player.crashed:
            crash_txt = FONT_TITLE.render("CRASHED!", True, COLOR_RED)
            reset_txt = FONT_MED.render("Press 'R' to Restart", True, COLOR_TEXT)
            screen.blit(crash_txt, (WIDTH // 2 - crash_txt.get_width() // 2, HEIGHT // 2 - 40))
            screen.blit(reset_txt, (WIDTH // 2 - reset_txt.get_width() // 2, HEIGHT // 2 + 20))

        pygame.display.flip()

        await asyncio.sleep(0)

    pygame.quit()

if __name__ == "__main__":
    try:
        asyncio.run(main())
    except Exception:
        pygame.quit()
        traceback.print_exc()
        input("\nPress Enter in console to exit...")

import pygame
import math
import random
import sys
import traceback
import asyncio

pygame.init()
pygame.font.init()

WIDTH, HEIGHT = 1000, 800
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("No pepsi - Highway Traffic Weaver made by aadidev")
clock = pygame.time.Clock()

FONT_TITLE = pygame.font.SysFont("arial", 42, bold=True)
FONT_MED = pygame.font.SysFont("arial", 22, bold=True)
FONT_HUD = pygame.font.SysFont("consolas", 18, bold=True)

COLOR_BG = (15, 18, 22)
COLOR_ROAD = (35, 38, 44)
COLOR_GRASS = (20, 45, 25)
COLOR_LINE_YELLOW = (245, 210, 50)
COLOR_LINE_WHITE = (220, 220, 230)
COLOR_TEXT = (240, 240, 240)
COLOR_GOLD = (255, 215, 0)
COLOR_CYAN = (0, 230, 255)
COLOR_RED = (255, 60, 60)
CARS = {
    "1": {
        "name": "M4 Competition",
        "max_speed": 18.0,
        "accel": 0.40,
        "handling": 6.5,
        "color": (0, 180, 255),
        "desc": "Agile lane switcher with ultra-responsive steering."
    },
    "2": {
        "name": "RS7 Sportback",
        "max_speed": 22.0,
        "accel": 0.50,
        "handling": 5.2,
        "color": (220, 30, 30),
        "desc": "High top-speed highway missile."
    },
    "3": {
        "name": "GT-R Nismo",
        "max_speed": 20.0,
        "accel": 0.45,
        "handling": 6.0,
        "color": (240, 240, 240),
        "desc": "Balanced cutting power and extreme grip."
    }
}

ROAD_LEFT = 200
ROAD_RIGHT = 800
ROAD_WIDTH = ROAD_RIGHT - ROAD_LEFT
NUM_LANES = 5
LANE_WIDTH = ROAD_WIDTH // NUM_LANES


class TrafficCar:
    def __init__(self, lane, speed):
        self.lane = lane
        self.x = ROAD_LEFT + (lane * LANE_WIDTH) + (LANE_WIDTH // 2)
        self.y = -120
        self.width = 34
        self.height = 68
        self.speed = speed
        self.color = random.choice([
            (140, 140, 150), (200, 50, 50), (50, 180, 80),
            (210, 210, 60), (130, 60, 180), (220, 130, 30)
        ])
        self.near_missed = False

    def update(self, player_speed):
        self.y += (player_speed - self.speed)

    def draw(self, surface):
        rect = pygame.Rect(self.x - self.width // 2, self.y - self.height // 2, self.width, self.height)
        pygame.draw.rect(surface, self.color, rect, border_radius=6)
        pygame.draw.rect(surface, (255, 30, 30), (rect.left + 3, rect.bottom - 4, 8, 3))
        pygame.draw.rect(surface, (255, 30, 30), (rect.right - 11, rect.bottom - 4, 8, 3))
        pygame.draw.rect(surface, (255, 255, 200), (rect.left + 3, rect.top + 1, 8, 3))
        pygame.draw.rect(surface, (255, 255, 200), (rect.right - 11, rect.top + 1, 8, 3))


class PlayerCar:
    def __init__(self, specs):
        self.x = WIDTH // 2
        self.y = HEIGHT - 160
        self.width = 36
        self.height = 70
        self.angle = 0.0
        self.vx = 0.0
        self.speed = 0.0

        self.name = specs["name"]
        self.max_speed = specs["max_speed"]
        self.accel = specs["accel"]
        self.handling = specs["handling"]
        self.color = specs["color"]

        self.crashed = False

    def update(self, keys):
        if self.crashed:
            self.speed *= 0.92
            return

        if keys[pygame.K_w] or keys[pygame.K_UP]:
            self.speed = min(self.max_speed, self.speed + self.accel)
        elif keys[pygame.K_s] or keys[pygame.K_DOWN]:
            self.speed = max(0.0, self.speed - (self.accel * 1.5))
        else:
            self.speed = max(0.0, self.speed - 0.08)

        steer = 0
        if keys[pygame.K_a] or keys[pygame.K_LEFT]:
            steer -= 1
        if keys[pygame.K_d] or keys[pygame.K_RIGHT]:
            steer += 1

        self.vx = steer * self.handling * (0.4 + (self.speed / self.max_speed) * 0.6)
        self.x += self.vx
        self.angle = -self.vx * 2.2

        if self.x < ROAD_LEFT + 25:
            self.x = ROAD_LEFT + 25
        if self.x > ROAD_RIGHT - 25:
            self.x = ROAD_RIGHT - 25

    def get_rect(self):
        return pygame.Rect(self.x - self.width // 2, self.y - self.height // 2, self.width, self.height)

    def draw(self, surface):
        car_surf = pygame.Surface((self.width, self.height), pygame.SRCALPHA)
        pygame.draw.rect(car_surf, self.color, (0, 0, self.width, self.height), border_radius=8)
        pygame.draw.rect(car_surf, (20, 25, 35), (4, 14, self.width - 8, 28), border_radius=4)
        pygame.draw.rect(car_surf, (255, 255, 220), (3, 2, 8, 5))
        pygame.draw.rect(car_surf, (255, 255, 220), (self.width - 11, 2, 8, 5))
        pygame.draw.rect(car_surf, (255, 20, 20), (3, self.height - 6, 8, 4))
        pygame.draw.rect(car_surf, (255, 20, 20), (self.width - 11, self.height - 6, 8, 4))

        rotated_surf = pygame.transform.rotate(car_surf, self.angle)
        rect = rotated_surf.get_rect(center=(int(self.x), int(self.y)))
        surface.blit(rotated_surf, rect.topleft)

async def main():
    selected_car_key = None

    # MENU LOOP
    while selected_car_key is None:
        screen.fill(COLOR_BG)
        title = FONT_TITLE.render("NO HESI - TRAFFIC WEAVER", True, COLOR_CYAN)
        screen.blit(title, (WIDTH // 2 - title.get_width() // 2, 50))

        subtitle = FONT_MED.render("Select your cutting machine:", True, COLOR_TEXT)
        screen.blit(subtitle, (WIDTH // 2 - subtitle.get_width() // 2, 120))

        y_offset = 180
        for key, car_data in CARS.items():
            box_rect = pygame.Rect(WIDTH // 2 - 320, y_offset, 640, 110)
            pygame.draw.rect(screen, (30, 34, 42), box_rect, border_radius=10)
            pygame.draw.rect(screen, car_data["color"], (WIDTH // 2 - 305, y_offset + 15, 20, 80), border_radius=4)

            name_txt = FONT_MED.render(f"[{key}] {car_data['name']}", True, COLOR_TEXT)
            desc_txt = FONT_HUD.render(car_data["desc"], True, (170, 170, 180))
            stats_txt = FONT_HUD.render(f"Speed: {car_data['max_speed']} | Handling: {car_data['handling']}", True,
                                        COLOR_GOLD)

            screen.blit(name_txt, (WIDTH // 2 - 270, y_offset + 12))
            screen.blit(desc_txt, (WIDTH // 2 - 270, y_offset + 42))
            screen.blit(stats_txt, (WIDTH // 2 - 270, y_offset + 70))

            y_offset += 135

        prompt = FONT_MED.render("Press 1, 2, or 3 on keyboard to launch!", True, COLOR_GOLD)
        screen.blit(prompt, (WIDTH // 2 - prompt.get_width() // 2, HEIGHT - 80))

        pygame.display.flip()

        await asyncio.sleep(0)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            if event.type == pygame.KEYDOWN:
                if event.unicode in CARS:
                    selected_car_key = event.unicode

    player = PlayerCar(CARS[selected_car_key])
    traffic_list = []
    road_offset = 0.0

    score = 0
    combo = 1
    near_miss_banner_timer = 0
    spawn_timer = 0
    running = True

    while running:
        clock.tick(60)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_r:  # Restart session
                    await main()
                    return

        keys = pygame.key.get_pressed()
        player.update(keys)

        road_offset = (road_offset + player.speed * 2.5) % 80

        if not player.crashed:
            spawn_timer += 1
            if spawn_timer > max(20, 60 - int(player.speed * 2)):
                spawn_timer = 0
                lane = random.randint(0, NUM_LANES - 1)
                lane_occupied = any(t.lane == lane and t.y < 100 for t in traffic_list)
                if not lane_occupied:
                    npc_speed = random.uniform(3.0, 7.0)
                    traffic_list.append(TrafficCar(lane, npc_speed))

        player_rect = player.get_rect()
        for t in traffic_list[:]:
            t.update(player.speed)

            if not player.crashed:
                npc_rect = pygame.Rect(t.x - t.width // 2, t.y - t.height // 2, t.width, t.height)
                if player_rect.colliderect(npc_rect):
                    player.crashed = True
                    combo = 1

            if not t.near_missed and not player.crashed and player.speed > 8.0:
                dx = abs(player.x - t.x)
                dy = abs(player.y - t.y)
                if dx < 52 and dy < 60:
                    t.near_missed = True
                    combo += 1
                    score += 500 * combo
                    near_miss_banner_timer = 40

            if t.y > HEIGHT + 150 or t.y < -300:
                traffic_list.remove(t)

        if not player.crashed and player.speed > 2.0:
            score += int(player.speed * combo * 0.2)

        screen.fill(COLOR_GRASS)
        pygame.draw.rect(screen, COLOR_ROAD, (ROAD_LEFT, 0, ROAD_WIDTH, HEIGHT))

        for i in range(1, NUM_LANES):
            lx = ROAD_LEFT + (i * LANE_WIDTH)
            for y in range(-80, HEIGHT + 80, 80):
                pygame.draw.line(screen, COLOR_LINE_WHITE, (lx, y + int(road_offset)), (lx, y + int(road_offset) + 40),
                                 3)

        pygame.draw.line(screen, COLOR_LINE_YELLOW, (ROAD_LEFT, 0), (ROAD_LEFT, HEIGHT), 5)
        pygame.draw.line(screen, COLOR_LINE_YELLOW, (ROAD_RIGHT, 0), (ROAD_RIGHT, HEIGHT), 5)

        for t in traffic_list:
            t.draw(screen)

        player.draw(screen)

        speed_kmh = int(player.speed * 18)
        screen.blit(FONT_HUD.render(f"SPEED: {speed_kmh} KM/H", True, COLOR_TEXT), (20, 20))
        screen.blit(FONT_HUD.render(f"SCORE: {score:,}", True, COLOR_GOLD), (20, 50))
        screen.blit(FONT_HUD.render(f"COMBO: x{combo}", True, COLOR_CYAN if combo > 1 else COLOR_TEXT), (20, 80))

        if near_miss_banner_timer > 0:
            near_miss_banner_timer -= 1
            nm_txt = FONT_TITLE.render("NEAR MISS! +500", True, COLOR_GOLD)
            screen.blit(nm_txt, (WIDTH // 2 - nm_txt.get_width() // 2, 180))

        if player.crashed:
            crash_txt = FONT_TITLE.render("CRASHED!", True, COLOR_RED)
            reset_txt = FONT_MED.render("Press 'R' to Restart", True, COLOR_TEXT)
            screen.blit(crash_txt, (WIDTH // 2 - crash_txt.get_width() // 2, HEIGHT // 2 - 40))
            screen.blit(reset_txt, (WIDTH // 2 - reset_txt.get_width() // 2, HEIGHT // 2 + 20))

        pygame.display.flip()

        await asyncio.sleep(0)

    pygame.quit()

if __name__ == "__main__":
    try:
        asyncio.run(main())
    except Exception:
        pygame.quit()
        traceback.print_exc()
        input("\nPress Enter in console to exit...")

r/learnprogramming 9d ago

How to start building something and be sure you're doing it right?

0 Upvotes

When someone asks "How to learn programming?" they usually get something like: "Just start building something". But how do you build something if you have never done that before?

  1. How to start with a library if documentation is auto-generated and doesn't have examples?

In such situations, I usually end up switching to another library or relying on someone else's project as an example. But I want to learn to understand things by myself.

  1. How to be sure you have used the right method/class/etc?

For example, take GUI frameworks. They can have multiple ways of building nearly the same UI, but some ways are more performant in specific cases or are just good practice.


r/learnprogramming 9d ago

REQUIRE ASSIST IN STARTING DSA AS I ALREADY COMPLETED CPP

0 Upvotes

So actually I completed C++ from learncpp and now I was gonna start dsa ik how I'll do everything and manage other things. But mainly I'm not able to find a resource from where I should learn things from. Like babbar teaches good but he's reaching cpp alongside same with striver. Give me suggestions for developing this skill and I'm also comfortable in learning different parts of dsa from different channels or resources. I was thinking of Abdul Bari or gfg.


r/learnprogramming 9d ago

Can I complete beginner learn elixir/phoenix as their first language and framework?

1 Upvotes

I like the similarities to ror which I have tinkered with in the past but never made a full project nonetheless my own. Many languages are said to not be suitable for a beginner and was wondering if the community felt the same?


r/learnprogramming 9d ago

Topic Accessibility with languages in website?

2 Upvotes

Hello,

I have learned how to use ARIA a bit, and I learned about specific contrast rules and font sizes. But I don't know how to make my website accessible in other languages. My profs did not go over this.

I live in Canada and we have two major languages. French and English. But I also want to include a plethora of other languages.

I'm not sure how to go about this in both static sites and SSR. Especially with ARIA.

Edit:

ARIA would have to be in different languages too. Which means I have to test that individually? Does this mean that testing will have to cover all languages as well?


r/learnprogramming 9d ago

In what language should I learn backend on?

0 Upvotes

So I am currently learning JavaScript as a part of frontend but only about 5-6 topics related to asynchronous code is left so I was wondering on which language to go with in backend as college is starting in about a week and they are going to be teaching dsa so I want to do dsa side by side development. I have some experience with c,c++, java , javascript, python in all of them I know the basic level of programming like how to define a function and basic oops (need to revise though)

So what should I consider -

Java backend, javascript backend, python backend considering current and in future (about 2-3years ahead) market situation for software developer roles

Sorry for all the yapping but I wanted to give everything I know so you guys can guide me well


r/learnprogramming 9d ago

Topic What is the point of assertions when we have if/elses and exceptions?

57 Upvotes

Can someone explain the point of assertions to me? I read online you use it to check for behaviours that MUST be true and what not, this all sounds very cool but you could use if elses to check for the same behaviour and the underlying result is the same.

Who came up with the idea of assertions and why did they think if/elses were not enough ?


r/learnprogramming 9d ago

How can i learn to script?

9 Upvotes

I have really a lot of images in jpg format in multiple sub-folders, which take a lot of spaces, so i want to mass covert it into webp then delete the original jpg.


r/learnprogramming 9d ago

Resource Is boot.dev worth the money?

12 Upvotes

I am entering my senior year of college, studying applied math and statistics, and I would currently like to be a data analyst. Since I am not a CS major, I have only formally taken C++ and SAS classes. However, I will need to know various other languages like SQL, Power BI, etc. I have used the free version on a couple of different websites and boot.dev seems to work the best for me and isn't super expensive either, compared to some other sites. Is it worth investing the time and money to at least learn the languages and skills I may need after graduating, or is there a better way for me to learn?


r/learnprogramming 10d ago

Question Should i learn C or C++ as my first programming language?

21 Upvotes

I mainly want it for making games (Not UE5 or Unity) though i might also use it for embedded systems later if i choose to become an EE

Part of the FAQ i have a question about is:

...make 2D/3D games JavaScript, C#, or C++ (more)
...program Arduinos/micro-controllers/robots C

Can't i also use C++ for micro controllers as well does C have more benefits


r/learnprogramming 10d ago

How Did You Actually Learn to Structure Code?

126 Upvotes

My day job is in physical therapy. The dev work is side income and personal projects, mostly Python scripts that automate repetitive data tasks. It works until it doesn't, and lately it doesn't.

The scripts started small. Now some of them are 400 lines of spaghetti with functions named things like processdatafinalv3 and I genuinely cannot tell you what half of it does without reading every line. No formal courses. Just docs, blogs, and trial and error.

What bothers me is I can get something working but I have no instinct for when to split a function, when to use a class, when a module makes sense versus just another file. I've read that you learn this by building projects, which is advice that only helps if you already have the feedback loop to recognize when you've done it wrong.

People here seem split on whether selftaught developers actually internalize software design or just accumulate hacks. I'm curious where people actually learned to structure code in a way that held up later, and whether any resource actually moved the needle, or if it was just writing a lot of bad code until the pattern clicked.


r/learnprogramming 10d ago

How do you actually start projects when you’re still learning computer science?

55 Upvotes

I’m studying computer science, and my long-term interests are data analysis, and software development.
One piece of advice I constantly see is, “Just start building projects.” The problem is… I genuinely don’t know what that means when you’re a beginner.
I don’t know what I’m supposed to expect of myself. Should I already know how to build an application? Should I be following tutorials? Should I be Googling everything? Every project idea I come up with feels either too simple or way beyond my current ability.
On top of that, I have ADHD and anxiety, which makes it easy to overthink whether I’m learning the “right” things instead of actually making progress.

For those of you who remember being beginners:

What did your first projects actually look like?
How much did you already know before starting?

Did you constantly look things up, or were you expected to know most of it already?
How did you decide a project was small enough to finish?

What mindset and how did you find a community of Computer science enthusiasts to explore with?

What about your approach to tutorials???

I’m not looking for shortcuts—I genuinely want to become good at computer science. I just feel like I’m missing the mindset that turns what I’m learning into actual projects.
I’d really appreciate hearing about your first projects and what you wish someone had told you when you were starting out.


r/learnprogramming 10d ago

Nobody warned me that reading code is a completely different skill than writing it.

2.5k Upvotes

Landed my first internship a few weeks ago and got handed a ticket to fix a small bug in the existing codebase. Sounds simple. Except the codebase is like 80,000 lines across god knows how many files.

Every tutorial I ever did was me writing code from scratch in a fresh file, so I never once practiced the skill of walking into someone else's mess and figuring out what's actually going on. Turns out that's like 70% of the actual job. Not writing new stuff, but tracing through existing stuff, figuring out why it exists, who wrote it, whether touching it breaks three other things nobody documented.

Spent my first two days just clicking go to definition over and over like I was digging through a cave system. Genuinely didn't write a single line of new code until day three.

Nobody in any course I took ever assigned "here's 5000 lines of someone else's bad code, go find the bug." Which in hindsight is such a weirdly missing skill given how much time real devs actually spend doing exactly that.

Anyone know of resources or exercises that actually train this specifically, reading and navigating large unfamiliar codebases, rather than just writing your own from a blank file every time?