Autor Beitrag
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mo 20.06.05 19:21 
ich habe jetzt die imagesprites nicht durch dead entfernt sondern mit einem leeren bild überschrieben, damit ich sie per restart wiederherstellen kann.
aber in der nächsten runde blinken die blöcke die in der runde davor zuerstört wurden, hab schon versucht es zu beheben, dadurch, hats schon einmal im ersten spiel geblinkt.

hier source, dann nochmal mit binaries am anhang:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
unit UMain;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  DXDraws, DXSounds, DXClass, DXSprite, DXInput;

type
  TBeam = class(TImageSprite)
  private
    speed: integer;
  public
    constructor Create(AParent: TSprite); override;
    procedure DoMove(MoveCount: Integer); override;
    procedure DoCollision(Sprite: TSprite; var Done: Boolean); override;
  end;

type
  TBall = class(TImageSprite)
  private
    xspeed, yspeed: integer;
  public
    constructor Create(AParent: TSprite); override;
    procedure Contact;
    procedure DoMove(MoveCount: Integer); override;
    procedure DoCollision(Sprite: TSprite; var Done: Boolean); override;
  end;

type
  TBlock = class(TImageSprite)
  private
    dying: boolean;
    broken: boolean;
    tick: integer;
  public
    constructor Create(AParent: TSprite); override;
    procedure Contact;
    procedure DoMove(MoveCount: Integer); override;
  end;

type
  TMainForm = class(TForm)
    DXDraw1: TDXDraw;
    DXImageList1: TDXImageList;
    DXInput1: TDXInput;
    DXSpriteEngine1: TDXSpriteEngine;
    DXTimer1: TDXTimer;
    DXSound1: TDXSound;
    DXWaveList1: TDXWaveList;
    DXSpriteEngine2: TDXSpriteEngine;
    procedure FormCreate(Sender: TObject);
    procedure DXTimer1Timer(Sender: TObject; LagCount: Integer);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  MainForm: TMainForm;
  Background: TBackgroundSprite;
  Beam: TBeam;
  Ball: TBall;
  Blocks: array [1..15] of array [1..10] of TBlock;
  Score: integer;
  running: boolean = false;
  Bool_GameOver: boolean = false;
  Bool_GameStart: boolean = true;

implementation

{$R *.DFM}

procedure GameOver;
var
  i, j: integer;
begin
  Ball.xspeed := 0;
  Ball.yspeed := 0;
  Score := 0;
  running := false;
  Bool_GameOver := true;
end;

procedure ResetGame;
var
  i, j: integer;
  dir: integer;
begin
  if bool_gameover then
    begin
      score := 0;
      with ball do
        begin
          x := (MainForm.ClientWidth - Width)  div 2;
          y := 205;
          dir := random(2);
          if dir = 0 then
            xspeed := - 6;
          if dir = 1 then
            xspeed := 6;
          yspeed := 6;
        end;
      with beam do
        begin
          x := (MainForm.ClientWidth - Width)  div 2;
          y := 400;
        end;
      for i := 1 to 15 do
        for j := 1 to 10 do
          with Blocks[i, j] do
            begin
              Image := MainForm.DXImageList1.Items[random(5) + 3];
              dying := false;
              broken := false;
              tick := 0;
            end;
      bool_gameover := false;
      Bool_GameStart := false;
      running := true;
    end;
end;

constructor TBeam.Create(AParent: TSprite);
begin
  inherited Create(AParent);

  Image := MainForm.DXImageList1.Items[1];
  Width := Image.Width;
  Height := Image.Height;

  x := (MainForm.ClientWidth - Width)  div 2;
  y := 400;

  speed := 8;
end;

procedure TBeam.DoMove(MoveCount: Integer);
begin
  inherited DoMove(MoveCount);

  if x <= 0 then
    x := 0;
  if x >= MainForm.ClientWidth - width then
    x := MainForm.ClientWidth - width;

  if isLeft in MainForm.DXInput1.States then
    x := x - speed;
  if isRight in MainForm.DXInput1.States then
    x := x + speed;

  Collision;
end;

procedure TBeam.DoCollision(Sprite: TSprite; var Done: Boolean);
begin
  if Sprite is TBall then
    TBall(Sprite).Contact;
end;

constructor TBall.Create(AParent: TSprite);
var
  dir: integer;
begin
  inherited Create(AParent);

  Image := MainForm.DXImageList1.Items[0];
  Width := Image.Width;
  Height := Image.Height;

  x := (MainForm.ClientWidth - Width)  div 2;
  y := 205;
  z := 1;
  dir := random(2);
  if dir = 0 then
    xspeed := - 6;
  if dir = 1 then
    xspeed := 6;
  yspeed := 6;
end;

procedure TBall.Contact;
begin
  if yspeed > 0 then
    yspeed := - yspeed;
  MainForm.DXWaveList1.Items[1].Play(false);
end;

procedure TBall.DoMove(MoveCount: Integer);
begin
  inherited DoMove(MoveCount);

  if x <= 0 then
    if xspeed < 0 then
      begin
        xspeed := - xspeed;
        MainForm.DXWaveList1.Items[1].Play(false);
      end;
  if x >= MainForm.ClientWidth - width then
    if xspeed > 0 then
      begin
        xspeed := - xspeed;
        MainForm.DXWaveList1.Items[1].Play(false);
      end;
  if y <= 0 then
    if yspeed < 0 then
      begin
        yspeed := - yspeed;
        MainForm.DXWaveList1.Items[1].Play(false);
      end;  
  if y >= MainForm.height - height then
    GameOver;

  x := x + xspeed;
  y := y + yspeed;

  Collision;
end;

procedure TBall.DoCollision(Sprite: TSprite; var Done: Boolean);
begin
  if Sprite is TBlock then
    TBlock(Sprite).Contact;
end;

constructor TBlock.Create(AParent: TSprite);
begin
  inherited Create(AParent);

  Image := MainForm.DXImageList1.Items[random(5) + 3];

  Width := Image.Width;
  Height := Image.Height;

  dying := false;
  broken := false;
  tick := 0;
end;

procedure TBlock.Contact;
begin
  if not broken then
    begin
      MainForm.DXWaveList1.Items[0].Play(false);
      image := MainForm.DXImageList1.Items[8];
      AnimStart := 0;
      AnimCount := Image.PatternCount;
      AnimLooped := true;
      AnimSpeed := 1/20;
      dying := true;
    end;
end;

procedure TBlock.DoMove(MoveCount: Integer);
begin
  inherited DoMove(MoveCount);
  If dying then
    begin
      inc(tick);
      if tick = 9 then
        begin
          inc(score, 1);
          image := MainForm.DXImageList1.items[10];
          broken := true;
          dying := false;
        end;  
    end;
end;

procedure TMainForm.FormCreate(Sender: TObject);
var
  i, j: integer;
begin
  randomize;
  BackGround := TBackGroundSprite.Create(DXSpriteEngine2.Engine);
  with Background do
    begin
      Tile := True;
      SetMapSize(1, 1);
      image := DXImageList1.Items[2];
      z := - 1;
    end;
  Beam := TBeam.Create(DXSpriteEngine1.Engine);  
  Ball := TBall.Create(DXSpriteEngine1.Engine);
  for i := 1 to 15 do
    for j := 1 to 10 do
      begin
        Blocks[i, j] := TBlock.Create(DXSpriteEngine1.Engine);
        with Blocks[i, j] do
          begin
            x := i * width - width + (clientwidth - 15 * width) div 2;
            y := j * height + 25;
          end;
      end;
end;

procedure TMainForm.DXTimer1Timer(Sender: TObject; LagCount: Integer);
var
  i,j:integer;
begin
  DXInput1.Update;
  DXDraw1.Surface.Fill(clBlack);
  DXSpriteEngine2.Draw;
  DXImageList1.Items[9].Draw(DXDraw1.Surface, MainForm.clientwidth div 2 - DXImageList1.items[9].width div 2, 75, 0);
  DXSpriteEngine1.Draw;
  if Running and not bool_GameOver then
    begin
      DXSpriteEngine1.Move(20);
      DXSpriteEngine1.Dead;
    end;
  if not Running and bool_GameStart then
    begin
      with DXDraw1.Surface.Canvas do
        begin
          Brush.Style := bsclear;
          Font.name := 'Arial';
          Font.Color := clwhite;
          Font.Size := 24;
          Font.Style := [fsbold];
          TextOut(168, 265, 'Press Enter to start');
          Release;
        end;
      if IsButton2 in DXInput1.States then
        begin
          running := true;
          bool_GameStart := false;
        end;
    end;
  if not Running and bool_GameOver then
    begin
      with DXDraw1.Surface.Canvas do
        begin
          Brush.Style := bsclear;
          Font.name := 'Arial';
          Font.Color := clwhite;
          Font.Size := 48;
          Font.Style := [fsbold];
          TextOut(145, 200, 'GameOver!');
          Font.Size := 24;
          Font.Style := [fsbold];
          TextOut(168, 265, 'Press Enter to start');
          Release;
        end;
      if IsButton2 in DXInput1.States then
        ResetGame;
    end;
  with DXDraw1.Surface.Canvas do
    begin
      Brush.Style := bsClear;
      Font.name := 'Arial';
      Font.Color := clwhite;
      Font.Size := 16;
      Font.Style := [fsbold];
      TextOut(5, 0, 'Score: ' + inttostr(Score));
      Release;
    end;
  DXDraw1.Flip;
  if isButton3 in DXInput1.States then
    Close;
end;

end.
Einloggen, um Attachments anzusehen!
Larus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 431



BeitragVerfasst: Mo 20.06.05 19:37 
Vieleicht liegt es ja hieran!

s.u.

(musste PROZESS killen anders kriegte ich Programm net weg)
Einloggen, um Attachments anzusehen!
F34r0fTh3D4rk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 21.06.05 11:53 
der fehler ist mir unbekannt, aber dadurch kenne ich die ursache ja auch net :roll:
Larus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 431



BeitragVerfasst: Di 21.06.05 18:21 
Nun ja ich konnte den Fehler erst gar net selber sehen wegen diesem Feheler! Ein Spiel und statt restart kam das! :cry:
F34r0fTh3D4rk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 21.06.05 18:23 
komisch, naja irgendwo muss ja die ursache liegen :roll:
Larus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 431



BeitragVerfasst: Di 21.06.05 18:24 
ich zieh es mir nochma rein! mom *schnieffff* lol nein scherz

ich muss dich enttäuschen! Auch nach mehrfachen versuchen ging es net! Immer wieder die Selbe meldung!