Worms-like Terrain

Übersicht BlitzMax, BlitzMax NG Codearchiv & Module

Neue Antwort erstellen

maximilian

Betreff: Worms-like Terrain

BeitragDi, Okt 25, 2005 17:42
Antworten mit Zitat
Benutzer-Profile anzeigen
So, hier ist das ultimative Code-Sample. Da ich es zwischendurch programmiert habe, ist es zwar grottig geschrieben (komisch strukturiert, komische Variablennamen, kein Strict...), aber ich habe keine Lust mehr es zu verändern, jetzt wo es funktioniert.

Sample-Download

Code: [AUSKLAPPEN]

SetGraphicsDriver GLMax2DDriver()
Graphics 640, 480, 0, NOSYNC


Global terrain:TImage[20, 15]


LoadTerrain("terrain.bmp")

While Not KeyHit(KEY_ESCAPE)

 DrawTerrain()
 DrawText ShowFPS(), 0, 0

 If MouseDown(1) Then
   EditTerrain(MouseX(), MouseY(), 20)
 End If

 Flip
 Cls

Wend



Function LoadTerrain(file:String)

 SetMaskColor 255, 0, 255
 Local img_terrain = LoadImage("terrain.bmp"), x, y, tmp_pixmap:TPixmap, tmp_terrain:TPixmap
 tmp_terrain = LockImage(img_terrain)

 For x = 0 To 19
  For y = 0 To 14
    terrain[x, y] = CreateImage(32, 32)

    tmp_pixmap = LockImage(terrain[Min(x, 19), Min(y, 14)])

    Local bx, by
    For bx = 0 To 31
     For by = 0 To 31
      WritePixel(tmp_pixmap, bx, by, ReadPixel(tmp_terrain, x*32+bx, y*32+by))
     Next
    Next

    UnlockImage(terrain[x, y])
  Next
 Next

 UnlockImage(img_terrain)
 img_terrain = Null

End Function


Function DrawTerrain()

 Local x, y

 For x = 0 To 19
  For y = 0 To 14
    DrawImage terrain[x, y], x*32, y*32
  Next
 Next

End Function


Function EditTerrain(x, y, r)

 Local x1, y1, p1

 x1 = 0
 y1  = -r
 p1  = y Shl 1+3

 While x1 <= -y1

   EditLine(x-x1, x+x1, y+y1)
   EditLine(x-x1, x+x1, y-y1)
   EditLine(x-y1, x+y1, y+x1)
   EditLine(x-y1, x+y1, y-x1)

   If p1 >= 0 Then
    y1 = y1 + 1
    p1 = p1 + ((x1 + y1) Shl (2+6))
   Else
    p1 = p1 + (x1 Shl (2+6))
   End If
   x1 = x1 + 1

 Wend

End Function


Function EditLine(x1, x2, y)

 Local x, tile:TImage, pixmap, locked:TImage, ux:Int, uy:Int

 If x2 < x1 Then
  Local s = x1
  x1 = x2
  x2 = s
 End If


 uy = y/32
 If y > -1 And uy < 15 Then

 For x = x1 To x2

   ux = x/32
   If x > -1 And ux < 20 Then

   locked = tile
   tile = terrain[ux, uy]
   If tile <> locked Then
    pixmap = LockImage(tile)
   End If

   WritePixel(pixmap, x Mod 32, y Mod 32, $FF000000)

   End If

 Next

 End If

End Function


Function ShowFps:Int()

 Global fps_show:Int
 Global fps_ms:Int = MilliSecs()
 Global fps_frames:Int


 fps_frames=fps_frames+1
 If MilliSecs()-fps_ms >= 1000 Then
  fps_show=fps_frames
  fps_frames=0
  fps_ms=MilliSecs()
 End If

 Return fps_show
   
End Function
Variety is the spice of life. One day ignore people, next day annoy them.
  • Zuletzt bearbeitet von maximilian am So, Feb 14, 2010 16:06, insgesamt 3-mal bearbeitet
 

ke^kx

BeitragMi, Okt 26, 2005 17:29
Antworten mit Zitat
Benutzer-Profile anzeigen
MEGA GEIL!

Aber mach das ganze doch nochmal in b2d, plz *g*

Jiriki
http://i3u8.blogspot.com
Asus Striker II
Intel Core2Quad Q9300 @ 2,5 GHz (aber nur zwei Kerne aktiv aufgrund der Instabilität -.-)
Geforce 9800 GTX
2GB RAM

Goodjee

BeitragSo, Apr 09, 2006 19:46
Antworten mit Zitat
Benutzer-Profile anzeigen
hm, ich habe festgestellt, das die krater nicht immer ganz rund sind:

der mit dem grünen Pfeil ist rund,
der mit dem roten irgrendwie blumenförmig^^

user posted image
"Ideen sind keine Coladosen, man kann sie nicht recyclen"-Dr. House
http://deeebian.redio.de/ http://goodjee.redio.de/

maximilian

BeitragDi, Apr 11, 2006 20:00
Antworten mit Zitat
Benutzer-Profile anzeigen
Hm, also bei mir kann ich nichts dergleichen feststellen. Kannst du mir sagen welche Kreisgröße du verwendest?
Variety is the spice of life. One day ignore people, next day annoy them.

Goodjee

BeitragSa, Apr 15, 2006 11:43
Antworten mit Zitat
Benutzer-Profile anzeigen
20...gleub ich, ganz normal.....
vllt liegts aber auch an meiner schlechten übersetzung nach bb^^
"Ideen sind keine Coladosen, man kann sie nicht recyclen"-Dr. House
http://deeebian.redio.de/ http://goodjee.redio.de/
 

Dreamora

BeitragSa, Apr 15, 2006 14:43
Antworten mit Zitat
Benutzer-Profile anzeigen
Wenn du nach BB machst, kommt 1 Problem rein: Int() konvertierung arbeitet in BB anders als in BM. Int() müsste dann durch Floor() ersetzt werden um gleich wie in BM zu arbeiten.

EDIT: Da ich nicht in den Code geschaut hab, weiss ich net ob ein Int vorkommt. Aber auch implizite Konvertierung (also wenn man int = float * float hat) würde unter diesem Problem leiden. Dann müsste man also sogar explizit konvertieren über Floor.
Ihr findet die aktuellen Projekte unter Gayasoft und könnt mich unter @gayasoft auf Twitter erreichen.
  • Zuletzt bearbeitet von Dreamora am Sa, Apr 15, 2006 16:59, insgesamt einmal bearbeitet

Goodjee

BeitragSa, Apr 15, 2006 15:31
Antworten mit Zitat
Benutzer-Profile anzeigen
ahh, thx

edit: es kommt gar kein int im wichtigen code vor, werden in editline noch in der anderen funktion, editterrain....
"Ideen sind keine Coladosen, man kann sie nicht recyclen"-Dr. House
http://deeebian.redio.de/ http://goodjee.redio.de/

Bigmichi

BeitragSo, Jul 09, 2006 17:11
Antworten mit Zitat
Benutzer-Profile anzeigen
Könnte das jemand nochmal bitte uppren? wäre extrem nett von euch =))

Neue Antwort erstellen


Übersicht BlitzMax, BlitzMax NG Codearchiv & Module

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group