Autor Beitrag
Tomac
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 113

Win XP
D6 Ent
BeitragVerfasst: Sa 13.07.02 13:34 
Hallo

Ich bin dabei, für mienen kleinen Bruder ein ganz simples Pacman Spiel zu programmieren.
Ich erstelle ein Level folgendermaßen:

ausblenden volle Höhe 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:
var 
arr: array[0..14, 0..14] of integer =
 ( (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
   (1,0,0,0,0,0,0,0,0,0,0,0,0,0,1),
   (1,0,1,1,1,1,1,0,1,1,1,1,1,0,1),
   (1,0,1,0,0,0,0,0,0,0,0,0,1,0,1),
   (1,0,1,0,1,1,1,0,1,1,1,0,1,0,1),
   (1,0,1,0,1,0,0,0,0,0,1,0,1,0,1),
   (1,0,1,0,1,0,0,0,0,0,1,0,1,0,1),
   (1,0,0,0,0,0,0,0,0,0,0,0,0,0,1),
   (1,0,1,0,1,0,0,0,0,0,1,0,1,0,1),
   (1,0,1,0,1,0,0,0,0,0,1,0,1,0,1),
   (1,0,1,0,1,1,1,0,1,1,1,0,1,0,1),
   (1,0,1,0,0,0,0,0,0,0,0,0,1,0,1),
   (1,0,1,1,1,1,1,0,1,1,1,1,1,0,1),
   (1,0,0,0,0,0,0,0,0,0,0,0,0,0,1),
   (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1))

{...}

procedure TForm1.PaintBox1Paint(Sender: TObject);
var
x: integer;
y: integer;
begin
for x := 0 to 14 do begin
  for y := 0 to 14 do begin
    case arr[y, x] of
      0: PaintBox1.Canvas.CopyRect(Rect(x*20, y*20, (x*20)+20, (y*20)+20),
           food.Canvas, Rect(0, 0, 20, 20));
      1: PaintBox1.Canvas.CopyRect(Rect(x*20, y*20, (x*20)+20, (y*20)+20),
           wall.Canvas, Rect(0, 0, 20, 20));
      2: PaintBox1.Canvas.CopyRect(Rect(x*20, y*20, (x*20)+20, (y*20)+20),
           empty.Canvas, Rect(0, 0, 20, 20));
    end;
  end;
end;
end;


Die Bewegung habe ich so gemacht, dass das Bild des Pacman (20*20) mit Hilfe eines Timers immer genau um 1 Feld (also auch 20*20) schön flüssig bewegt wird.

Mein Problem ist nun, dass ich nicht weiß, wie ich es machen kann, dass sich das Bild des Pacman nur auf den Feldern "0" bzw. "2" bewegen kann.
Wenn ich zum Beispiel nach rechts drücke, rechts vom Pacman ist aber eine Wand ("1"), dann soll gar nichts geschehen. :?:

Vielen Dank im Voraus

mfG
Tomac
MathiasH
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 699

WinXP, Win98SE, Debian, Win95
D5 Stand, D6 Prof
BeitragVerfasst: Sa 13.07.02 13:50 
du musst vor der bewegung, des Pacmans die zukünfige Koordinate(im Array!!!) abfragen, und wenn sie nicht 0 oder 2 -wertig ist wird nichts bewegt.

etwa so

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var
 pacX, pacY: Smallint; //Koordinate des Pacmans
 dirX, dirY: Shortint;    //bewegunswerte des Pacmans (-1, 0, 1)
begin
 if arr[pacX + dirX, pacY + dirY] = 1 then begin
  showmessage('keine Bewegung Möglich');
 end
 else begin
  pacX := pacX + dirX;
  pacY := pacY + dirY;
 end;
end;


MathiasH

_________________
"Viel von sich reden, kann auch ein Mittel sein, sich zu verbergen."
Friedrich Nietzsche
Tomac Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 113

Win XP
D6 Ent
BeitragVerfasst: Sa 13.07.02 15:37 
Titel: kollision
Danke, aber ich komm damit nicht ganz klar. Könntest du mir bitte sagen, wie ich das jetzt genau einbauen muss?

hier der gesamte bisherige Code:

ausblenden volle Höhe 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:
var
  Form1: TForm1;
  mousex: integer;
  mousey: integer;
  var i:integer = 0;
  aup, adown, aleft, aright: boolean;
  arr: array[0..14, 0..14] of integer =
 ( (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
   (1,0,0,0,0,0,0,0,0,0,0,0,0,0,1),
   (1,0,1,1,1,1,1,0,1,1,1,1,1,0,1),
   (1,0,1,0,0,0,0,0,0,0,0,0,1,0,1),
   (1,0,1,0,1,1,1,0,1,1,1,0,1,0,1),
   (1,0,1,0,1,0,0,0,0,0,1,0,1,0,1),
   (1,0,1,0,1,0,0,0,0,0,1,0,1,0,1),
   (1,0,0,0,0,0,0,0,0,0,0,0,0,0,1),
   (1,0,1,0,1,0,0,0,0,0,1,0,1,0,1),
   (1,0,1,0,1,0,0,0,0,0,1,0,1,0,1),
   (1,0,1,0,1,1,1,0,1,1,1,0,1,0,1),
   (1,0,1,0,0,0,0,0,0,0,0,0,1,0,1),
   (1,0,1,1,1,1,1,0,1,1,1,1,1,0,1),
   (1,0,0,0,0,0,0,0,0,0,0,0,0,0,1),
   (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1))

  ;


implementation

{$R *.dfm}

procedure TForm1.PaintBox1Paint(Sender: TObject);
var
x: integer;
y: integer;
begin
for x := 0 to 14 do begin
  for y := 0 to 14 do begin
    case arr[y, x] of
      0: PaintBox1.Canvas.CopyRect(Rect(x*20, y*20, (x*20)+20, (y*20)+20),
           food.Canvas, Rect(0, 0, 20, 20));
      1: PaintBox1.Canvas.CopyRect(Rect(x*20, y*20, (x*20)+20, (y*20)+20),
           wall.Canvas, Rect(0, 0, 20, 20));
      2: PaintBox1.Canvas.CopyRect(Rect(x*20, y*20, (x*20)+20, (y*20)+20),
           empty.Canvas, Rect(0, 0, 20, 20));
    end;
  end;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var i,j:integer;
begin
doublebuffered:=true;
pacman.left:=paintbox1.left+20;
pacman.top:=paintbox1.Top+20;
memo1.Lines.loadfromfile(extractfilepath(application.exename)+'level.ini');
end;

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
label1.caption:=inttostr(pacman.left);
label2.caption:=inttostr(pacman.top);
label3.Caption:=inttostr(arr[pacman.Left,pacman.top]);
if timer1.enabled=true then key:=vk_space;
case key of
  vk_down: begin
           timer1.enabled:=true;
           adown:=true; aup:=false; aleft:=false; aright:=false;
           end;
  vk_right: begin
            timer1.enabled:=true;
            adown:=false; aup:=false; aleft:=false; aright:=true;
            end;
  vk_left: begin
            timer1.enabled:=true;
            adown:=false; aup:=false; aleft:=true; aright:=false;
            end;
  vk_up: begin
            timer1.enabled:=true;
            adown:=false; aup:=true; aleft:=false; aright:=false;
            end;
end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
if adown then begin
pacman.Top:=pacman.Top+2;
i:=i+1;
if i=10 then begin
timer1.enabled:=false;
i:=0;
end;
end;


if aright then begin
pacman.left:=pacman.left+2;
i:=i+1;
if i=10 then begin
timer1.enabled:=false;
i:=0;
end;
end;

if aleft then begin
pacman.left:=pacman.left-2;
i:=i+1;
if i=10 then begin
timer1.enabled:=false;
i:=0;
end;
end;

if aup then begin
pacman.top:=pacman.top-2;
i:=i+1;
if i=10 then begin
timer1.enabled:=false;
i:=0;
end;
end;

end;

end.


THX
Tomac
MathiasH
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 699

WinXP, Win98SE, Debian, Win95
D5 Stand, D6 Prof
BeitragVerfasst: Sa 13.07.02 20:31 
wenn du mir deine E-mail adresse( als Persönliche Nachricht) gibst, kann ich dir den Sourcecode eines kleinen Snake Spiels schicken, das Funzt fast genauso.

_________________
"Viel von sich reden, kann auch ein Mittel sein, sich zu verbergen."
Friedrich Nietzsche
Lobo
Hält's aus hier
Beiträge: 7



BeitragVerfasst: Mo 19.08.02 22:07 
Titel: Snake Spiel
hi Mathias,
kannst du mir das Snake Spiel mal schicken?
Würde mich mal interessieren, wie der Sourcecode aussieht.

Danke

Lobo

e-Mail: st_rieker@hotmail.com

_________________
"Habe Mut, dich deines eigenen Verstandes zu bedienen"
Immanuel Kant
Tommy82
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: Mi 21.08.02 13:53 
Titel: Snake Spiel
Hallo, könntest du8 mir bitte auch mal den Quelltext zu deinem Snake-Spiel schicken ? Mein Problem ist fast dasselbe.
Danke

email.: goettsching@gmx.net
MathiasH
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 699

WinXP, Win98SE, Debian, Win95
D5 Stand, D6 Prof
BeitragVerfasst: Do 22.08.02 09:44 
mach ich
*Quelltextummichschmeiß*

noch jemand?, irgendwie komisch, ich glaub das Speil hab ich schon 20 mal gebastelt :wink:

MathiasH

_________________
"Viel von sich reden, kann auch ein Mittel sein, sich zu verbergen."
Friedrich Nietzsche
Tommy82
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: Do 22.08.02 11:28 
Titel: Thanks
Danke, vielleicht hilft mir das ja weiter
Lobo
Hält's aus hier
Beiträge: 7



BeitragVerfasst: Sa 24.08.02 02:01 
Titel: Danke für Snake
Hallo Alexander, bzw. Mathias,
ich danke dir für das Snake, werde es mir gleich mal anschauen, wie du das ganze bewältigt hast.

viele Grüße

Lobo

P.S. Sorry, wenn ich dich in der Mail falsch angesprochen habe!

_________________
"Habe Mut, dich deines eigenen Verstandes zu bedienen"
Immanuel Kant
MathiasH
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 699

WinXP, Win98SE, Debian, Win95
D5 Stand, D6 Prof
BeitragVerfasst: Sa 24.08.02 14:44 
Aber passt auf, das spiel ist voll von kleinen Fehlern und Unzulänglichkeiten., dafür hats aber auch nur ne halbe Stunde gedauert zu schreiben :wink:

MathiasH

_________________
"Viel von sich reden, kann auch ein Mittel sein, sich zu verbergen."
Friedrich Nietzsche
Fabian
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 42



BeitragVerfasst: Mi 11.09.02 18:44 
Hallo

Könntest du mir bitte auch den Quelltext zu deinem Snake-Spiel schicken ? Ich habe ein ähnliches Problem.

E-mail: [url]F.Berstecher@gmx.de[/url]

Danke