Page 1 sur 2

Purepunch raté sur l'effet de serre !

Publié : mar. 30/juin/2009 6:44
par Huitbit
Un jeu très "oldskull" :lol: :lol:
Je vous laisse comprendre le but (flêches droite, haut et gauche)! Bons scores !

Code : Tout sélectionner

l=640:h=480:k$="|þˉþþU":Structure a:x.l:y.l:EndStructure:Macro r:Random
EndMacro:Macro f:DisplaySprite:EndMacro:Dim g.a(4):Dim m.a(4):g(0)\x=0:x=4:a=1
g(0)\y=240:m(0)\x=r(l):m(0)\y=-r(l):For i=1 To 4:g(i)\x=g(i-1)\x+128+r(32)
g(i)\y=160+r(160):m(i)\x=r(l):m(i)\y=-r(l):Next i:InitSprite():InitKeyboard()
OpenWindow(0,0,0,l,h,""):OpenWindowedScreen(WindowID(0),0,0,l,h,0,0,0)
CreateSprite(0,l,40):StartDrawing(SpriteOutput(0)):Box(0,0,l,40,$EFCF10)
StopDrawing():CreateSprite(1,16,16):StartDrawing(SpriteOutput(1)):For j=1 To 8
For i=1 To 8:If Mid(RSet(Bin(Asc(Mid(k$,j,1))),8,"0"),i,1)="1"
Box(i*2-2,j*2-2,2,2,$FF):EndIf:Next i:Next j:StopDrawing()
CreateSprite(2,16,16):StartDrawing(SpriteOutput(2)):Circle(8,8,8,$227CE9)
StopDrawing():CreateSprite(3,48,h):StartDrawing(SpriteOutput(3))
Ellipse(24,0,24,360,$FCFBEB):StopDrawing():Repeat:FlipBuffers():ClearScreen(0)
For i=0 To 4:If m(i)\y>440:m(i)\x=r(640):m(i)\y=-r(l):g(i)\y=g(i)\y+10:EndIf
If SpriteCollision(1,x,y,2,m(i)\x,m(i)\y):m(i)\x=r(624):m(i)\y=-r(l):s+1:EndIf
f(2,m(i)\x,m(i)\y):m(i)\y=m(i)\y+1:Next i:For i=0 To 4:f(3,g(i)\x,g(i)\y)
Next i:f(1,x,y):f(0,0,440):For i=0 To 4
If SpriteCollision(1,x+dx,y+dy,3,g(i)\x,g(i)\y):If y<=g(i)\y-15:z=g(i)\y-16
EndIf:Break:Else:z=0:EndIf:Next i:If SpriteCollision(1,x,y,0,0,440)
MessageRequester("",Str(s)):End:EndIf:ExamineKeyboard():If  KeyboardPushed(200)
If z:dy=-24:a=1:EndIf:EndIf:If KeyboardPushed(203) And x>3:dx=-3
ElseIf  KeyboardPushed(205) And  x<621:dx=3:Else:dx=0:EndIf:If z=0:If y<424
x+dx:dy+a:y+dy:EndIf:Else:x+dx:y=z:EndIf:Repeat:E= WindowEvent():If  E=16:End
EndIf:Until e=0:Delay(1):ForEver

Version dépunchée si quelqu'un a le courage de mettre le nez dedans !

(Je pense que ça doit être possible de le "puncher" en plein écran? :roll: ?)

Code : Tout sélectionner

;skull
;auteur Huitbit
;PureBasic 4.30 (Windows - x86)
;*********************************
Enumeration
  #fond
  #mer
  #skull
  #meteore 
  #iceberg
EndEnumeration

#largeur_ecran=640
#hauteur_ecran=480
skull$="|þˉþþU"

Structure coordo
  x.l
  y.l
EndStructure

Dim iceberg.coordo(4)
Dim meteore.coordo(4)


iceberg(0)\x=0
iceberg(0)\y=320
meteore(0)\x=Random(640)
meteore(0)\y=-100+Random(90)

;-positionnement du crâne
x=4
y=0
ay=1 ;accélération

;-placement des icebergs
For i=1 To 4
  iceberg(i)\x=iceberg(i-1)\x+128+Random(32)
  iceberg(i)\y=160+Random(160)
  meteore(i)\x=Random(620)
  meteore(i)\y=-400+Random(400)
Next i

;-PROGRAMME PRINCIPAL
InitSprite()
InitKeyboard()
OpenWindow(0,0,0,#largeur_ecran,#hauteur_ecran,"skull ",#PB_Window_ScreenCentered|#PB_Window_SystemMenu  )
OpenWindowedScreen(WindowID(0),0,0,#largeur_ecran,#hauteur_ecran,0,0,0)
 
 ;-SPRITES
 ;-fond d'écran   
CreateSprite(#fond,#largeur_ecran,#hauteur_ecran)
;-mer
CreateSprite(#mer,#largeur_ecran,40)
StartDrawing(SpriteOutput(#mer))
Box(0,0,#largeur_ecran,40,$FF0000)
StopDrawing() 
;-crâne
CreateSprite(#skull,16,16)
StartDrawing(SpriteOutput(#skull))
For j=1 To 8
  For i=1 To 8
    If Mid(RSet(Bin(Asc(Mid(skull$,j,1))),8,"0"),i,1)="1"
      Box(i*2-2,j*2-2,2,2,$FF)
    EndIf
  Next i
Next j
StopDrawing() 
;-météore    
CreateSprite(#meteore,16,16)
StartDrawing(SpriteOutput(#meteore))
Circle(8,8,8,$FFFF)
StopDrawing() 
;-iceberg
CreateSprite(#iceberg,48,#hauteur_ecran)
StartDrawing(SpriteOutput(#iceberg))
Ellipse(24,0,24,#hauteur_ecran*0.75,$FFFFFF)
StopDrawing() 

;-BOUCLE PRINCIPALE
Repeat
  FlipBuffers() 
  ;-fond noir
  DisplaySprite(#fond,0,0)
  ;-météores
  For i=0 To 4
    If meteore(i)\y>440
      meteore(i)\x=Random(640)
      meteore(i)\y=-400+Random(400)
      iceberg(i)\y=  iceberg(i)\y+10
    EndIf
    ;-test collision crâne~météore
    If SpriteCollision(#skull,x,y,#meteore,meteore(i)\x,meteore(i)\y)
      meteore(i)\x=Random(624)
      meteore(i)\y=-400+Random(400)
      score=score+1
    EndIf
    DisplaySprite(#meteore,meteore(i)\x,meteore(i)\y)
    meteore(i)\y=meteore(i)\y+1
  Next i
  ;-iceberg
  For i=0 To 4
    DisplaySprite(#iceberg,iceberg(i)\x,iceberg(i)\y)
  Next i
  
  ;-crâne
  DisplaySprite(#skull,x,y)
  ;-mer
  DisplaySprite(#mer,0,440)
  
  ;-test collision crâne~iceberg
  For i=0 To 4
    If SpriteCollision(#skull,x+dx,y+dy,#iceberg,iceberg(i)\x,iceberg(i)\y)
      If y<=iceberg(i)\y-15
        y_contact=iceberg(i)\y-16
      EndIf
      Break
    Else
      y_contact=0
    EndIf
  Next i
  
  ;-fin de la partie
  If SpriteCollision(#skull,x+dx,y+dy,#mer,0,440)
    MessageRequester("score ",Str(score))
    End
  EndIf
  
  
  ExamineKeyboard()
  If  KeyboardPushed(#PB_Key_Up) 
  ;-saut seulement si crâne au contact du sol
    If y_contact
      dy=-24
      ay=1
    EndIf
  EndIf
  
  If KeyboardPushed(#PB_Key_Left) And x>3
    dx=-3
  ElseIf  KeyboardPushed(#PB_Key_Right) And  x<621
    
    dx=3
  Else 
    dx=0
  EndIf  
  
  ;-déplacement  en l'air 
  If y_contact=0
    If y<440-16
      x=x+dx
      dy=dy+ay
      y=y+dy
    EndIf
    
  Else
  ;-déplacement sur l'iceberg
    x=x+dx
    y=y_contact
  EndIf
  
  
  
  Repeat
    Event = WindowEvent()      
    If  Event = #PB_Event_CloseWindow
      End 
    EndIf
  Until Event = 0
  
  Delay(10)
ForEver
Hasta la vista !

Publié : mar. 30/juin/2009 9:39
par kernadec
bonjour
3 j' arrête trop énervant
merci

Publié : mar. 30/juin/2009 10:15
par TazNormand
ah la vache, 5, et je confirme, super énervant !!!

mais joli quand même

par contre, désolé, me suis pas penché pour diminuer le code, mais je pense qu'Ollivier vas nous raccourcir ton code en moins de 2 !!!

Publié : mar. 30/juin/2009 10:16
par Cool Dji
Well, 2 pas mieux ça kill !!

Publié : mar. 30/juin/2009 12:18
par Huitbit
super énervant !!!
j' arrête trop énervant
ça kill !!
:lol: :lol: :lol:
C'est plus un purepunch, c'est un purechi..... euh, purelaxatif :lol: !
je pense qu'Ollivier va nous raccourcir ton code en moins de 2 !!!
S'il le souhaite, cela devra être avant les douze coups de minuit :wink: !

Plus sérieusement, j'ai posté le code ici car il y a trois choses qui peuvent servir :
>>la création du sprite "crâne" avec "|þˉþþU" (utilisation des codes ASCII pour créer le sprite 8*8 )
La chaîne ci-dessus correspond aux valeurs suivantes 124,254,203,137,254,254,85,21 que je convertis en séries de 8 bits (ex : 255-->11111111) comme au bon vieux temps !

>>la prise en compte d'une gravité dans les déplacements

>>mais surtout la gestion de la collision iceberg~crâne qui n'est pas si triviale que ça (il faut tenir compte du dépacement qui n'est pas uniforme et il n'y a que le sommet des icebergs qui est pris en compte malgré l'utilisation de SpriteCollision())

J'espère que ça servira !

Hasta la vista !

PS : pour le punch, je vais essayer une version en mode écran, monochrome (rouge( $FF) et noir (0) par exemple)

Publié : mar. 30/juin/2009 13:04
par flaith
:D arf : 9 mais dur, dur

Publié : mar. 30/juin/2009 13:23
par djes
Vous êtes nuls les gars, 18 les doigts dans le nez! J'adore!

(faut dire que j'ai fini des jeux comme rick dangerous 1 et 2 et la famille addams, qui sont autrement plus costauds ;))

Publié : mar. 30/juin/2009 14:02
par Cool Dji
9 et 18 :P
Bordel, comment vous faites ???

Publié : mar. 30/juin/2009 14:10
par TazNormand
whoo 29 !!!

Gros coup de bol, plein de boules jaunes collées les unes aux autres !!!

Image

PS : les boutons supplémentaires dans la barre de titre de la fenêtre proviennent de l'application Actual Windows Manager

Encore raté !

Publié : mar. 30/juin/2009 19:29
par Huitbit

Code : Tout sélectionner

l=640:s$="|þˉþþU":Structure p:x.l:y.l:EndStructure:Macro d(a):StartDrawing(a)
EndMacro:h=480:Macro r:random:EndMacro:Macro a:displaysprite:EndMacro:Macro k
KeyboardPushed:EndMacro:Macro e:EndIf:EndMacro:Dim i.p(4):Dim m.p(4):i(0)\y=320
m(0)\x=r(l):m(0)\y=-r(h):a=1:For i=1 To 4:i(i)\x=i(i-1)\x+128+r(32):m(i)\x=r(l)
i(i)\y=160+r(160):m(i)\y=-r(l):Next i:InitSprite():InitKeyboard():c=16:q=440
OpenScreen(l,h,32,""):CreateSprite(0,l,40):d(SpriteOutput(0)):Box(0,0,l,40,$FF)
StopDrawing():CreateSprite(1,c,c):d(SpriteOutput(1)):For j=1 To 8:For i=1 To 8
If Mid(RSet(Bin(Asc(Mid(s$,j,1))),8,"0"),i,1)="1":Box(i*2-2,j*2-2,2,2,$FF):e
Next i:Next j:StopDrawing():CreateSprite(2,c,c):d(SpriteOutput(2))
Circle(8,8,8,$FF):StopDrawing():CreateSprite(3,48,h):d(SpriteOutput(3))
Ellipse(24,0,24,360,$FF):StopDrawing():Repeat:FlipBuffers():ClearScreen(0)
For i=0 To 4:If m(i)\y>q:m(i)\x=r(l):m(i)\y=-r(l):i(i)\y+10:e
If SpriteCollision(1,x,y,2,m(i)\x,m(i)\y):m(i)\x=r(l):m(i)\y=-r(l):s+1:e
a(2,m(i)\x,m(i)\y):m(i)\y+1:Next i:For i=0 To 4:a(3,i(i)\x,i(i)\y):Next i
a(1,x,y):a(0,0,q):For i=0 To 4:If SpriteCollision(1,x+o,y+u,3,i(i)\x,i(i)\y)
If y<=i(i)\y-15:z=i(i)\y-c:e:Break:Else:z=0:e:Next i
If SpriteCollision(1,x+o,y+u,0,0,q):End:e:ExamineKeyboard():If  k(200):If z
u=-24:a=1:e:e:If k(203) And x>3:o=-3:ElseIf  k(205) And  x<621:o=3:Else:o=0:e
If z=0:If y<424:x+o:u+a:y+u:e:Else:x+o:y=z:e:d(ScreenOutput())
DrawText(0,0,Str(s)):StopDrawing():Delay(1):Until k(1)
J'y arriverai, j'y arriverai
:lol: :lol: :roll:

Publié : mar. 30/juin/2009 19:42
par Anonyme
même en mettant des macros au CreateSprite / Start&StopDrawing , tu ne gagnerais que 1 ou 2 lignes. simplifie tes calculs :)

Publié : mar. 30/juin/2009 20:07
par djes
:lol: il te reste 3h! :)

Publié : mar. 30/juin/2009 22:15
par Ollivier
La boucle principale n'est même pas commencée qu'on atteind déjà la dixième ligne!!
Bourrin le HuitBit parfois...

Code : Tout sélectionner

Macro D:Macro:EndMacro:D K:End:End#D:Dim C(4):Dim N(4):Dim O(4):InitSprite()
D Q:EndIf:K#D:D R:Random:K#D:D F:DisplaySprite:K#D:L=640:H=480:X=4:Dim B(4):a=1
D P:Next:K#D:D S(A,B,C):For A=B To C:K#D:N(0)=R(L):InitKeyboard():O(0)=-R(L)
S(I,1,4):D T(A,B,C):CreateSprite(A,B,C):StartDrawing(SpriteOutput(A)):K#D
B(i)=B(i-1)+128+R(32):C(i)=160+R(160):N(i)=R(L):O(i)=-R(L):P:C(0)=240
OpenWindowedScreen(OpenWindow(0,0,0,L,H,""),0,0,L,H,0,0,0):D U:StopDrawing():K#D
T(0,L,40):Box(0,0,L,40,$EFCF10):U:T(1,16,16):S(J,1,8):S(I,1,8):V=$FF
If Mid(RSet(Bin(Asc(Mid("|þˉþþU",J,1))),8,"0"),I,1)="1":Box(i*2-2,j*2-2,2,2,V)
:Q:P:P:U:T(2,16,16):Circle(8,8,8,$227CE9):U:T(3,48,H):Ellipse(24,0,24,360,$FCFBEB)
U:Repeat:FlipBuffers():ClearScreen(0):S(I,0,4):If O(i)>440:N(i)=r(L):O(i)=-r(L)
C(i)+10:Q:If SpriteCollision(1,x,y,2,N(i),O(i)):N(i)=R(624):O(i)=-r(L):S+1:Q
F(2,N(i),O(i)):O(i)=O(i)+1:P:S(I,0,4):F(3,B(i),C(i)):P:F(1,x,y):F(0,0,440)
S(I,0,4):If SpriteCollision(1,x+dx,y+dy,3,B(i),C(i)):If y<=C(i)-15:Z=C(i)-16:Q
I=4:Else:Z=0:Q:P:If SpriteCollision(1,x,y,0,0,440):MessageRequester("",Str(s))
K:Q:ExamineKeyboard():If KeyboardPushed(200):If z:dy=-24:a=1:Q:Q
If KeyboardPushed(203) And x>3:dx=-3:ElseIf KeyboardPushed(205) And x<621:dx=3
Else:dx=0:Q:If z=0:If y<424:x+dx:dy+a:y+dy:Q:Else:x+dx:y=z:Q:Delay(1)
Until WindowEvent()=16

Publié : mer. 01/juil./2009 0:00
par Huitbit
Bourrin le HuitBit parfois...
:lol: :lol: :lol:
Toujours !
J'étais parti pour faire un purepunch "jeu de plateforme" et puis après, j'ai perdu le contrôle !
D'ailleurs, avec un tableau peut-être que ce serait passé !

Hasta la vista !

Publié : mer. 01/juil./2009 0:02
par Anonyme
Huitbit a écrit :
Bourrin le HuitBit parfois...
J'étais parti pour faire un purepunch "jeu de plateforme" et puis après, j'ai perdu le contrôle !

:D