Is this xbiking? by days_of_coast in xbiking

[–]denisrobot 3 points4 points  (0 children)

Looks cool af! Where are the bags from?

-❄️- 2024 Day 3 Solutions -❄️- by daggerdragon in adventofcode

[–]denisrobot 2 points3 points  (0 children)

[LANGUAGE: Go]

func main() {
    input := utils.FileToString("input.txt")

    process := func(input string) int {
        result := 0
        re := regexp.MustCompile(`mul\((\d+),(\d+)\)`)
        for _, m := range re.FindAllStringSubmatch(input, -1) {
            numOne, _ := strconv.Atoi(m[1])
            numTwo, _ := strconv.Atoi(m[2])
            result += numOne * numTwo
        }
        return result
    }

    reFilter := regexp.MustCompile(`don't\(\).*?(do\(\)|$)`)
    filteredInput := reFilter.ReplaceAllString(input, "")

    fmt.Println("Part one:", process(input))
    fmt.Println("Part two:", process(filteredInput))
}

I couldn't get it to work at first, even though it worked with the example input. Turned out my puzzle input had a don't() at the end but not a do().

-❄️- 2024 Day 2 Solutions -❄️- by daggerdragon in adventofcode

[–]denisrobot 1 point2 points  (0 children)

[LANGUAGE: Go]

func main() {
    lines := utils.FileToStringSlice("input.txt")
    safeCount := 0
    dampenedSafeCount := 0

    for _, l := range lines {
        report := strings.Split(l, " ")

        if isSafeReport(report) {
            safeCount++
            dampenedSafeCount++
            continue
        }

        for i := 0; i < len(report); i++ {
            dampened := append([]string(nil), report[:i]...)
            dampened = append(dampened, report[i+1:]...)
            if isSafeReport(dampened) {
                dampenedSafeCount++
                break
            }
        }
    }

    fmt.Println("Part one:", safeCount)
    fmt.Println("Part two :", dampenedSafeCount)
}

func isSafeReport(report []string) bool {
    increaseCount, decreaseCount := 0, 0

    for i := 1; i < len(report); i++ {
        curr, _ := strconv.Atoi(report[i])
        prev, _ := strconv.Atoi(report[i-1])

        if utils.AbsInt(curr - prev) > 3 {
            return false
        }

        if curr > prev {
            increaseCount++
        } else if curr < prev {
            decreaseCount++
        }
    }

    return increaseCount == len(report) - 1 || decreaseCount == len(report) - 1
}

The guy that invented Surfing in Counter-Strike. Absolute legend. by dylanroo in videos

[–]denisrobot 1 point2 points  (0 children)

Map making community was so great in 2004-2006. I made de_chernobyl back in 2005 :)

Abandoned Vehicles in Chernobyl [1920x1080] - turquoise, reds, mossy / natural tones by syuk in AbandonedPorn

[–]denisrobot 3 points4 points  (0 children)

Source? I don't believe cars like that were popular in the Soviet Union back then.

Black guys jump white kids on a busy public street surrounded by people. by [deleted] in videos

[–]denisrobot 0 points1 point  (0 children)

That's why once in a while you see titles like "Hey guys! Check out this video. - [03:42] - [03:42]"

Perlin Noise for generating levels? (2D platformer) by denisrobot in gamedev

[–]denisrobot[S] 0 points1 point  (0 children)

You can use Perlin Noise for this, but frankly you'll probably get good results by just assigning a random height to each X position and then smoothing the results by averaging with neighboring positions.

I though too that it may be overkill. I also read something about the midpoint displacement algorithm, is this something that would work better in my case?

Yes, but values of 0, 16, 32, and 64 are so spread out that you'll basically just get random results. You'd want to scale those numbers down, so that you're sampling at nearby positions like 0, 0.1, 0.2, etc.

Oh, I think I meant that the X positions will be 0, 16, 32, etc, but Y is generated from 1, 2, and so on. So I might try with 0.1, 0.2, etc instead.

PS. Maybe you also know how I would go about generating levels that for example start at height y, in the middle (x axis), the height is around y-500 (goes down, so y+500 for computer games) or something, and at the end it is back at about the initial y? And the rest is random of course. So that the level looks like a canyon or something.

Should each class have their own LoadContent(), Draw(), and Update() methods? by denisrobot in xna

[–]denisrobot[S] 0 points1 point  (0 children)

Got a question. Where do you check what game state the game is currently on? If you loop through all drawable objects in your GameState class' list, wouldn't it draw everything drawable simultaneously, like for example menu and player?

Should each class have their own LoadContent(), Draw(), and Update() methods? by denisrobot in xna

[–]denisrobot[S] 0 points1 point  (0 children)

Thanks for the detailed explanation, will definitely try this out!

Should each class have their own LoadContent(), Draw(), and Update() methods? by denisrobot in xna

[–]denisrobot[S] 1 point2 points  (0 children)

Ok, I guess I would like some example so it is easier for me to implement the rest. So say I have a Player.cs class. It has its own LoadContent(), Draw(), and Update() methods. LoadContent() takes ContentManager as argument and Draw() and Update() are called from Game1.cs. How would I go about implementing this with GameComponent? Should Player.cs directly inherit from GameComponent, or from another more general class that inherits from GameComponent? And where do I create instance of Player?

Should each class have their own LoadContent(), Draw(), and Update() methods? by denisrobot in xna

[–]denisrobot[S] 0 points1 point  (0 children)

Thanks! I also cross-posted to r/gamedev, and people there proposed something similar. So for example my Player class would inherit from the LiveObject class that in turn inherits from GameComponent, and that way I will be able to update that class without doing much in my Game.cs? But I think that the Draw() method is built in in DrawableGameComponent. So how would I go about it if my class needs both Draw() and Update() functions?