delphiX obrót sprite'a a poruszanie

0

witam

jest taka procedurka

var
x, y, width, height, 0, px, py, obr : integer 
DXImageList1.Items.Find('grafika').DrawRotate.dxdraw1.Surface,x,y,width,height,0,px,py,obr);

px, py - punkty obrotu obrazka, obr - obrót
chodzi mi o taki efekt ze gdy poruszam spirte'm np y := y + 1; to aby ruszył sie w tym kierunku w jakim stopniu jest obrocony spirte czyli według zmiennej obr
nie wiem jak to zrobic...prosze o jakies rady :-)

dzeki za pomoc
pozdro

0

Podstawowa trygonometria albo macierz obrotu.

Co to ma do inzynierii oprogramowania?

0

ze co? [glowa]

ale co maja do tego operacje na macierzach? patrzalem cos na ten temat i raczej nie bardzo...:/

moze ktos wie konkretnie?

0

jak coś nie działa to nie wiem nie mam nawet delphi zainstalowanego :S

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, DXDraws, DXSprite, DXClass, Noxxdxsprite, DXInput, ExtCtrls;

type
  TForm1 = class(TForm)
    DXDraw1: TDXDraw;
    DXImageList1: TDXImageList;
    DXTimer1: TDXTimer;
    DXSpriteEngine1: TDXSpriteEngine;
    Noxxdxsprite1: TNoxxdxsprite;
    DXInput1: TDXInput;
    procedure DXTimer1Timer(Sender: TObject; LagCount: Integer);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
   procedure check_enemy_bullet_collide;
  end;

  
type tbullet = record
x,y  : single;
leci : boolean;
kat  : byte;
end;

type tstatek = record
name : string;
health : integer;
x,y  : single;
kat  : byte;
clip : array[0..6] of tbullet;
speedup : byte;
end;

type tdraw_now = (tdngame, tdnstart, tdnfinish, tdnfalse);
type mywall = record
x,y : integer;
health : integer;
end;

const
spdup_max = 10;

var
  Form1: TForm1;
  statek : tstatek;
  speedup_pressed : boolean;
  spdup_actual : integer;
  shot : integer = -1;
  rysuje : tdraw_now;
  mureq : array[0..11] of mywall;

procedure move_statek(up : boolean);
procedure move_bullet(incb : byte);
procedure sshot;

implementation
uses math;

{$R *.DFM}




procedure tform1.check_enemy_bullet_collide;
var
i,i2 : byte;
begin
for i:=0 to 6 do
if statek.clip[i].leci = true then
for i2:=0 to 11 do
if noxxdxsprite1.collision(statek.clip[i].x,statek.clip[i].y,4,4,mureq[i2].x,mureq[i2].y,31,19) = true then
mureq[i2].health := mureq[i2].health - 10;
end;

procedure move_bullet(incb : byte);
begin
statek.clip[incb].x := -statek.clip[incb].x*0.05*sin256(statek.clip[incb].kat) + statek.clip[incb].x;
statek.clip[incb].y :=  statek.clip[incb].y*0.05*cos256(statek.clip[incb].kat) + statek.clip[incb].y;
end;

procedure sshot;
begin
inc(shot);
if shot >= 6 then
shot := 0;
sleep(10);
statek.clip[shot].kat := statek.kat;
statek.clip[shot].x := statek.x;
statek.clip[shot].y := statek.y;
statek.clip[shot].leci := true;
end;

procedure move_statek(up : boolean);
begin
if up = true then
begin
statek.x := -statek.speedup*sin256(statek.kat) + statek.x;
statek.y :=  statek.speedup*cos256(statek.kat) + statek.y;
end else
begin
statek.x :=  statek.speedup*sin256(statek.kat) + statek.x;
statek.y := -statek.speedup*cos256(statek.kat) + statek.y;
end;


end;

procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
var
ishot,i,i2 : byte;
begin
if rysuje  = tdnfalse then exit;
dxdraw1.Surface.fill(0);
if rysuje = tdngame then
begin
DXInput1.Update;
//ruch dla statku 1

if (isleft  in dxinput1.States)   then statek.kat := statek.kat - 2;
if (isright in dxinput1.States)   then statek.kat := statek.kat + 2;
if statek.kat > 255       then statek.kat := 0;
if statek.kat < 0         then statek.kat := 255;
if (isup      in dxinput1.states) then move_statek(true);
if (isdown    in dxinput1.states) then move_statek(false);
if (isbutton1 in dxinput1.states) then sshot;
if (isbutton2 in dxinput1.states) then
begin
spdup_actual := 0;
speedup_pressed := true;
statek.speedup := 4;
end;


if speedup_pressed = true then
begin
inc(spdup_actual);
if spdup_actual >= spdup_max then
begin
statek.speedup := 2;
spdup_actual := 0;
speedup_pressed := false;
end;
end;
check_enemy_bullet_collide;

for i2:=0 to 11 do
if mureq[i2].health > 0 then
DXImagelist1.Items[3].Draw(dxdraw1.surface,mureq[i2].x,mureq[i2].y,0);



//eof ruch dla statku 1
DXImagelist1.Items[0].DrawRotate(DXDraw1.Surface,
round(statek.x),
round(statek.y),
11,
11,
0,
0.55,
0.55,
trunc(statek.kat));

for ishot:=0 to 6 do
if statek.clip[ishot].leci = true then
begin
if not noxxdxsprite1.collision(statek.clip[ishot].x,statek.clip[ishot].y,4,4,0,0,form1.width,form1.height) then
statek.clip[ishot].leci := false;

DXImagelist1.Items[2].DrawRotate(DXDraw1.Surface,
round(statek.clip[ishot].x),
round(statek.clip[ishot].y),
11,
11,
0,
0.55,
0.55,
trunc(statek.clip[ishot].kat));


move_bullet(ishot);
end;


end;

if rysuje = tdnfinish  then
close;

//koniec rysowania gry :)
DXDraw1.Flip;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
i,i2 : integer;
begin
randomize;
rysuje := tdnfalse;
for i:=0 to 6 do
begin
statek.clip[i].kat := statek.kat;
statek.clip[i].x := statek.x;
statek.clip[i].y := statek.y;
statek.clip[i].leci := false;
end;
statek.health := 120;
statek.x := 24;
statek.y := 200;
statek.kat := 0;
statek.speedup := 2;
for i2:=0 to 11 do
begin
mureq[i2].health := 100;
mureq[i2].x := random(form1.width);
mureq[i2].y := random(form1.height);
end;
rysuje := tdngame;
end;

end.

Najlepsze jest to ze ta gierka to byl prezent urodzinowy :] I mozna latac i strzelac do scian :X

0
AdamK86 napisał(a)

ze co? [glowa]

ale co maja do tego operacje na macierzach? patrzalem cos na ten temat i raczej nie bardzo...:/

moze ktos wie konkretnie?

x+=sin(alpha)*speed;
y+=cos(alpha)*speed;

Pokombinuj z plusami i minusami jakby się poruszał nie w tą stronę co trzeba.

1 użytkowników online, w tym zalogowanych: 0, gości: 1