add loading links and divs

This commit is contained in:
zongor 2023-12-13 00:51:50 -05:00
parent dfcbe4368c
commit 5afa075450
1 changed files with 110 additions and 22 deletions

132
main.go
View File

@ -2,6 +2,8 @@ package main
import (
"fmt"
"slices"
"strings"
rl "github.com/gen2brain/raylib-go/raylib"
"github.com/gocolly/colly"
@ -9,44 +11,90 @@ import (
func main() {
c := colly.NewCollector(
colly.AllowedDomains("alfrescocavern.com"),
)
c := colly.NewCollector()
var links []string
var texts []string
c.OnHTML("a[href]", func(e *colly.HTMLElement) {
link := e.Attr("href")
fmt.Printf("Link found: %q -> %s\n", e.Text, link)
//c.Visit(e.Request.AbsoluteURL(link))
if strings.Contains(link, "http") {
links = append(links, link)
}
})
c.OnHTML("div", func(h *colly.HTMLElement) {
fmt.Printf(h.Text)
})
c.OnHTML("p", func(h *colly.HTMLElement) {
fmt.Printf(h.Text)
if !slices.Contains(texts, h.Text) {
//fmt.Printf(h.Text)
texts = append(texts, h.Text)
}
})
c.OnRequest(func(r *colly.Request) {
fmt.Println("Visiting", r.URL.String())
})
c.Visit("https://alfrescocavern.com/")
rl.InitWindow(800, 450, "raylib [core] example - 3d camera first person")
camera := rl.Camera3D{}
camera.Position = rl.NewVector3(4.0, 2.0, 4.0)
camera.Target = rl.NewVector3(0.0, 1.8, 0.0)
camera.Target = rl.NewVector3(0.0, 0.5, 0.0)
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
camera.Fovy = 60.0
camera.Projection = rl.CameraPerspective
cubeScreenPosition := rl.Vector2{}
// Generates some random columns
var total int
var positions []rl.Vector3
var positions2D []rl.Vector2
var t_total int
var t_positions []rl.Vector3
t_position2D := rl.NewVector2(0, 0)
rl.SetTargetFPS(60)
rl.DisableCursor()
collision := "https://alfrescocavern.com/"
t_collision := ""
for !rl.WindowShouldClose() {
rl.UpdateCamera(&camera, rl.CameraFirstPerson) // Update camera with first person mode
if collision != "" {
links = nil
positions = nil
positions2D = nil
texts = nil
t_positions = nil
t_position2D = rl.NewVector2(0, 0)
links = make([]string, 0)
texts = make([]string, 0)
c.Visit(collision)
total = len(links)
positions = make([]rl.Vector3, total)
positions2D = make([]rl.Vector2, total)
for i := 0; i < total; i++ {
positions[i] = rl.NewVector3(float32(rl.GetRandomValue(-50, 50)),
0.5,
float32(rl.GetRandomValue(-50, 50)))
}
t_total = len(texts)
t_positions = make([]rl.Vector3, t_total)
for i := 0; i < t_total; i++ {
t_positions[i] = rl.NewVector3(float32(rl.GetRandomValue(-50, 50)),
0.5,
float32(rl.GetRandomValue(-50, 50)))
}
collision = ""
}
rl.UpdateCamera(&camera, rl.CameraThirdPerson) // Update camera with first person mode
rl.BeginDrawing()
@ -54,19 +102,59 @@ func main() {
rl.BeginMode3D(camera)
rl.DrawPlane(rl.NewVector3(0.0, 0.0, 0.0), rl.NewVector2(32.0, 32.0), rl.LightGray) // Draw ground
rl.DrawCube(rl.NewVector3(-16.0, 2.5, 0.0), 1.0, 5.0, 32.0, rl.Blue) // Draw a blue wall
rl.DrawCube(rl.NewVector3(16.0, 2.5, 0.0), 1.0, 5.0, 32.0, rl.Lime) // Draw a green wall
rl.DrawCube(rl.NewVector3(0.0, 2.5, 16.0), 32.0, 5.0, 1.0, rl.Gold) // Draw a yellow wall
cubeScreenPosition = rl.GetWorldToScreen(rl.NewVector3(camera.Target.X, camera.Target.Y+1.0, camera.Target.Z), camera)
for i := 0; i < total; i++ {
rl.DrawCube(positions[i], 1.0, 1.0, 1.0, rl.Maroon)
pos := rl.NewVector3(positions[i].X, positions[i].Y+1.0, positions[i].Z)
positions2D[i] = rl.GetWorldToScreen(pos, camera)
// Check collisions player vs enemy-box
if rl.CheckCollisionBoxes(
rl.NewBoundingBox(
rl.NewVector3(camera.Target.X-0.5, camera.Target.Y-0.5, camera.Target.Z-0.5),
rl.NewVector3(camera.Target.X+0.5, camera.Target.Y+0.5, camera.Target.Z+0.5)),
rl.NewBoundingBox(
rl.NewVector3(positions[i].X-0.5, positions[i].Y-0.5, positions[i].Z-0.5),
rl.NewVector3(positions[i].X+0.5, positions[i].Y+0.5, positions[i].Z+0.5)),
) {
collision = links[i]
}
}
for i := 0; i < t_total; i++ {
rl.DrawCube(t_positions[i], 1.0, 1.0, 1.0, rl.Blue)
if rl.CheckCollisionBoxes(
rl.NewBoundingBox(
rl.NewVector3(camera.Target.X-0.5, camera.Target.Y-0.5, camera.Target.Z-0.5),
rl.NewVector3(camera.Target.X+0.5, camera.Target.Y+0.5, camera.Target.Z+0.5)),
rl.NewBoundingBox(
rl.NewVector3(t_positions[i].X-0.5, t_positions[i].Y-0.5, t_positions[i].Z-0.5),
rl.NewVector3(t_positions[i].X+0.5, t_positions[i].Y+0.5, t_positions[i].Z+0.5)),
) {
t_collision = texts[i]
pos := rl.NewVector3(t_positions[i].X, t_positions[i].Y+1.0, t_positions[i].Z)
t_position2D = rl.GetWorldToScreen(pos, camera)
}
}
rl.DrawPlane(rl.NewVector3(0.0, 0.0, 0.0), rl.NewVector2(60.0, 60.0), rl.LightGray) // Draw ground
rl.DrawCube(camera.Target, 1.0, 1.0, 1.0, rl.Green)
rl.EndMode3D()
rl.DrawRectangle(10, 10, 220, 70, rl.Fade(rl.SkyBlue, 0.5))
rl.DrawRectangleLines(10, 10, 220, 70, rl.Blue)
rl.DrawText("User", int32(cubeScreenPosition.X)-rl.MeasureText("User", 20)/2, int32(cubeScreenPosition.Y), 20, rl.Black)
rl.DrawText("First person camera default controls:", 20, 20, 10, rl.Black)
rl.DrawText("- Move with keys: W, A, S, D", 40, 40, 10, rl.DarkGray)
rl.DrawText("- Mouse move to look around", 40, 60, 10, rl.DarkGray)
for i := 0; i < len(links); i++ {
rl.DrawText(links[i], int32(positions2D[i].X)-rl.MeasureText(links[i], 10)/2, int32(positions2D[i].Y), 10, rl.Maroon)
}
if t_collision != "" {
rl.DrawText(t_collision, int32(t_position2D.X)-rl.MeasureText(t_collision, 10)/2, int32(t_position2D.Y+10), 10, rl.Blue)
}
rl.EndDrawing()
}