Skip to content

Commit b21644b

Browse files
<!DOCTYPE html>
<html> <head> <title>لعبة JavaScript بسيطة</title> <style> canvas { border: 1px solid black; } </style> </head> <body> <canvas id="gameCanvas" width="800" height="600"></canvas> <script> const canvas = document.getElementById("gameCanvas"); const ctx = canvas.getContext("2d"); let player = { x: 400, y: 500, width: 50, height: 50, speed: 5 }; function drawPlayer() { ctx.fillStyle = "red"; ctx.fillRect(player.x, player.y, player.width, player.height); } function gameLoop() { ctx.clearRect(0, 0, canvas.width, canvas.height); drawPlayer(); requestAnimationFrame(gameLoop); } window.addEventListener("keydown", (e) => { if (e.key === "ArrowLeft" && player.x > 0) player.x -= player.speed; if (e.key === "ArrowRight" && player.x < canvas.width - player.width) player.x += player.speed; }); gameLoop(); </script> </body> using UnityEngine; public class PlayerMovement : MonoBehaviour { public float moveSpeed = 5f; void Update() { float horizontal = Input.GetAxis("Horizontal"); float vertical = Input.GetAxis("Vertical"); Vector3 movement = new Vector3(horizontal, 0f, vertical) * moveSpeed * Time.deltaTime; transform.Translate(movement); } }import pygame pygame.init() # إنشاء نافذة اللعبة screen = pygame.display.set_mode((800, 600)) pygame.display.set_caption("لعبة بسيطة") # اللاعب (مربع صغير) player = pygame.Rect(400, 500, 50, 50) player_speed = 5 # اللعبة تعمل running = True while running: screen.fill((0, 0, 0)) # خلفية سوداء for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # تحريك اللاعب بالأزرار keys = pygame.key.get_pressed() if keys[pygame.K_LEFT] and player.x > 0: player.x -= player_speed if keys[pygame.K_RIGHT] and player.x < 750: player.x += player_speed pygame.draw.rect(screen, (255, 0, 0), player) # رسم اللاعب pygame.display.update() pygame.quit() </html>
1 parent 51f80c0 commit b21644b

File tree

0 file changed

+0
-0
lines changed

    0 file changed

    +0
    -0
    lines changed

    0 commit comments

    Comments
     (0)