Klötzchen!

Übersicht BlitzBasic Codearchiv

Neue Antwort erstellen

Ninja

Betreff: Klötzchen!

BeitragMi, Jul 05, 2006 10:59
Antworten mit Zitat
Benutzer-Profile anzeigen
Kleiner einstieg, nachdem ich nun echt lange nichtmehr mit BB programmiert habe Smile
Mit der linken maustaste erzeugt ihr so bausteine, und mit der rechten zieht ihr sie zum Mauszeiger, leider kleben die dinger gern mal aneinander, vileicht wills ja jemand verbessern Smile

Code: [AUSKLAPPEN]

;Konstanten
Const SCREEN_WIDTH = 640
Const SCREEN_HEIGHT = 480
Const GRAVITY# = 20

;-
Global BLOCK_WIDTH = 20
Global BLOCK_HEIGHT = 10


Graphics 640,480,0,2
SetBuffer BackBuffer()
SeedRnd MilliSecs()


Type block
   Field x#,y#
   Field vel_x#,vel_y#
   Field r,g,b
   Field width,height
   Field fixed
   Field id
End Type





Repeat
ClsColor 170,170,120
Cls



For block.block = Each block
   Color block\r,block\g,block\b
   Rect block\x,block\y,block\width,block\height   

   
   If movepossible(block\x,block\y,block\id,block\width,block\height,block\vel_x,block\vel_y)
            block\x = block\x + block\vel_x
            block\y = block\y + block\vel_y
         Else
            block\vel_y = 0 : block\vel_x = 0
   EndIf
   
   ;Beschleunigung ausgleichen
   If block\vel_x > 0 Then block\vel_x = block\vel_x - 0.1
   If block\vel_x < 0 Then block\vel_x = block\vel_x + 0.1
   
   If block\vel_y < GRAVITY Then block\vel_y = block\vel_y + 0.1
   If block\vel_y > GRAVITY Then block\vel_y = block\vel_y - 0.1
Next




If MouseHit(1) And IsPixelFree(MouseX(),MouseY(),BLOCK_WIDTH,BLOCK_HEIGHT) ; Erzeugen
   block.block = New block
   block\x = MouseX()
   block\y = MouseY()
   ;
   block\r = Rand(255)
   block\g = Rand(255)
   block\b = Rand(255)
   ;
   
   block\width = BLOCK_WIDTH
   block\height = BLOCK_HEIGHT
   ;
   block\id = FreeID()
EndIf




If MouseDown(2) ; Anziehen
   For block.block = Each block
      entfernung# = Sqr( (MouseX()-block\x)^2 + (MouseY()-block\y)^2)
      If entfernung# < 200
         grad = ATan2(MouseY()-block\y,MouseX()-block\x)
         block\vel_x = block\vel_x + Cos(grad)/1.5
         block\vel_y = block\vel_y + Sin(grad)/1.5
      EndIf
   Next
EndIf



Flip
Until KeyHit(1)
End

;
;----------------
;


Function IsPixelFree(x,y,width,height) ; Prüfen ob hier ein Stein platziert werden kann
   For block.block = Each block
      If RectsOverlap(x,y,width,height,block\x,block\y,block\WIDTH,block\HEIGHT)
         Return False
      EndIf
   Next
   Return True
End Function

;
;----------------
;

Function movepossible(x,y,id,width,height,velx#,vely#)

   If y+height+vely# >= SCREEN_HEIGHT Then Return 0 ; Unterer bildschirmrand-kollision
   
   For block.block = Each block
      If block\id <> id
         If RectsOverlap(x+velx#,y+vely#,width,height,block\x,block\y,block\WIDTH,block\HEIGHT)
            Return False
         EndIf
      EndIf
   Next
   
   Return True
End Function

;
;----------------
;

Function FreeID() ; Freie ID suchen
   ID = Rand(0,9000)
   
   Repeat
      free = 1
      For block.block = Each block
         If block\id = ID
            ID = ID + 1
            free = 0
         EndIf
      Next
      If free = 1 Then Exit
   Forever
   Return ID
End Function


mfg Ninja
Spiele & Security Tools
www.SelfSoft.org

BlitzChecker

BeitragMi, Jul 05, 2006 11:44
Antworten mit Zitat
Benutzer-Profile anzeigen
nicht schlecht, allerdings physikalisch gesehen manchmal ein bisschen unlogisch, das die steine auch kippen können sollten, sonst kann man sowas bauen:
Zitat:

.#
..#
...#
....#
.....#
......#
--------------

dann müsste der turm eigentlich umkippen.
  • Zuletzt bearbeitet von BlitzChecker am Mi, Jul 05, 2006 13:37, insgesamt einmal bearbeitet

Blitzcoder

Newsposter

BeitragMi, Jul 05, 2006 12:04
Antworten mit Zitat
Benutzer-Profile anzeigen
Stimmt, die Physik ist manchmal etwas komisch:
user posted image

Aber sonst ganz lustig.


MfG Blitzcoder
 

Schnuff

BeitragMi, Jul 05, 2006 15:39
Antworten mit Zitat
Benutzer-Profile anzeigen
mal ne klitze kleine verbesserung:
Code: [AUSKLAPPEN]

Function movepossible(x,y,id,width,height,velx#,vely#)

   If y+height+vely# >= SCREEN_HEIGHT Then Return 0 ; Unterer bildschirmrand-kollision
   
   For block.block = Each block
      If block\id <> id
         If RectsOverlap(x+velx#,y+vely#,width,height,block\x,block\y,block\WIDTH,block\HEIGHT-1)
            Return False
         EndIf
      EndIf
   Next
   
   Return True
End Function


Damit können die steine immerhin schon nach unten fallen wenn da noch was drauf ist Wink
Programmers dont die. They gosub without return...

Ninja

BeitragMi, Jul 05, 2006 15:49
Antworten mit Zitat
Benutzer-Profile anzeigen
Und wem es, wegen der verletzungsgefahr, von mama nur erlaubt ist mit gummiklötzen zu spielen tausch einfach die Zeile 43:

Code: [AUSKLAPPEN]
block\vel_y = 0 : block\vel_x = 0


gegen diese aus Razz

Code: [AUSKLAPPEN]
block\vel_y = -block\vel_y/2 : block\vel_x = -block\vel_x/2
Spiele & Security Tools
www.SelfSoft.org

Kabelbinder

Sieger des WM-Contest 2006

BeitragSa, Jul 08, 2006 22:44
Antworten mit Zitat
Benutzer-Profile anzeigen
Hi

Sehr schöne Idee.
Hab mal versuch, das mit dem Kippen noch dazu zu bekommen. Klappt einigermaßen aber, dass eine Treppe umkippt, sobald der Schwerpunkt auf außerhalb gewisser Breiten liegt hab ich jetzt auf die Schnelle auch nicht hinbekommen.
Code: [AUSKLAPPEN]
AppTitle "Rollklötzchen"
Graphics 640,480,16,2
SeedRnd MilliSecs()
TFormFilter 0

Dim klotz(360)
klotz(0)=CreateImage(20,10)
SetBuffer ImageBuffer(klotz(0))
Color 100,100,0
Rect 0,0,20,10
MidHandle klotz(0)
MaskImage klotz(0),255,0,255

For i = 1 To 360
klotz(i)=CopyImage(klotz(0))
RotateImage klotz(i),i
Next

Global num
Const max = 150
Dim unit#(max,6)

Function create(x,y)
unit(num,3)=1
unit(num,1)=x
unit(num,2)=y
unit(num,4)=0
unit(num,5)=0
unit(num,6)=Rand(0,360)

If num=max Then
num = 0
Else
num = num + 1
EndIf
End Function

Function edit()
For i = 0 To max
If unit(i,3)=1 Then
unit(i,5)=unit(i,5)+0.5
unit(i,5) = unit(i,5) * 0.9

unit(i,4) = unit(i,4) * 0.9

unit(i,1)=unit(i,1)+unit(i,4)
unit(i,2)=unit(i,2)+unit(i,5)

If RectsOverlap(unit(i,1),unit(i,2)-5,1,10,0,480,640,234) Then
unit(i,2)=unit(i,2)-unit(i,5)
unit(i,5)=0

If Tan(unit(i,6))>-0 Then unit(i,6)=unit(i,6)-2
If Tan(unit(i,6))<0 Then unit(i,6)=unit(i,6)+2
EndIf

If unit(i,6)>360 Then unit(i,6) = 0
If unit(i,6)<0 Then unit(i,6) = 360

For j = 0 To max
If unit(j,3)=1 Then

If unit(i,2)<unit(j,2)

If i<>j Then
If ImagesCollide(klotz(unit(i,6)),unit(i,1),unit(i,2),0,klotz(unit(j,6)),unit(j,1),unit(j,2),0) Then
unit(i,2)=unit(i,2)-unit(i,5)
unit(i,5)=0

If Tan(unit(i,6))<-0.1 Then unit(i,6)=unit(i,6)+1
If Tan(unit(i,6))>0.1 Then unit(i,6)=unit(i,6)-1

If unit(i,1)-unit(j,1)>5 Then
unit(i,6)=unit(i,6)+3
If Tan(unit(i,6))>0.1 Then unit(i,4)=unit(i,4)+0.1
EndIf

If unit(i,1)-unit(j,1)<-5 Then
unit(i,6)=unit(i,6)-3
If Tan(unit(i,6))<-0.1 Then unit(i,4)=unit(i,4)-0.1
EndIf

If unit(i,6)>360 Then unit(i,6) = 0
If unit(i,6)<0 Then unit(i,6) = 360

EndIf
EndIf
EndIf
EndIf
Next

EndIf
Next
End Function

Function draw()
For i = 0 To max
If unit(i,3)=1 Then
DrawImage klotz(unit(i,6)),unit(i,1),unit(i,2)
EndIf
Next
End Function

SetBuffer BackBuffer()
Repeat
fratim = MilliSecs()
mx = MouseX()
my = MouseY()

If MouseHit(1)=1 Then create(mx,my)

edit()
draw()

Flip
If MilliSecs()-fratim<13 Then Delay (13-(MilliSecs()-fratim))
Cls
Until KeyHit(1)
End
<Wing Avenger Download> ◊◊◊ <Macrophage Download>
 

#Reaper

Newsposter

BeitragSo, Jul 09, 2006 11:39
Antworten mit Zitat
Benutzer-Profile anzeigen
Ist ja echt lustig gemacht Very Happy
AMD Athlon 64 3500+, ATI AX800 Pro/TD, 2048 MB DRR 400 von Infineon, ♥RIP♥ (2005 - Juli 2015 -> sic!)
Blitz3D, BlitzMax, MaxGUI, Monkey X; Win7

Neue Antwort erstellen


Übersicht BlitzBasic Codearchiv

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group