Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <graphics.h>
- #include <windows.h>
- #include <iostream>
- #include <stdio.h>
- #include <winbgim.h>
- #include <process.h>
- using namespace std;
- void ruch();
- class Obiekt;
- int licz;
- int x, y, przyspieszenie=10, szybkosc=5;
- int szerOkna, wysOkna;
- class Obiekt
- {
- public:
- int x, y, w, h;
- int speed;
- enum Direction
- {
- gora,
- dol,
- prawo,
- lewo
- };
- Direction direction;
- Obiekt(int iks=0, int igrek=0, int width=15, int height=15, int sp=1)
- {
- x = iks;
- y = igrek;
- w = width;
- h = height;
- speed = sp;
- }
- };
- Obiekt obiekty[10];
- obiekty[0].direction = Obiekt.Direction.dol;
- int main( )
- {
- DWORD mode;
- INPUT_RECORD event;
- initwindow(400, 400, "Graficzny Program >.<", 80, 250);
- szerOkna = getwindowwidth();
- wysOkna = getwindowheight();
- HANDLE hstdin = GetStdHandle( STD_INPUT_HANDLE );
- GetConsoleMode( hstdin, &mode );
- SetConsoleMode( hstdin, 0 );
- while (true)
- {
- Sleep(10);
- {
- ruch();
- }
- setbkcolor(123);
- if (WaitForSingleObject( hstdin, 0 ) == WAIT_OBJECT_0)
- {
- DWORD count;
- ReadConsoleInput( hstdin, &event, 1, &count );
- if(event.Event.KeyEvent.wVirtualKeyCode == VK_LEFT){
- printf("lewo\n");
- x-= szybkosc;
- ruch();
- }
- if(event.Event.KeyEvent.wVirtualKeyCode == VK_RIGHT){
- printf("prawo\n");
- x+= szybkosc;
- ruch();
- }
- if(event.Event.KeyEvent.wVirtualKeyCode == VK_DOWN){
- printf("dol\n");
- y+= szybkosc;
- ruch();
- }
- if(event.Event.KeyEvent.wVirtualKeyCode == VK_UP){
- printf("gora\n");
- y-= szybkosc;
- ruch();
- }
- }
- }
- while (!kbhit( ))
- {
- delay(200);
- }
- return 0;
- }
- void ruch()
- {
- cleardevice();
- for(int i=0; i<(sizeof(obiekty)/sizeof(*obiekty)); i++)
- {
- if(i == 0)
- bar(x, y, x+15, y+15);
- else
- bar(obiekty[i].x, obiekty[i].y, obiekty[i].x+obiekty[i].w, obiekty[i].y+obiekty[i].h);
- if(obiekty[i].direction == Obiekt.Direction.dol)
- obiekty[i].y+=obiekty[i].speed;
- else if(obiekty[i].direction == Obiekt.Direction.gora)
- obiekty[i].y-=obiekty[i].speed;
- else if(obiekty[i].direction == Obiekt.Direction.lewo)
- obiekty[i].x-=obiekty[i].speed;
- else if(obiekty[i].direction == Obiekt.Direction.prawo)
- obiekty[i].x+=obiekty[i].speed;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement