for i := 0 to 9 do begin tux[ i ].Texture := texTuxWalk; tux[ i ].Frame := random( 19 ) + 2; tux[ i ].Pos.X := i * 96; tux[ i ].Pos.Y := 130; tux[ i ].Killed:= false; end; for i := 10 to 20 do begin tux[ i ].Texture := texTuxWalk; tux[ i ].Frame := random( 19 ) + 2; tux[ i ].Pos.X := ( i - 9 ) * 96; tux[ i ].Pos.Y := 325; tux[ i ].Killed:= false; end; nave.Texture := texTuxStand; nave.Frame := random( 19 ) + 2; nave.Pos.X := 400 - 32; nave.Pos.Y := 300 - 64 - 4; nave.DeltaX := 5; nave.DeltaY := 5; nave.Killed:= false; fntMain := font_LoadFromFile( dirRes + 'font.zfi' ); joy_Init(); fnt := font_LoadFromFile( dirRes + 'font.zfi' ); end;
procedure Draw; var i : Integer; t : Single; begin batch2d_Begin(); if time > 255 Then begin zgl_Disable( COLOR_BUFFER_CLEAR ); back0_offset:= (time div 10) mod 800; back1_offset:= (time div 3) mod 1600;
if back1_offset > 800 then ssprite2d_Draw( texBack1, -(back1_offset mod 800-800), 400, 1600, 200, 0 ); text_Draw( fntMain, 0, 25, 'time: ' + u_IntToStr( time ) ); text_Draw( fntMain, 0, 50, 'sfondo 0 offset: ' + u_IntToStr( back0_offset ) ); text_Draw( fntMain, 0, 75, 'sfondo 1 offset: ' + u_IntToStr( back1_offset ) ); cam2d_Set( @camMain ); for i := 0 to 20 do begin if not tux[ i ].Killed then asprite2d_Draw( tux[ i ].Texture, tux[ i ].Pos.X, tux[ i ].Pos.Y, 64, 64, 0, tux[ i ].Frame div 2, 255, FX_BLEND ); end; asprite2d_Draw( nave.Texture, nave.Pos.X, nave.Pos.Y, 64, 64, 0, nave.Frame div 2 ); end;
if time <= 255 Then ssprite2d_Draw( texLogo, 400 - 256, 300 - 128, 512, 256, 0, time ) else if time < 510 Then begin ssprite2d_Draw( texLogo, 400 - 256, 300 - 128, 512, 256, 0, 510 - time ); end;
if time > 255 Then text_Draw( fntMain, 0, 0, 'FPS: ' + u_IntToStr( zgl_Get( RENDER_FPS ) ) );
DrawDebugInfo_Joy;
batch2d_End(); end;
function Intersect( const Rect1, Rect2 : zglTRect ) : Boolean; var tw,th, rw,rh, tx,ty,rx,ry : double; begin result:= false; tw := Rect1.H; th := Rect1.H; rw := Rect2.W; rh := Rect2.H; // controllo parametri errati if (rw <= 0) or (rh <= 0) or (tw <= 0) or (th <= 0) then begin exit; end; tx := Rect1.x; ty := Rect1.y; rx := Rect2.x; ry := Rect2.y; rw += rx; rh += ry; tw += tx; th += ty; result := ((rw < rx) or (rw > tx)) and ((rh < ry) or (rh > ty)) and ((tw < tx) or (tw > rx)) and ((th < ty) or (th > ry)); end; procedure Timer; var i : Integer; c1, c2:zglTRect; begin INC( time, 2 ); for i := 0 to 20 do begin INC( tux[ i ].Frame ); if tux[ i ].Frame > 20 Then tux[ i ].Frame := 2; end; inc(nave.Frame); if (nave.Frame > 20) then nave.Frame:= 2; for i := 0 to 20 do begin tux[ i ].Pos.X := tux[ i ].Pos.X + 1.5; if tux[ i ].Pos.X > 864 Then tux[ i ].Pos.X := -96; end; if key_Press( K_ESCAPE ) Then zgl_Exit(); if key_Down( K_UP ) Then nave.Pos.Y := nave.Pos.Y - nave.DeltaY; if key_Down( K_DOWN ) Then nave.Pos.Y := nave.Pos.Y + nave.DeltaY; if key_Down( K_LEFT ) Then nave.Pos.X := nave.Pos.X - nave.DeltaX; if key_Down( K_RIGHT ) Then nave.Pos.X := nave.Pos.X + nave.DeltaX;
c1.Y:=nave.Pos.Y; c1.X:=nave.Pos.X; c1.W:=64; c1.H:=64; for i := 0 to 20 do begin c2.Y:=tux[i].Pos.Y; c2.X:=tux[i].Pos.X; c2.W:=64; c2.H:=64; if (Intersect(C1,C2)) then tux[i].Killed:= true; end; end;
Begin randomize(); time := 255; // nomorelogic: con questo si salta lo splash screen ;) back0_offset := 0; back1_offset := 0; timer_Add( @Timer, 16 ); zgl_Reg( SYS_LOAD, @Init ); zgl_Reg( SYS_DRAW, @Draw ); zgl_Enable( APP_USE_UTF8 ); wnd_SetCaption( '05 - Sprites 2D' ); wnd_ShowCursor( TRUE ); scr_SetOptions( 800, 600, REFRESH_MAXIMUM, FALSE, FALSE ); zgl_Init(); End.
--- Termina codice ---
nomorelogic:
si vede che ha gli scudi alzati 8)
sergio:
State andando avanti come dei treni , purtroppo io ho un sacco di lavoro e non riesco a starvi dietro , ma mi sembra che si incominci a intravvedere già una buona base per il gioco ! :D Complimenti. Per Castle , non sono ancora riuscito a vedere ,nomorelogic , ma appena riesco ti dico .
nomorelogic:
anche io ho un sacco di lavoro, come tutti penso e solo nel weekend riesco a fare qualcosina di concreto però dandoci una mano a vicenda qualcosa viene fuori sicuramente.
Ad esempio avevo intenzione di "trasformare" il sorgente che abbiamo ora su zengl in qualcosa di più vicino all'OOP. Questo dovrebbe aiutare a chiarire meglio le idee a tutti su come si andrà a programmare se si userà questa liberia. Che poi penso che nonostante la programmazione OOP sia meno performante nei videogame in realtà, quando si lavora in più persone, aiuta molto in quanto le modifiche vengono apportate alle classi ed è molto più semplice così piuttosto che andare a spasso per il codice a modificare record, funzioni e procedure varie.
Però penso che oramai... tocca aspettare il prossimo weekend :)
Stilgar:
Oddio, la OOP non è più lenta a priori ... basta stare attenti a come si fanno le cose ;) Se vuoi ti posso scrivere un pezzo di codice in C che è più lento di VB o Java ;)