pbInfo.ro
Probleme
Probleme - clasa a IX-a
Probleme - clasa a X-a
Probleme - clasa a XI-a
Probleme din concursuri
Căutare problemă
Exerciții
Programează cu Blockly
Desenează cu Processing
Exersează SQL
Soluţii
Resurse
Resurse pentru clasa a IX-a
Resurse pentru clasa a X-a
Resurse pentru clasa a XI-a
Subiecte bacalaureat
Ajutor
Autentificare
Înregistrare
Autentificare
Utilizator sau email
Parola
Acest site foloseşte cookies. Navigând în continuare, vă exprimaţi acordul asupra folosirii cookie-urilor.
Îti place pbInfo? Atunci acceptă-l cu totul! Dezactivează modulul de blocare a reclamelor!
Lista scripturi
Script Nou
Ajutor
"Script Nou" - Processing
ID
Autor
Duplicat din
Ultima modificare
#6737
6B-Necsulescu Stefan Matei (Stefan_Matei_Necsulescu)
-
Sambata, 17 mai 2025, 13:16
#include
#include
#include
const int SCREEN_WIDTH = GetSystemMetrics(SM_CXSCREEN); const int SCREEN_HEIGHT = GetSystemMetrics(SM_CYSCREEN); const int PLAYER_SIZE = 60; const int ZOMBIE_SIZE = 60; const int SPEED = 5; const int GRAVITY = 2; const int FLOOR_HEIGHT = 20; const int MAX_LIVES = 3; const int DAMAGE_COOLDOWN = 1000; const int TORNADO_DURATION = 10000; const int TORNADO_COOLDOWN = 30000; const int TORNADO_SIZE = 100; const int TORNADO_SPEED = 10; const int MAX_AMMO = 7; const int RELOAD_TIME = 6000; int GROUND_Y = SCREEN_HEIGHT - PLAYER_SIZE - FLOOR_HEIGHT; struct Tornado { int x, y; bool active = false; DWORD startTime = 0; void activate(int startX, int startY, int level) { if (!active && GetTickCount() - startTime > TORNADO_COOLDOWN && level == 1) { x = startX; y = startY; active = true; startTime = GetTickCount(); } } void update() { if (active && GetTickCount() - startTime > TORNADO_DURATION) { active = false; } } }; struct Zombie { int x, y, health = 3; bool alive = true; DWORD lastAttackTime = 0; void update(int playerX) { if (alive) x += (playerX > x) ? 2 : -2; } bool canDamage() { DWORD currentTime = GetTickCount(); return (currentTime - lastAttackTime > DAMAGE_COOLDOWN); } }; struct Bullet { int x, y; bool active = true; }; struct Player { int x, y, dx, dy, lives = MAX_LIVES; int level = 1; bool onGround, facingRight; int ammo = MAX_AMMO; DWORD lastReloadTime = 0; void update() { x += dx; y += dy; if (y >= GROUND_Y) { y = GROUND_Y; dy = 0; onGround = true; } else dy += GRAVITY; } void jump() { if (onGround) { dy = -20; onGround = false; } } void reload() { DWORD currentTime = GetTickCount(); if (currentTime - lastReloadTime > RELOAD_TIME) { ammo = MAX_AMMO; lastReloadTime = currentTime; } } }; Player player = {SCREEN_WIDTH / 2, GROUND_Y, 0, 0, MAX_LIVES, 1, true, true}; std::vector
zombies = {{100, GROUND_Y}, {300, GROUND_Y}, {500, GROUND_Y}}; std::vector
bullets; Tornado tornado; void checkCollisions() { for (auto& zombie : zombies) { if (zombie.alive && player.x >= zombie.x && player.x <= zombie.x + ZOMBIE_SIZE) { if (zombie.canDamage()) { player.lives--; zombie.lastAttackTime = GetTickCount(); if (player.lives < 0) player.lives = 0; } } } } void checkBulletCollisions() { for (auto& bullet : bullets) { for (auto& zombie : zombies) { if (zombie.alive && bullet.x >= zombie.x && bullet.x <= zombie.x + ZOMBIE_SIZE) { zombie.health -= 1; bullet.active = false; if (zombie.health <= 0) zombie.alive = false; } } } } void checkTornadoDamage() { if (tornado.active) { for (auto& zombie : zombies) { if (zombie.alive && zombie.x >= tornado.x && zombie.x <= tornado.x + TORNADO_SIZE) { zombie.health -= 1; if (zombie.health <= 0) zombie.alive = false; } } } } void drawHUD(HDC hdc) { char levelText[20]; sprintf(levelText, "Level: %d", player.level); TextOut(hdc, 10, 10, levelText, strlen(levelText)); char livesText[20]; sprintf(livesText, "Lives: %d", player.lives); TextOut(hdc, SCREEN_WIDTH - 100, 10, livesText, strlen(livesText)); char ammoText[20]; sprintf(ammoText, "Ammo: %d", player.ammo); TextOut(hdc, SCREEN_WIDTH / 2 - 50, 10, ammoText, strlen(ammoText)); } void shoot() { if (player.ammo > 0) { bullets.push_back({player.x + PLAYER_SIZE / 2, player.y + PLAYER_SIZE / 2}); player.ammo--; } } LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_KEYDOWN: if (wParam == 'A') { player.dx = -SPEED; player.facingRight = false; } else if (wParam == 'D') { player.dx = SPEED; player.facingRight = true; } else if (wParam == VK_SPACE) player.jump(); else if (wParam == '1') tornado.activate(player.x, player.y, player.level); else if (wParam == VK_SHIFT) shoot(); else if (wParam == 'R') player.reload(); break; case WM_KEYUP: if (wParam == 'A' || wParam == 'D') player.dx = 0; break; case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); FillRect(hdc, &ps.rcPaint, CreateSolidBrush(RGB(0, 0, 0))); // Desenează terenul RECT groundRect = {0, GROUND_Y + PLAYER_SIZE, SCREEN_WIDTH, SCREEN_HEIGHT}; FillRect(hdc, &groundRect, CreateSolidBrush(RGB(100, 50, 20))); // Desenează zombii for (auto &zombie : zombies) { if (zombie.alive) { RECT zombieRect = {zombie.x, zombie.y, zombie.x + ZOMBIE_SIZE, zombie.y + ZOMBIE_SIZE}; FillRect(hdc, &zombieRect, CreateSolidBrush(RGB(255, 0, 0))); Ellipse(hdc, zombie.x + 15, zombie.y + 15, zombie.x + 25, zombie.y + 25); Ellipse(hdc, zombie.x + 35, zombie.y + 15, zombie.x + 45, zombie.y + 25); } } // Desenează jucătorul RECT playerRect = {player.x, player.y, player.x + PLAYER_SIZE, player.y + PLAYER_SIZE}; FillRect(hdc, &playerRect, CreateSolidBrush(RGB(255, 255, 255))); // Desenează tornada ca triunghi albastru if (tornado.active) { POINT tornadoPoints[3] = { {tornado.x, tornado.y + TORNADO_SIZE}, {tornado.x + TORNADO_SIZE / 2, tornado.y}, {tornado.x + TORNADO_SIZE, tornado.y + TORNADO_SIZE} }; SelectObject(hdc, CreateSolidBrush(RGB(0, 0, 255))); Polygon(hdc, tornadoPoints, 3); } // Desenează gloanțele for (auto& bullet : bullets) { if (bullet.active) { RECT bulletRect = {bullet.x, bullet.y, bullet.x + 10, bullet.y + 5}; FillRect(hdc, &bulletRect, CreateSolidBrush(RGB(255, 255, 0))); } } drawHUD(hdc); EndPaint(hwnd, &ps); } break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; } void updateBullets() { for (auto& bullet : bullets) { if (bullet.active) { bullet.x += SPEED * 2; // Se deplasează rapid spre dreapta } } } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASS wc = {0}; wc.lpfnWndProc = WindowProc; wc.hInstance = hInstance; wc.lpszClassName = "PlatformerGame"; RegisterClass(&wc); HWND hwnd = CreateWindow(wc.lpszClassName, "Platformer Game", WS_POPUP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL); ShowWindow(hwnd, SW_SHOWMAXIMIZED); MSG msg; while (true) { while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) return 0; TranslateMessage(&msg); DispatchMessage(&msg); } player.update(); tornado.update(); updateBullets(); checkCollisions(); checkBulletCollisions(); checkTornadoDamage(); for (auto &zombie : zombies) zombie.update(player.x); InvalidateRect(hwnd, NULL, TRUE); Sleep(16); } return 0; }
Duplicare
Executare
Cod
×
Cod HTML
<iframe sandbox="allow-scripts" src="/p5js/index.php?id=6737" style="width:408px; height:408px;border:solid 1px gray; overflow: scroll;"></iframe>
×
Duplicare script
Denumirea noului script
Du-te sus!