الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

لعبة العبث بسطح المكتب

بدأه Delphawi في 27 مارس 2008 · 2 رد · 1,774 مشاهدة · في DirectX
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

بسم الله الرحمن الرحيم

السلام عليكم اخواني ورحمة الله وبركاته

هنا سأشرح مثال بسيط للبنية الأساسية لألعاب العبث بسطح المكتب

البنية الأساسية للعبة :

اللعبة بالتأكيد لا تعبث بسط المكتب مباشرة , وإنما تقوم بعمل Capture لسطح المكتب وتقوم بالتعديل عليه

من خلال مجموعة أدوات الرسم

ما تحتاج إليه :

برنامج Microsoft Visual basic 6

ندخل في الموضوع مباشرة ...

خطوات العمل :

1/ انشئ مشروعا جديدا من النوع القياسي Standard EXE

2/ غير خصائص النموذج لتصبح كالتالي :

BoarderStyle = 0-None

Caption = Destroy DT

WindowState = 2-Maximized

3/ لأخذ لقطة للشاشة , ضع الأمر التالي :


Const RC_PALETTE As Long = &H100
Const SIZEPALETTE As Long = 104
Const RASTERCAPS As Long = 38
Private Type PALETTEENTRY
peRed As Byte
peGreen As Byte
peBlue As Byte
peFlags As Byte
End Type
Private Type LOGPALETTE
palVersion As Integer
palNumEntries As Integer
palPalEntry(255) As PALETTEENTRY
End Type
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
Private Type PicBmp
Size As Long
Type As Long
hBmp As Long
hPal As Long
Reserved As Long
End Type
Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal iCapabilitiy As Long) As Long
Private Declare Function GetSystemPaletteEntries Lib "gdi32" (ByVal hdc As Long, ByVal wStartIndex As Long, ByVal wNumEntries As Long, lpPaletteEntries As PALETTEENTRY) As Long
Private Declare Function CreatePalette Lib "gdi32" (lpLogPalette As LOGPALETTE) As Long
Private Declare Function SelectPalette Lib "gdi32" (ByVal hdc As Long, ByVal hPalette As Long, ByVal bForceBackground As Long) As Long
Private Declare Function RealizePalette Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Function CreateBitmapPicture(ByVal hBmp As Long, ByVal hPal As Long) As Picture
Dim R As Long, Pic As PicBmp, IPic As IPicture, IID_IDispatch As GUID

With IID_IDispatch
.Data1 = &H20400
.Data4(0) = &HC0
.Data4(7) = &H46
End With

With Pic
.Size = Len(Pic)
.Type = vbPicTypeBitmap
.hBmp = hBmp
.hPal = hPal
End With

R = OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)

Set CreateBitmapPicture = IPic
End Function
Function hDCToPicture(ByVal hDCSrc As Long, ByVal LeftSrc As Long, ByVal TopSrc As Long, ByVal WidthSrc As Long, ByVal HeightSrc As Long) As Picture
Dim hDCMemory As Long, hBmp As Long, hBmpPrev As Long, R As Long
Dim hPal As Long, hPalPrev As Long, RasterCapsScrn As Long, HasPaletteScrn As Long
Dim PaletteSizeScrn As Long, LogPal As LOGPALETTE

hDCMemory = CreateCompatibleDC(hDCSrc)
hBmp = CreateCompatibleBitmap(hDCSrc, WidthSrc, HeightSrc)
hBmpPrev = SelectObject(hDCMemory, hBmp)

RasterCapsScrn = GetDeviceCaps(hDCSrc, RASTERCAPS)
HasPaletteScrn = RasterCapsScrn And RC_PALETTE
PaletteSizeScrn = GetDeviceCaps(hDCSrc, SIZEPALETTE)

If HasPaletteScrn And (PaletteSizeScrn = 256) Then
LogPal.palVersion = &H300
LogPal.palNumEntries = 256
R = GetSystemPaletteEntries(hDCSrc, 0, 256, LogPal.palPalEntry(0))
hPal = CreatePalette(LogPal)
hPalPrev = SelectPalette(hDCMemory, hPal, 0)
R = RealizePalette(hDCMemory)
End If

R = BitBlt(hDCMemory, 0, 0, WidthSrc, HeightSrc, hDCSrc, LeftSrc, TopSrc, vbSrcCopy)

hBmp = SelectObject(hDCMemory, hBmpPrev)

If HasPaletteScrn And (PaletteSizeScrn = 256) Then
hPal = SelectPalette(hDCMemory, hPalPrev, 0)
End If

R = DeleteDC(hDCMemory)

Set hDCToPicture = CreateBitmapPicture(hBmp, hPal)
End Function
Private Sub Form_Load()
Set Me.Picture = hDCToPicture(GetDC(0), 0, 0, Screen.Width / Screen.TwipsPerPixelX, Screen.Height / Screen.TwipsPerPixelY)
End Sub
 Public ok As Boolean

طبعا ساخرج عن الدرس إن قمت بتفصيله , لذا ان لم تفهم جملة ما , اذهب إلى منتدى الفاجوال بيزك

هل نفع الكود ؟

نعم , جرب البرنامج ثم حاول الكتابة او ضغط أي زر

لن ينفع

لذا استخدم Alt + Tab للانتقال وإيقاف البرنامج

4/ إضافة أمر الخروج :

الآن رأيت مشكلة عدم القدرة على الخروج من البرنامج , لذا .. أضف الأمر التالي :


If KeyAscii = 27 Then End
End Sub
 Private Sub Form_KeyPress(KeyAscii As Integer)

جرب البرنامج , وللخروج اضغط زر Esc

5/ إضافة أمر الرسم :

سأقوم هنا اختصارا بوضع أمر واحد للرسم , وابداعك يكمل الباقي


Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim i As Integer
If ok = True Then
i = Rnd * 15
If Button = 1 Then
Me.Circle (X, Y), 200, QBColor(i)
End If
End If
End Sub
 :

6/ أمر تحويل مؤشر الفأرة :

ستكون اللعبة بلا طعم دون صور , لذا قم بتحميل الصورة المرفقة , وضعها في القرص C

ثم أضف إلى الحدث Form_KeyPress الأمر :



If KeyAscii = 98 Then
ok = True
Form1.Cls
Me.MousePointer = 99
Me.MouseIcon = LoadPicture("C:\pencil.ico")
End If
End If
If KeyAscii = 27 Then End

أصبح البرنامج جاهزا ولله الحمد والشكر

إلا بعض الأشياء الصغيرة جدا

وجزاكم الله خيرا ,

المشروع مرفق

Destroy_DT.rar

pencil.ico

اقتباس
If A is success in life, then A equals x plus y plus z. Work is x; y is play; and z is keeping your mouth shut

Albert Einstein

مدخل إلى برمجة وتصميم الألعاب : كيف أبدأ ؟

#2

بارك الله فيك :)

rasool4k.gif

[وسط]mimetex.cgi?MSN:root@root-shell.net.

[/وسط]

#3

شكرا لك اخي وبارك الله فيك

ولي عوده بعد التطبيق

Programming Yemen

www.pryem.com

mail:pirate_yemen@hotmail.com

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…