Jump to content

I need some help with my Super Mario game


E1M1
 Share

Recommended Posts

I am trying to create my own supermario game, but I have some problems with it(I have tried to fix these but I can't find out how to do it).

1) If I load sky from image then timer disapear soon as I press arrow keys, also char disappear for a short time and then comes back on screen.

2) If use AdlibEnable("timer", 1000) to discount time then I can't move at all.

3) If I shoot missile then I can't move until it flies.

4) While I am moving up or down, I can't move left or right at that time.

And how to make it auto scroll level?

How to make 2 and more things move at same time? I need to move my char and missile (and later monsters) at same time, but I have no idea how.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <WinAPI.au3>
#Include <GDIPlus.au3>

Dim $char
$CharLeftDefault = 10
$CharTopDefault = 371
$CharLeft = $CharLeftDefault
$CharTop = $CharTopDefault
$sv_speed = 10
$sv_gravity = 0.3
$titleBarHeitht = 25
$w_fireball_missile_speed = 20
;~ $w_fireball_missile_Damage = 75
;~ $w_iceblast_missile_speed = 2
;~ $w_iceblast_missile_Damage = 30
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Mario", 640, 480)
GUISetBkColor(0x99D9EA);Instead of Addsky()
;~ GUISetBkColor(0x000000)
$timer = GUICtrlCreateLabel(400,0,0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$dll = DllOpen("user32.dll")
Level()
AdlibEnable("input", 25)
;~ AdlibEnable("timer", 1000)
While GUIGetMsg() <> -3
    Sleep(25)
    If $CharTop > 430 Then
        GameOver()
    EndIf
    If $CharLeft > 620 Then
        Win()
    EndIf
    $pos = WinGetPos($Form1)
    If PixelGetColor($pos[0] + $CharLeft, $pos[1] + $CharTop + 50 + $titleBarHeitht, $Form1) = 0x99D9EA Then
;~  If PixelGetColor($pos[0] + $CharLeft, $pos[1] + $CharTop + 50 + $titleBarHeitht, $Form1) = 0x000000 Then
        $CharTop += $sv_speed * $sv_gravity
        GUICtrlSetPos($char, $CharLeft, $CharTop)
    EndIf
WEnd

Func Level()
    $LevelWidth = 640
    AddChar(10, 371, 26, 49)
    AddGround(0, 420, 320, 60)
    AddGround(450, 420, 320, 60)
;~  AddSky($LevelWidth)
EndFunc   ;==>Level

Func AddSky($LevelWidth)
    GUICtrlCreatePic("sky.bmp", 0, 0, $LevelWidth, 480, $GUI_DISABLE)
EndFunc   ;==>AddSky

Func AddGround($left, $top, $width, $height)
    GUICtrlCreatePic("ground.bmp", $left, $top, $width, $height, $GUI_ONTOP)
EndFunc   ;==>AddGround

Func AddChar($left, $top, $width, $height)
    $char = GUICtrlCreatePic("char.bmp", $left, $top, $width, $height, $GUI_ONTOP)
    GUICtrlSetBkColor(-1, 0x99D9EA)
EndFunc   ;==>AddChar

Func GameOver()
    MsgBox(0, 0, "Game Over")
    $CharLeft = $CharLeftDefault
    $CharTop = $CharTopDefault
    GUICtrlSetPos($char, $CharLeft, $CharTop)
EndFunc   ;==>GameOver

Func Summon($sText, $iX, $iY)
    Switch $sText
        Case "fireball"
    Return GUICtrlCreatePic("missile.bmp", $iX, $iY, 20, 20)
    EndSwitch
EndFunc   ;==>Summon

Func ShootMissile($ID, $iStartX, $iStartY, $missile_speed)
    While $iStartX < 640
        $iStartX += $missile_speed
        Sleep(50)
        GUICtrlSetPos($ID, $iStartX, $iStartY)
    WEnd
    GUICtrlDelete($ID)
EndFunc   ;==>ShootMissile

Func Input()
    If _IsPressed("27", $dll) Then
        $CharLeft += $sv_speed
        GUICtrlSetPos($char, $CharLeft, $CharTop)
        _WinAPI_RedrawWindow(GUICtrlGetHandle($char), "", "", BitOR($WM_ERASEBKGND, $RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME))
    ElseIf _IsPressed("25", $dll) Then
        $CharLeft -= $sv_speed
        GUICtrlSetPos($char, $CharLeft, $CharTop)
        _WinAPI_RedrawWindow(GUICtrlGetHandle($char), "", "", BitOR($WM_ERASEBKGND, $RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME))
    ElseIf _IsPressed("28", $dll) Then
        $CharTop += $sv_speed
        GUICtrlSetPos($char, $CharLeft, $CharTop)
        _WinAPI_RedrawWindow(GUICtrlGetHandle($char), "", "", BitOR($WM_ERASEBKGND, $RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME))
    ElseIf _IsPressed("26", $dll) Then
        $CharTop -= $sv_speed
        GUICtrlSetPos($char, $CharLeft, $CharTop)
        _WinAPI_RedrawWindow(GUICtrlGetHandle($char), "", "", BitOR($WM_ERASEBKGND, $RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME))
    ElseIf _IsPressed("11", $dll) Then
        $MissileID = Summon("fireball", $CharLeft, $CharTop)
        ShootMissile($MissileID, $CharLeft, $CharTop, $w_fireball_missile_speed)
;~      Summon("darkimpball")
    EndIf
EndFunc   ;==>Input

Func Win()
    MsgBox(0, 0, "end")
    $CharLeft = $CharLeftDefault
    $CharTop = $CharTopDefault
    GUICtrlSetPos($char, $CharLeft, $CharTop)
EndFunc   ;==>Win

;$iColor - Colour to be made transparent. Hex colour format 0xRRGGBB. If Default used then top left pixel colour of image
; is used as the transparent colour.
Func ImageColorToTransparent($hImage2, $iStartPosX = 0, $iStartPosY = 0, $GuiSizeX = Default, $GuiSizeY = Default, $iColor = Default)
    Local $hBitmap1, $Reslt, $width, $height, $stride, $format, $Scan0, $v_Buffer, $v_Value, $iIW, $iIH
    $iIW = _GDIPlus_ImageGetWidth($hImage2)
    $iIH = _GDIPlus_ImageGetHeight($hImage2)
    If $GuiSizeX = Default Or $GuiSizeX > $iIW - $iStartPosX Then $GuiSizeX = $iIW - $iStartPosX
    If $GuiSizeY = Default Or $GuiSizeY > $iIH - $iStartPosY Then $GuiSizeY = $iIH - $iStartPosY
    $hBitmap1 = _GDIPlus_BitmapCloneArea($hImage2, $iStartPosX, $iStartPosY, $GuiSizeX, $GuiSizeY, $GDIP_PXF32ARGB)
    If $iColor = Default Then $iColor = GDIPlus_BitmapGetPixel($hBitmap1, 1, 1); Transparent color
    $Reslt = _GDIPlus_BitmapLockBits($hBitmap1, 0, 0, $GuiSizeX, $GuiSizeY, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32ARGB)
    ;Get the returned values of _GDIPlus_BitmapLockBits ()
    $width = DllStructGetData($Reslt, "width")
    $height = DllStructGetData($Reslt, "height")
    $stride = DllStructGetData($Reslt, "stride")
    $format = DllStructGetData($Reslt, "format")
    $Scan0 = DllStructGetData($Reslt, "Scan0")
    For $i = 0 To $GuiSizeX - 1
        For $j = 0 To $GuiSizeY - 1
            $v_Buffer = DllStructCreate("dword", $Scan0 + ($j * $stride) + ($i * 4))
            $v_Value = DllStructGetData($v_Buffer, 1)
            If Hex($v_Value, 6) = Hex($iColor, 6) Then
                DllStructSetData($v_Buffer, 1, Hex($iColor, 6)); Sets Transparency here. Alpha Channel = 00, not written to.
            EndIf
        Next
    Next
    _GDIPlus_BitmapUnlockBits($hBitmap1, $Reslt)
    Return $hBitmap1
EndFunc   ;==>ImageColorToTransparent

;The GetPixel method gets the color of a specified pixel in this bitmap.
Func GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)
    Local $tArgb, $pArgb, $aRet
    $tArgb = DllStructCreate("dword Argb")
    $pArgb = DllStructGetPtr($tArgb)
    $aRet = DllCall($ghGDIPDll, "int", "GdipBitmapGetPixel", "hwnd", $hBitmap, "int", $iX, "int", $iY, "ptr", $pArgb)
    Return "0x" & Hex(DllStructGetData($tArgb, "Argb"))
EndFunc   ;==>GDIPlus_BitmapGetPixel

Func timer()
    GUICtrlSetData($timer,GUICtrlRead($timer)-1)
EndFunc

edited

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...