Tiles drehen.. ich verzweifel noch daran :(
Übersicht

![]() |
SmilyBetreff: Tiles drehen.. ich verzweifel noch daran :( |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hoi,
ich stehe derzeit ein wenig auf dem schlauch. Wahrscheinlich ist es aber was ganz einfaches, das mir einfach nicht einfallen will. Mit dem Code kann man ein Pentomino auf einem Spielfeld bewegen. soo und nun will ich noch, dass man mit der Leertaste das Pentomino drehen kann, (also so wie man es von Tetris kennt ^^) Aber irgendwie komme ich nicht darrauf, wie das geht. Für jeden block muss die x- und y-position von der Mitte aus berrechnet werden, wo er dann gezeichnet wird. gegeben ist noch eine Variable Ri, die angeben soll, in welche richtung das ding gedreht ist. ich habe es schon mit sin und cos(ri*90) versucht. Ich glaube auch dass dieser ansatz richtig ist. (siehe auskommentierte codezeilen) Allerdings verwende ich das wahrscheinlich falsch. Ich wäre dankbar, wenn mir jemand helfen kann ^^ Code: [AUSKLAPPEN] Global pent:TPent[12]
Global feldsx = 10 Global feldsy = 6 Global feldx = 1 Global feldy = 1 Type Tpent Field block[5,5] Field cr, cg, cb Field x,y Field ri Method New() cr = Rand(100,255) cg = Rand(100,255) cb = Rand(100,255) End Method Method setblock(x,y, v=1) block[x,y] = v End Method Method draw() SetColor cr,cg,cb my = y + feldx mx = x + feldy For bx = 0 To 4 For by = 0 To 4 dx = mx+ (bx-2)' * Sin(ri*90) + (by-2) * Cos(ri*90) dy = my+ (by-2)' * Sin(ri*90) + (bx-2) * Cos(ri*90) If block[bx,by] DrawRect dx*20, dy*20,19,19 Next Next SetColor 255,255,255 DrawRect mx*20, my*20,19,19 End Method Method infeld() mx = x-2 my = y-2 For bx = 0 To 4 For by = 0 To 4 If block[bx,by] px = mx+bx py = my+bx If px < 0 Return 0 If py < 0 Return 0 If px > feldsx-1 Return 0 If py > feldsy-1 Return 0 End If Next Next Return 1 End Method End Type filein = ReadFile("1.pent") For p = 0 To 11 pent[p] = New TPent For y = 0 To 4 B = ReadByte(filein) Print Bin(b) For x = 0 To 4 c = 1 Shl x pent[p].setblock(x,y,c&b) Next Next Next CloseFile filein Graphics 800,800 Repeat a = 3 Cls SetColor 100,100,100 For x = 1 To feldsx For y = 1 To feldsy DrawRect (x+feldx-1)*20,(y+feldy-1)*20,19,19 Next Next pent[a].draw() DrawText pent[A].infeld(),0,0 If KeyHit(Key_Down) pent[a].y :+ 1 If KeyHit(key_Left) pent[a].x :- 1 If KeyHit(Key_Up) pent[a].y :- 1 If KeyHit(key_Right) pent[a].x :+ 1 If KeyHit(key_space) pent[a].ri :+1 Flip Forever Function updatescreen() End Function PS: die benötigte "1.pent" kann man sich hiermit erstellen: Code: [AUSKLAPPEN] fileout = WriteFile("1.pent")
WriteByte fileout, %11111 WriteByte fileout, %00000 WriteByte fileout, %00000 WriteByte fileout, %00000 WriteByte fileout, %00000 WriteByte fileout, %01111 WriteByte fileout, %01000 WriteByte fileout, %00000 WriteByte fileout, %00000 WriteByte fileout, %00000 WriteByte fileout, %01111 WriteByte fileout, %00100 WriteByte fileout, %00000 WriteByte fileout, %00000 WriteByte fileout, %00000 ' Diese figur dient nur zum Ausprobieren. WriteByte fileout, %00101 WriteByte fileout, %00100 WriteByte fileout, %11011 WriteByte fileout, %00100 WriteByte fileout, %00100 Rem WriteByte fileout, %11100 WriteByte fileout, %10000 WriteByte fileout, %10000 WriteByte fileout, %00000 WriteByte fileout, %00000 End Rem WriteByte fileout, %11100 WriteByte fileout, %01000 WriteByte fileout, %01000 WriteByte fileout, %00000 WriteByte fileout, %00000 WriteByte fileout, %01110 WriteByte fileout, %01010 WriteByte fileout, %00000 WriteByte fileout, %00000 WriteByte fileout, %00000 WriteByte fileout, %11100 WriteByte fileout, %00110 WriteByte fileout, %00000 WriteByte fileout, %00000 WriteByte fileout, %00000 WriteByte fileout, %00000 WriteByte fileout, %00100 WriteByte fileout, %01110 WriteByte fileout, %00100 WriteByte fileout, %00000 WriteByte fileout, %11100 WriteByte fileout, %11000 WriteByte fileout, %00000 WriteByte fileout, %00000 WriteByte fileout, %00000 WriteByte fileout, %11000 WriteByte fileout, %01100 WriteByte fileout, %00100 WriteByte fileout, %00000 WriteByte fileout, %00000 WriteByte fileout, %10000 WriteByte fileout, %11100 WriteByte fileout, %00100 WriteByte fileout, %00000 WriteByte fileout, %00000 WriteByte fileout, %10000 WriteByte fileout, %11100 WriteByte fileout, %01000 WriteByte fileout, %00000 WriteByte fileout, %00000 CloseFile fileout |
||
Lesestoff:
gegen Softwarepatente | Netzzensur | brain.exe | Unabhängigkeitserklärung des Internets "Wir müssen die Rechte der Andersdenkenden selbst dann beachten, wenn sie Idioten oder schädlich sind. Wir müssen aufpassen. Wachsamkeit ist der Preis der Freiheit --- Keine Zensur!" stummi.org |
![]() |
LordArtus |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hi,
hab jetzt zu wenig Zeit , aber auf den ersten Blick gehst du die Sache meiner Meinung nach falsch an. Für die Drehung (falls ich es richtig Verstehe) brauchst du kein Sin und Cos , sondern einfach ein Vertauschen der 'bx' und 'by'-Schleifen. Aber ich schaue es mir heute Abend genauer an. MfG LordArtus Edit :Hast du das gemeint ??? Code: [AUSKLAPPEN] Global pent:TPent[12] Global feldsx = 10 Global feldsy = 6 Global feldx = 1 Global feldy = 1 Type Tpent Field block[5,5] Field cr, cg, cb Field x,y Field ri Method New() cr = Rand(100,255) cg = Rand(100,255) cb = Rand(100,255) End Method '-------------------------------------------------------------- Method Drehen() Local zblock[5,5] For Local xd=0 To 4 For Local yd=0 To 4 zblock[4-yd,xd]=block[xd,yd] Next Next block=zblock End Method '-------------------------------------------------------------- Method setblock(x,y, v=1) block[x,y] = v End Method Method draw() '------------------------- If ri=1 Self.Drehen() ri=0 EndIf '------------------------- SetColor cr,cg,cb my = y + feldx mx = x + feldy For bx = 0 To 4 For by = 0 To 4 dx = mx+ (bx-2)' * Sin(ri*90) + (by-2) * Cos(ri*90) dy = my+ (by-2)' * Sin(ri*90) + (bx-2) * Cos(ri*90) If block[bx,by] DrawRect dx*20, dy*20,19,19 Next Next SetColor 255,255,255 DrawRect mx*20, my*20,19,19 End Method Method infeld() mx = x-2 my = y-2 For bx = 0 To 4 For by = 0 To 4 If block[bx,by] px = mx+bx py = my+bx If px < 0 Return 0 If py < 0 Return 0 If px > feldsx-1 Return 0 If py > feldsy-1 Return 0 End If Next Next Return 1 End Method End Type filein = ReadFile("1.pent") For p = 0 To 11 pent[p] = New TPent For y = 0 To 4 B = ReadByte(filein) Print Bin(b) For x = 0 To 4 c = 1 Shl x pent[p].setblock(x,y,c&b) Next Next Next CloseFile filein Graphics 800,800 While Not KeyHit(KEY_ESCAPE) a = 3 Cls SetColor 100,100,100 For x = 1 To feldsx For y = 1 To feldsy DrawRect (x+feldx-1)*20,(y+feldy-1)*20,19,19 Next Next pent[a].draw() DrawText pent[A].infeld(),0,0 If KeyHit(Key_Down) pent[a].y :+ 1 If KeyHit(key_Left) pent[a].x :- 1 If KeyHit(Key_Up) pent[a].y :- 1 If KeyHit(key_Right) pent[a].x :+ 1 If KeyHit(key_space) pent[a].ri :+1 Flip Wend Function updatescreen() End Function |
||
![]() |
Smily |
![]() Antworten mit Zitat ![]() |
---|---|---|
danke erstmal, das ist auch eine Möglichkeit (auch wenn es nicht so gedacht war)
Allerdings weis ich nicht, was von der Performance her schneller ist: die Positionen bei jedem durchlauf anhand der Ri variable (wert von 1 bis 4) neu zu berrechnen oder die Werte direkt in den Variablen umschreiben. (Man bedenke, dass die funktion "Drehen" bei jedem durchlauf ein neues Array erstellt). gruß, Smily0412 |
||
Lesestoff:
gegen Softwarepatente | Netzzensur | brain.exe | Unabhängigkeitserklärung des Internets "Wir müssen die Rechte der Andersdenkenden selbst dann beachten, wenn sie Idioten oder schädlich sind. Wir müssen aufpassen. Wachsamkeit ist der Preis der Freiheit --- Keine Zensur!" stummi.org |
![]() |
LordArtus |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hi,
ist es überhaupt das , was Du vorhattest ? Also ich denke so muss es schneller sein , falls Du es anders lösen solltest würde ich es gerne sehen. MfG LordArtus p.s. Ich erstelle deshalb ein neues Array , weil bedenke , dass du sonst in das gleiche Array schreibst von dem du noch nicht alles gelesen hast und ich denke , dass es anders (falls es möglich ist) ziemlich komplex wäre und somit auch ziemlich langsam.Und ausserdem hast Du es in den Block drinne und nicht nur auf den Bildschirm , somit kannst Du mit dem Block andere Sachen anstellen.Oder Du machst gleich für jeden Block 4 'Grafiken'. |
||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group