Autor Beitrag
Mikula
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Sa 09.03.13 15:44 
Hallo liebe community,

Ich habe mich eben erst hier angemeldet, deswegen, sry für fehler in der rechtschreibung oder iwas anderes.

Ich solte gleich erwähnen das ich nicht sehr viel Erfahrung mit Delphi habe, aber hoffe mir diese anzueignen.

Nun ja, ich sitze schon ca 3 wochen an einem Pacman Spiel in Delphi für die Schule.
Folgendes habe ich nun hinbekommen. Die bewegung an sich, außenwände, punkte und das essen der punkte und noch ein paar kleinigkeiten.

An folgenden Problemen zerbreche ich mir lange den Kopf:
- Wie kann man innere Wände erstellen?
Also Wände im Spielfeld durch die der Pacman (oder wie ich ihn Capman genannt habe)
nicht durch kann
- Wie kann ich monster einfügen?
Die Monster sollen auf kürzestem Wege den Pacman finden. Sie sollen auch nicht durhch
Wände gehen können.
Ich habe bereits versucht ein Monster mit Timer zu erstellen, ohne Erfolg
Ich habe unten meinen Quellcode, den ich bisher erstellt habe eingefügt. (Da sollte ich zwar noch aufräumen aber diese gewisse unordnung beeinflusst das Programm nicht.

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:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415:
416:
417:
418:
419:
420:
421:
422:
423:
424:
425:
426:
427:
428:
429:
430:
431:
432:
433:
434:
435:
436:
437:
438:
439:
440:
441:
442:
443:
444:
445:
446:
447:
448:
449:
450:
451:
452:
453:
454:
455:
456:
457:
458:
459:
460:
461:
462:
463:
464:
465:
unit CapMan;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls;

type
        TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    BitBtn1: TBitBtn;
    Timer1: TTimer;

  procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure FormCreate(Sender: TObject);
    procedure Waende;
    procedure Timer1Timer(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1 ;
  x : integer = 200//Alle Variablen global da: -Kopieren nicht notig
  y : integer = 200// -Alle Proceduren benutzen diese
  c : integer; // Abstand -andern sich eh standig
  r: integer = 20// Radius
  t: integer = 40// Verzogerung beim Offnen/Schliesen
  s: integer = 20// Schritt Lange
  fm : integer = clblack; // Maul Farbe
  fh : integer = clblack; // Hintergrund Farbe
  x1: integer = 40 ; x11: integer = 40 ; x21: integer = 240 ; //x-werte für Punkte
  x2: integer = 80 ; x12: integer = 40 ; x22: integer = 280 ;
  x3: integer = 120 ; x13: integer = 40 ; x23: integer = 320 ;
  x4: integer = 160 ; x14: integer = 40 ; x24: integer = 360 ;
  x5: integer = 200 ; x15: integer = 40 ; x25: integer = 360 ;
  x6: integer = 240 ; x16: integer = 40 ; x26: integer = 360 ;
  x7: integer = 280 ; x17: integer = 80 ; x27: integer = 360 ;
  x8: integer = 320 ; x18: integer = 120 ; x28: integer = 360 ;
  x9: integer = 360 ; x19: integer = 160 ; x29: integer = 360 ;
  x10: integer = 40 ; x20: integer = 200 ; x30: integer = 360 ;
  w : array [1..1001..2of integer; //y-werte für punkte
  rp: integer = 10//radius punkte
  mx: integer = 300//Monster x-wert
  my:integer = 300//Monster y-wert
  implementation
{$R *.dfm}

//******************************************************************************
//********************************(PROGRAMM)************************************
//******************************************************************************
procedure TForm1.Waende;
begin

canvas.Brush.color:=clgreen;
canvas.pen.Color:=clgreen;
canvas.rectangle(0,0,20,form1.height-20); // R
canvas.Rectangle(0,0,form1.Width,20); // A
canvas.Rectangle(form1.Width-40,0,form1.Width,form1.Height); // N
canvas.Rectangle(0,form1.Height-60,form1.Width,form1.Height); // D

 w[1,2]:=40; w[11,2]:=120; w[21,2]:=320// y-werte für Punkte
 w[2,2]:=40; w[12,2]:=160; w[22,2]:=320;
 w[3,2]:=40; w[13,2]:=200; w[23,2]:=320;
 w[4,2]:=40; w[14,2]:=240; w[24,2]:=320;
 w[5,2]:=40; w[15,2]:=280; w[25,2]:=80;
 w[6,2]:=40; w[16,2]:=320; w[26,2]:=120;
 w[7,2]:=40; w[17,2]:=320; w[27,2]:=160;
 w[8,2]:=40; w[18,2]:=320; w[28,2]:=200;
 w[9,2]:=40; w[19,2]:=320; w[29,2]:=240;
 w[10,2]:=80; w[20,2]:=320; w[30,2]:=280;



canvas.Pen.Color:=clyellow;
canvas.Brush.Color:=clyellow;
canvas.Ellipse(x1-rp,w[1,2]-rp,x1+rp,w[1,2]+rp);
canvas.Ellipse(x2-rp,w[2,2]-rp,x2+rp,w[2,2]+rp);
canvas.Ellipse(x3-rp,w[3,2]-rp,x3+rp,w[3,2]+rp);
canvas.Ellipse(x4-rp,w[4,2]-rp,x4+rp,w[4,2]+rp);
canvas.Ellipse(x5-rp,w[5,2]-rp,x5+rp,w[5,2]+rp);
canvas.Ellipse(x6-rp,w[6,2]-rp,x6+rp,w[6,2]+rp);
canvas.Ellipse(x7-rp,w[7,2]-rp,x7+rp,w[7,2]+rp);
canvas.Ellipse(x8-rp,w[8,2]-rp,x8+rp,w[8,2]+rp);
canvas.Ellipse(x9-rp,w[9,2]-rp,x9+rp,w[9,2]+rp);
canvas.Ellipse(x10-rp,w[10,2]-rp,x10+rp,w[10,2]+rp);
canvas.Ellipse(x11-rp,w[11,2]-rp,x11+rp,w[11,2]+rp);
canvas.Ellipse(x12-rp,w[12,2]-rp,x12+rp,w[12,2]+rp);
canvas.Ellipse(x13-rp,w[13,2]-rp,x13+rp,w[13,2]+rp);
canvas.Ellipse(x14-rp,w[14,2]-rp,x14+rp,w[14,2]+rp);
canvas.Ellipse(x15-rp,w[15,2]-rp,x15+rp,w[15,2]+rp);
canvas.Ellipse(x16-rp,w[16,2]-rp,x16+rp,w[16,2]+rp);
canvas.Ellipse(x17-rp,w[17,2]-rp,x17+rp,w[17,2]+rp);
canvas.Ellipse(x18-rp,w[18,2]-rp,x18+rp,w[18,2]+rp);
canvas.Ellipse(x19-rp,w[19,2]-rp,x19+rp,w[19,2]+rp);
canvas.Ellipse(x20-rp,w[20,2]-rp,x20+rp,w[20,2]+rp);
canvas.Ellipse(x21-rp,w[21,2]-rp,x21+rp,w[21,2]+rp);
canvas.Ellipse(x22-rp,w[22,2]-rp,x22+rp,w[22,2]+rp);
canvas.Ellipse(x23-rp,w[23,2]-rp,x23+rp,w[23,2]+rp);
canvas.Ellipse(x24-rp,w[24,2]-rp,x24+rp,w[24,2]+rp);
canvas.Ellipse(x25-rp,w[25,2]-rp,x25+rp,w[25,2]+rp);
canvas.Ellipse(x26-rp,w[26,2]-rp,x26+rp,w[26,2]+rp);
canvas.Ellipse(x27-rp,w[27,2]-rp,x27+rp,w[27,2]+rp);
canvas.Ellipse(x28-rp,w[28,2]-rp,x28+rp,w[28,2]+rp);
canvas.Ellipse(x29-rp,w[29,2]-rp,x29+rp,w[29,2]+rp);
canvas.Ellipse(x30-rp,w[30,2]-rp,x30+rp,w[30,2]+rp);

//canvas.Brush.Color:=clWhite; //Zeichnung des Monsters
//canvas.Ellipse(mx-r,my-r,mx+r,my+r); //erstmal ein Kreis



end;


procedure TForm1.FormCreate(Sender: TObject);
begin
canvas.Brush.Color:=fh;
canvas.rectangle(0,0,Form1.Height,Form1.Width);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
//canvas.Brush.Color:=clWhite; //Zeichnung des Monsters
//canvas.Ellipse(mx-r,my-r,mx+r,my+r); //erstmal ein Kreis

Waende;


end;



//********************************(NACH RECHTS)*********************************

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if (x=x1) and (y=w[1,2]) then inc(x1,form1.Width+100); //Punkt 1
  if (x=x2) and (y=w[2,2]) then inc(x2,form1.Width+100); //Punkt 2 //Die Punkte verschieben
  if (x=x3) and (y=w[3,2]) then inc(x3,form1.Width+100); //Punkt 3 // sich aus dem Spielfeld
  if (x=x4) and (y=w[4,2]) then inc(x4,form1.Width+100); //Punkt 4
  if (x=x5) and (y=w[5,2]) then inc(x5,form1.Width+100); //Punkt 5
  if (x=x6) and (y=w[6,2]) then inc(x6,form1.Width+100); //Punkt 6
  if (x=x7) and (y=w[7,2]) then inc(x7,form1.Width+100); //Punkt 7
  if (x=x8) and (y=w[8,2]) then inc(x8,form1.Width+100); //Punkt 8
  if (x=x9) and (y=w[9,2]) then inc(x9,form1.Width+100); //Punkt 9
  if (x=x10) and (y=w[10,2]) then inc(x10,form1.Width+100); //Punkt 10
  if (x=x11) and (y=w[11,2]) then inc(x11,form1.Width+100); //Punkt 11
  if (x=x12) and (y=w[12,2]) then inc(x12,form1.Width+100); //Punkt 12
  if (x=x13) and (y=w[13,2]) then inc(x13,form1.Width+100); //Punkt 13
  if (x=x14) and (y=w[14,2]) then inc(x14,form1.Width+100); //Punkt 14
  if (x=x15) and (y=w[15,2]) then inc(x15,form1.Width+100); //Punkt 15
  if (x=x16) and (y=w[16,2]) then inc(x16,form1.Width+100); //Punkt 16
  if (x=x17) and (y=w[17,2]) then inc(x17,form1.Width+100); //Punkt 17
  if (x=x18) and (y=w[18,2]) then inc(x18,form1.Width+100); //Punkt 18
  if (x=x19) and (y=w[19,2]) then inc(x19,form1.Width+100); //Punkt 19
  if (x=x20) and (y=w[20,2]) then inc(x20,form1.Width+100); //Punkt 20
  if (x=x21) and (y=w[21,2]) then inc(x21,form1.Width+100); //Punkt 21
  if (x=x22) and (y=w[22,2]) then inc(x22,form1.Width+100); //Punkt 22
  if (x=x23) and (y=w[23,2]) then inc(x23,form1.Width+100); //Punkt 23
  if (x=x24) and (y=w[24,2]) then inc(x24,form1.Width+100); //Punkt 24
  if (x=x25) and (y=w[25,2]) then inc(x25,form1.Width+100); //Punkt 25
  if (x=x26) and (y=w[26,2]) then inc(x26,form1.Width+100); //Punkt 26
  if (x=x27) and (y=w[27,2]) then inc(x27,form1.Width+100); //Punkt 27
  if (x=x28) and (y=w[28,2]) then inc(x28,form1.Width+100); //Punkt 28
  if (x=x29) and (y=w[29,2]) then inc(x29,form1.Width+100); //Punkt 29
  if (x=x30) and (y=w[30,2]) then inc(x30,form1.Width+100); //Punkt 30



  if (x1>form1.Width)and(x2>form1.Width)and(x3>form1.Width)and(x4>form1.Width)and(x5>form1.Width)
  and(x6>form1.Width)and(x7>form1.Width)and(x8>form1.Width)and(x9>form1.Width)and(x10>form1.Width)
  and(x11>form1.Width)and(x12>form1.Width)and(x13>form1.Width)and(x14>form1.Width)and(x15>form1.Width)
  and(x16>form1.Width)and(x17>form1.Width)and(x18>form1.Width)and(x19>form1.Width)and(x20>form1.Width)
  and(x21>form1.Width)and(x22>form1.Width)and(x23>form1.Width)and(x24>form1.Width)and(x25>form1.Width)
  and(x26>form1.Width)and(x27>form1.Width)and(x28>form1.Width)and(x29>form1.Width)and(x30>form1.Width)
  then begin
  canvas.Brush.Color:=fh;
  canvas.rectangle(0,0,Form1.Height,Form1.Width);
  Label1.Visible:=TRUE; // da steht Sie haben gewonnen und so.
  Label2.Visible:=TRUE;
  bitbtn1.Visible:=True;
  showmessage('YOU WIN');

  end else
  if Key = ('d'then begin
  //timer1.Enabled:=True; // TIMER EINSCHALTEN
  Application.ProcessMessages;
  if not (x>form1.Width-80then
  inc(x,s);
  c:=round((Form1.Width-x)/sin(45)*sin(90)); //Fur die Offnungsweite des Pie/maul
canvas.Brush.Color:=fh;
canvas.rectangle(0,0,Form1.Height,Form1.Width);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r); //Koerper
Waende;
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,Form1.Width,y+c,Form1.Width,y-c);
sleep(t);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,Form1.Width,round(y+c/2),Form1.Width,round(y-c/2));
sleep(t);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,Form1.Width,round(y+c/4),Form1.Width,round(y-c/4));
sleep(t);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,Form1.Width,y,Form1.Width,y-1);
canvas.Pen.Color:=clyellow;
canvas.Moveto(x,y);
canvas.Lineto(x+r,y); //Noch ein gelber Strich damit der Mund geschlossen wird
sleep(t);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,Form1.Width,round(y+c/4),Form1.Width,round(y-c/4));
sleep(t);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,Form1.Width,round(y+c/2),Form1.Width,round(y-c/2));
sleep(t);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,Form1.Width,y+c,Form1.Width,y-c);
end


//********************************(NACH LINKS)**********************************

  else
  if Key = 'a' then begin
  Application.ProcessMessages;
  if x>40 then
  dec(x,s);
  c:=round(x/sin(45)*sin(90));
canvas.Brush.Color:=fh;
canvas.rectangle(0,0,Form1.Height,form1.Width);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
Waende;
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,0,y-c,0,y+c);
sleep(t);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,0,round(y-c/2),0,round(y+c/2));
sleep(t);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,0,round(y-c/4),0,round(y+c/4));
sleep(t);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,0,y,0,y+1);
canvas.Pen.Color:=clyellow;
canvas.Moveto(x,y);
canvas.Lineto(x-r,y);
sleep(t);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,0,round(y-c/4),0,round(y+c/4));
sleep(t);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,0,round(y-c/2),0,round(y+c/2));
sleep(t);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,0,y-c,0,y+c);
end

//********************************(NACH OBEN)***********************************

  else
  if Key = 'w' then begin
  Application.ProcessMessages;
  if y>40 then
  dec(y,s);
  c:=round(y/sin(45)*sin(90));
canvas.Brush.Color:=fh;
canvas.rectangle(0,0,Form1.Height,form1.Width);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
Waende;
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,x+c,0,x-c,0);
sleep(t);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,round(x+c/2),0,round(x-c/2),0);
sleep(t);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,round(x+c/4),0,round(x-c/4),0);
sleep(t);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,x+1,0,x,0);
canvas.Pen.Color:=clyellow;
canvas.Moveto(x,y);
canvas.Lineto(x,y-r);
sleep(t);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,round(x+c/4),0,round(x-c/4),0);
sleep(t);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,round(x+c/2),0,round(x-c/2),0);
sleep(t);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,x+c,0,x-c,0);

end

//********************************(NACH UNTEN)**********************************

  else
  if Key = 's' then begin
  Application.ProcessMessages;
  if y<form1.Height-80 then
  inc(y,s);
  c:=round((Form1.Height-y)/sin(45)*sin(90));
canvas.Brush.Color:=fh;
canvas.rectangle(0,0,Form1.Height,form1.Width);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
Waende;
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,x-c,Form1.Height,x+c,Form1.Height);
sleep(t);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,round(x-c/2),Form1.Height,round(x+c/2),Form1.Height);
sleep(t);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,round(x-c/4),Form1.Height,round(x+c/4),Form1.Height);
sleep(t);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,x,Form1.Height,x+1,Form1.Height);
canvas.Pen.Color:=clyellow;
canvas.Moveto(x,y);
canvas.Lineto(x,y+r);
sleep(t);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,round(x-c/4),Form1.Height,round(x+c/4),Form1.Height);
sleep(t);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,round(x-c/2),Form1.Height,round(x+c/2),Form1.Height);
sleep(t);
canvas.Pen.Color:=fh;
canvas.Brush.color:=clyellow;
canvas.Ellipse(x-r,y-r,x+r,y+r);
canvas.Pen.Color:=fm;
canvas.Brush.color:=fm;
canvas.Pie(x-r,y-r,x+r,y+r,x-c,Form1.Height,x+c,Form1.Height);
end;
end;



procedure TForm1.Timer1Timer(Sender: TObject);
var i :integer;
begin
{canvas.Brush.Color:=clWhite;                  //MONSTER Versuch
canvas.Ellipse(mx-r,my-r,mx+r,my+r);
Application.ProcessMessages;
if x > mx then begin
  repeat inc(mx,20) until mx=x end;
if x < mx then begin
  repeat dec(mx,20) until mx=x end;
if y > my then begin
  repeat inc(my,20) until my=y end;
if y < my then begin
  repeat dec(my,20) until my=y end;  }

end;


end.


Ich weis viele würden mir die Suchfunktion usw. empfelen, deswegen gleich: Ich habe google und alle Foren durchgehend durchsucht und keine Antworten gefunden. Es gibt Vorschläge mit arrays für die Wände allerdings ist nirgendwo eine ausgiebige Erklärung vorhanden!


Vielen Dank für eure Hilfe im Voraus


Mikula
Fiete
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 601
Erhaltene Danke: 339

W7
Delphi 6 pro
BeitragVerfasst: Sa 09.03.13 19:22 
Moin Mikula,
versuchs mal hier: www.entwickler-ecke....amp;highlight=pacman

Gruß Fiete

_________________
Fietes Gesetz: use your brain (THINK)
Xion
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
EE-Maler
Beiträge: 1952
Erhaltene Danke: 128

Windows XP
Delphi (2005, SmartInspect), SQL, Lua, Java (Eclipse), C++ (Visual Studio 2010, Qt Creator), Python (Blender), Prolog (SWIProlog), Haskell (ghci)
BeitragVerfasst: So 10.03.13 11:13 
:welcome:

Ich muss zugeben, ich habe etwas Probleme bei deinen Variablen durchzublicken. Globale Variablen wie x sind immer verwirrend, vielleicht fällt dir ja ein aussagekräftiger Name ein ;) Alles in allem sieht das genau so aus, wie meine Programme, die ich zu Beginn geschrieben habe :D

user profile iconMikula hat folgendes geschrieben Zum zitierten Posting springen:
An folgenden Problemen zerbreche ich mir lange den Kopf:
- Wie kann man innere Wände erstellen?
Also Wände im Spielfeld durch die der Pacman (oder wie ich ihn Capman genannt habe)
nicht durch kann

Dazu würde ich ein 2D-Array of boolean benutzen:
ausblenden Delphi-Quelltext
1:
  isBlocked: array [1..50of [1..50array of boolean;					

Hier mal für ein 50x50 Feld. Da setzt du einfach deine Wand-Blöcke rein:
ausblenden Delphi-Quelltext
1:
 isBlocked[42,5] := true;					

Wenn jetzt der Pacman da hin laufen will (z.B. von rechts kommend) musst du nur gucken, ob das Feld blockiert ist:
ausblenden Delphi-Quelltext
1:
2:
 if (isBlocked[ Pacman.x-1, Pacman.y ]) then
  //hier gehts nicht weiter

Wenn du gleich noch den Rand mit in dieses array packst (also die 1-Linien und die 50-Linien mit true besetzt, dann gibts da auch keine Probleme mit dem Rand.

user profile iconMikula hat folgendes geschrieben Zum zitierten Posting springen:
- Wie kann ich monster einfügen?

Die Monster würde ich als array of TMonster machen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
 type TMonster=record
  Color: TColor;
  PosX: integer;
  PosY: integer;
 //...
end
Monsters: array [1..10of TMonster;


user profile iconMikula hat folgendes geschrieben Zum zitierten Posting springen:
Die Monster sollen auf kürzestem Wege den Pacman finden. Sie sollen auch nicht durhch Wände gehen können.

Das mit den Wänden kannst du über das isBlocked-Array überprüfen, wenn sie sich bewegen. Bzw. wenn du den kürzesten Weg hast, dann geht der natürlich durch keine Wand.
Die kürzesten Wege berechnen ist etwas schwieriger. Der Einfachheit wegen würde ich da Breitensuche benutzen.

Noch eine Anmerkung an deinen Monster-Versuch:
Das repeat hat da nix zu suchen, denn das wird ja auf einmal ausgeführt (du siehst also keine Zwischenschritte). Lass das einfach weg, der Timer übernimmt das repeat, da er ja wieder aufgerufen wird.

_________________
a broken heart is like a broken window - it'll never heal
In einem gut regierten Land ist Armut eine Schande, in einem schlecht regierten Reichtum. (Konfuzius)
Xion
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
EE-Maler
Beiträge: 1952
Erhaltene Danke: 128

Windows XP
Delphi (2005, SmartInspect), SQL, Lua, Java (Eclipse), C++ (Visual Studio 2010, Qt Creator), Python (Blender), Prolog (SWIProlog), Haskell (ghci)
BeitragVerfasst: Mi 13.03.13 10:54 
Nach Nachfrage per PN:

Ich habe mal zum ersten Problem ein Beispielprogramm gemacht. Ich hab gleich etwas mehr gemacht:

- ich habe eine Maske als Bild erstellt (das kleine .bmp Bild). Diese enthält die Wände (schwarz). So lässt sich die Karte einfach leichter editieren als im SourceCode :)

- ich lade diese Maske in ein 2D-boolean-array

- möchte sich der Nutzer bewegen, gucke ich, ob an der gewünschten Zielposition eine Wand ist. Wenn ja, dann kann er sich nicht bewegen.
Einloggen, um Attachments anzusehen!
_________________
a broken heart is like a broken window - it'll never heal
In einem gut regierten Land ist Armut eine Schande, in einem schlecht regierten Reichtum. (Konfuzius)
Mikula Threadstarter
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Do 14.03.13 22:39 
Hi,

danke für die Antwort.

leider blicke ich trotzdem nicht ganz durch.. Wie funktioniert das mit dem einlesen in das array?
Wir hatten das nicht in der schule oder so, deswegen verstehe ich irgendwie nur bahnhof ..

Könntest du es an meinem Spiel mit canvas erklären?

Weil alles außer Wände habe ich jetzt hinbekommen.

Gruß

Mikula
Jann1k
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 866
Erhaltene Danke: 43

Win 7
TurboDelphi, Visual Studio 2010
BeitragVerfasst: Do 14.03.13 23:26 
Die Idee von Xion ist folgende: Nehmen wir an dein Spielfeld hat die Größe von 50 x 50. Wir legen einfach ein zweidimensionales Array dieser Größe an und speichert dort an jeder Stelle einen boolschen Wert. True heißt an der Position befindet sich eine Wand, false heißt die Position ist begehbar. Bewegt sich Capman müssen wir nur im Array nachschauen ob die entsprechende Position blockiert ist oder nicht.

Nun ist die Frage, wie wir die Wahrheitswerte ins Array kriegen. Jeden Wert einzeln im Code festzulegen ist aufwendig und nur schwer zu warten. Xion liest deswegen ein Bitmap der Größe 50 x 50 Pixel ein. Ist der Pixel an Position X/Y Schwarz so befindet sich im Spielfeld dort eine Wand array[x,y] wird also auf false gesetzt - andernfalls auf true. So kann man leicht über das Editieren des Bilder Wände hinzufügen und entfernen.

Dir würde ich allerdings erstmal raten, deinen vorhandenen Code etwas aufzubessern. Schleifen habt ihr im Unterricht bestimmt schon besprochen, die solltest du auf alle Fälle einbauen anstatt Dutzende Zeilen zu kopieren und jeweils nur eine Zahl zu ändern.
Mikula Threadstarter
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Sa 16.03.13 16:25 
Wow danke !!!
nach langem Ausprobieren hab ichs tatsächlich hinbekommen :DD

Noch eine kleine Frage, wie kann man so ein Bild erstellen, also die Maske. Wenn ich zb. in Paint einfach ein Viereck zeichne
dann weis ich ja nicht von welchem bis welchem Pixel er geht..
Xion
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
EE-Maler
Beiträge: 1952
Erhaltene Danke: 128

Windows XP
Delphi (2005, SmartInspect), SQL, Lua, Java (Eclipse), C++ (Visual Studio 2010, Qt Creator), Python (Blender), Prolog (SWIProlog), Haskell (ghci)
BeitragVerfasst: Sa 16.03.13 22:11 
user profile iconMikula hat folgendes geschrieben Zum zitierten Posting springen:
Wenn ich zb. in Paint einfach ein Viereck zeichne
dann weis ich ja nicht von welchem bis welchem Pixel er geht..

Hmm, verstehe nicht genau was du meinst :gruebel:

Ich vermute: Du hast das große Bild (das dem Nutzer angezeigt wird) und möchtest daraus die Maske generieren?
:arrow: Ich persönlich würde für ein Spiel garnicht das große Bild benutzen, sondern NUR die Maske. Das Spiel zeichnet dann ein Wand-Bild überall dahin, wo bei der Maske das Bit gesetzt ist, per Canvas z.B.. Genau so, wie du auch die (flexiblen) Punkte einzeichnest ( so wie bei Bomberman: emu-russia.net/gdb/g...Mega_Bomberman_6.png ). In diesem Fall könnte ich dir auch ein paar Bilder machen, musst mir nur genau sagen, was du brauchst ;)

:arrow: Wenn du doch ein großes Bild haben willst (so wie in meiner Demo): Die Maske habe ich durch Skalierung erzeugt. Die Maske ist einfach nur eine kleinere (schwarz-weiß)-Version des Originals. Umgekehrt wärs mit Paint vielleicht einfacher: Male erst die Maske, und Vergrößere sie dann. Dort kannst du dann noch die Optik für den Nutzer etwas aufmöbeln.

Tipp: hol dir dieses Programm: www.pearl.de/a-PK3488-3200.shtml (den vektorbasierten "Designer"). Damit hast du wesentlich mehr möglichkeiten als mit Paint (hab für meine Bilder ca. 5 Minuten gebraucht). Wenns kein Geld kosten darf, kannst du auch mal Inkscape angucken (hab ich aber noch nie benutzt).

_________________
a broken heart is like a broken window - it'll never heal
In einem gut regierten Land ist Armut eine Schande, in einem schlecht regierten Reichtum. (Konfuzius)