Pathfinding/ readpixel ???

Übersicht BlitzBasic Allgemein

Neue Antwort erstellen

tyty

Betreff: Pathfinding/ readpixel ???

BeitragDi, Mai 31, 2005 15:55
Antworten mit Zitat
Benutzer-Profile anzeigen
Also ich habe ein 3x4 Gitter für eine Art Labyrinthspiel. Daraus soll der Rechner jetzt am Anfang des Levels zufällig ein Wegnetz erstellen.
Einfach so simpel, dass alle Einzelfelder miteinander verbunden sind und der Rechner dann selbst bemerkt ob jedes Feld eine Verbindung hat.


Außerdem kann ich nicht mehr auf Seite 7 vom Forumtreffen-Thread.
(Zugriff verweigert)
Also
@Mods : Könnt ihr mal n bisserl entspammen , muss einer der letzten beiträge sein
( auch die User)
User posted image

Kaikille suomea puhuville ihmisille: tyty = tyty the technical youngster!!!
  • Zuletzt bearbeitet von tyty am Di, Jun 07, 2005 14:58, insgesamt einmal bearbeitet
 

Kifferopa

Gast

BeitragDi, Mai 31, 2005 16:16
Antworten mit Zitat
Pathfinding? Gibt´s doch irgendwo bei "FAQ & TUTORIALS" Rolling Eyes

[Edit]Oder hier: http://www.blitzbase.de/artikel/path_1.htm [/Edit]
  • Zuletzt bearbeitet von Kifferopa am Di, Mai 31, 2005 16:27, insgesamt einmal bearbeitet

tyty

BeitragDi, Mai 31, 2005 16:26
Antworten mit Zitat
Benutzer-Profile anzeigen
Es ist ja nicht wirklich Pathfinding!
User posted image

Kaikille suomea puhuville ihmisille: tyty = tyty the technical youngster!!!
 

Kifferopa

Gast

BeitragDi, Mai 31, 2005 16:28
Antworten mit Zitat
Oben ist ein Button "Suchen"

simi

BeitragDi, Mai 31, 2005 16:33
Antworten mit Zitat
Benutzer-Profile anzeigen
suchst du sowas??:
Code: [AUSKLAPPEN]

;      ******************************************************************************************
;      *   Title: Maze Generator                                                             *
;      *   Author: Magellan                                                                 *
;      *   E-mail: Sirus@peoplepc.com                                                        *
;      *   Description: Generates random 'perfect' mazes. All mazes have exactly one solution   *
;      *                Based on some of my old DB code, which was converted from VB :)         *
;      *            Credit to Dave Brebner for the original VB code                     1
;      ******************************************************************************************

;The program will still function right if you modify any of the constants
                     ;The Number of tiles across, and down
Const MaxX=60            ;In this case, it's a 60*48 maze
Const MaxY=48            ;Feel free to change this.
                     
Const ScreenWidth=800      ;Screen Width
Const ScreenHeight=600      ;Screen Height
Const ScreenDepth=16      ;Screen Depth
Const Mode=1            ;Mode (1,Fullscreen, 2 Windowed)
;Now set the actual window, based on the constants
Graphics ScreenWidth,ScreenHeight,ScreenDepth,Mode

AppTitle "Maze Generator"   ;Application Title

SetBuffer BackBuffer()

Dim Mz(MaxX, MaxY)      ;This stores the actual maze data. 1 for wall, 0 for not
Dim VertsX(MaxX, MaxY)   ;For Maze generation
Dim VertsY(MaxX, MaxY)   ;For Maze generation

SeedRnd(MilliSecs())

;Make the borders
   For A = 0 To MaxX
       Mz(A, 0) = 1
       Mz(A, MaxY) = 1
   Next

   For A = 0 To MaxY
       Mz(0, A) = 1
       Mz(MaxX, A) = 1
   Next

;Generate the vertices
   For X = 2 To MaxX-2 Step 2
       For Y = 2 To MaxY-2 Step 2
           VertsX(X, Y) = X
           VertsY(X, Y) = Y
       Next
   Next

;Mix up the order To draw verticies
   For X1 = 2 To MaxX-2 Step 2
       For Y1 = 2 To MaxY-2 Step 2
           X2 = (Int(Rnd(1) * 13) + 1) * 2
           Y2 = (Int(Rnd(1) * 13) + 1) * 2
           tmpX = VertsX(X1, Y1)
           tmpY = VertsY(X1, Y1)
           VertsX(X1, Y1) = VertsX(X2, Y2)
           VertsY(X1, Y1) = VertsY(X2, Y2)
           VertsX(X2, Y2) = tmpX
           VertsY(X2, Y2) = tmpY
       Next
   Next

;Now here is the confusing part. Using a method I found
;on the internet. We are simply going To draw
;a wall from Each verticies in a random direction
;Until another wall is reached
   For X = 2 To MaxX-2 Step 2
       For Y = 2 To MaxY-2 Step 2
           XX = VertsX(X, Y)
           YY = VertsY(X, Y)
           If Mz(XX, YY) = 0
               Repeat
                   Cnt = 0
                   XX = VertsX(X, Y)
                   YY = VertsY(X, Y)
                   Dirn = Int(Rand(0,3))
                   Repeat
                       Cnt = Cnt + 1
                       T=0
                       If  Dirn=0 Then  XX = XX - 1 : T=1
                       If  Dirn=1 Then  XX = XX + 1 : T=1
                       If  Dirn=2 Then  YY = YY + 1 : T=1
                       If T=0 Then YY = YY - 1
                   Until Mz(XX, YY) = 1
               Until Cnt < MaxX-4 Or Cnt < MaxY-4
               XX = VertsX(X, Y)
               YY = VertsY(X, Y)
               Repeat
                   Mz(XX, YY) = 1
                   T=0
                   If  Dirn=0 Then  XX = XX - 1 : T=1
                   If  Dirn=1 Then  XX = XX + 1 : T=1
                   If  Dirn=2 Then  YY = YY + 1 : T=1
                   If T=0 Then YY = YY - 1
               Until Mz(XX, YY) = 1
           EndIf
       Next
   Next


;These two points will be the openings
   Mz(0, 1) = 0
   Mz(MaxX, MaxY-1) = 0

;Now draw the map
   Map()
   Image=CreateImage(ScreenWidth,ScreenHeight)
   GrabImage Image,0,0


;Make a simple little loop, to draw the image and the player
   Repeat
      If KeyDown(1) Then End
      Cls
      
      ;In here is where you would add the player playing around, etc
      DrawImage Image,0,0
      Flip
   Forever



;This is the map function. It draws the map based on the Screen size.
   Function Map()
     ScreenWidth1#=ScreenWidth
     ScreenHeight1#=ScreenHeight
     Max1#=MaxX
     Max2#=MaxY
     XSize#=ScreenWidth1#/(Max1#+1)
     YSize#=ScreenHeight1#/(Max2#+1)
   
     Test=CreateImage(XSize#+1,YSize#+1)
   
     For X=0 To XSize#+1
      For Y=0 To YSize#+1
         Color 0,0,Rand(255)
         Plot X,Y
      Next
     Next
   
     GrabImage Test,0,0
      Color 255,255,255
      For X = 0 To MaxX
          For Y = 0 To MaxY
              If Mz(X, Y) = 1
                 ;Rect X*XSize#,Y*YSize#,XSize#+1,YSize#+1
              DrawImage Test,X*XSize#,Y*YSize#
              EndIf
          Next
      Next
   End Function


(leider nicht von mir Wink )

tyty

BeitragDi, Mai 31, 2005 16:51
Antworten mit Zitat
Benutzer-Profile anzeigen
Zitat:
Oben ist ein Button "Suchen"


Aber ich wusste nicht genau wie man das nennt!?


@simi : Ich werde es zuhause mal ausprobieren.
User posted image

Kaikille suomea puhuville ihmisille: tyty = tyty the technical youngster!!!

tyty

BeitragDi, Jun 07, 2005 14:56
Antworten mit Zitat
Benutzer-Profile anzeigen
es ist nicht genau das was ich meinte
ich will dass es 12 (3x4) Vierecke sind und dann zusätzlich noch ein rahmen wzischen diesen ist.

ich hab es so versucht:

farbe01 = readpixel(x, y) ; um damit die farbe von den rahmen zu
farbe02 = readpixel(x, y) ; erfragen
...
if farbe01 = 255, 0, 0 and farbe09 = 255, 0, 0 then ; die 2 rahmen von der linken oberen ecke
variable = rnd(1,2)
if variable = 1 then
color 0, 0, 0
rect x1, y1 ; schwarzer rahmen da oder...
else
color 0, 0, 0
rect x2, y2 ; schwarzer rahmen dort
endif
endif


damit habe ich einen ausgang des vierecks unten oder rechts
er sagt jedoch "excepting end of line"
User posted image

Kaikille suomea puhuville ihmisille: tyty = tyty the technical youngster!!!

garret

BeitragFr, Jun 10, 2005 8:41
Antworten mit Zitat
Benutzer-Profile anzeigen
Sollte dein Code tatsächlich dem entsprechen, was du gerade geschrieben hast, dann hast du bei
Zitat:

rect x1, y1 ; schwarzer rahmen da oder...
else
color 0, 0, 0
rect x2, y2 ; schwarzer rahmen dort


die Länge der Rechtecke vergessen.

Rect x,y,Breite,Höhe,("Füllung")


Außerdem erwartet eine If-Abfrage immer nur eine Zuweisung
If farbe01=255 then


Du hast drei Zuweisungen
Zitat:

If farbe01 = 255, 0, 0 and farbe09 = 255, 0, 0 then


Du solltest die Farbe eines Pixels mit Getcolor(pixelx,pixely) abfragen und dann die einzelnen Farbwerte mit Colorred(),Colorgreen() und Colorblue() ermitteln. Alternativ geht auch Readpixel(fast), das ist sogar schneller glaube ich.
>>nec aspera terrent<< (Auch Widerwärtigkeiten schrecken nicht)

tyty

BeitragSo, Jun 12, 2005 16:20
Antworten mit Zitat
Benutzer-Profile anzeigen
danke, das mit der länge weiß ich wohl ich war nur nicht zuhause und konnte die genauen maße nicht nachgucken
User posted image

Kaikille suomea puhuville ihmisille: tyty = tyty the technical youngster!!!

Neue Antwort erstellen


Übersicht BlitzBasic Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group