Jump to content

I am trying to create my own mario game but cant add ground


E1M1
 Share

Recommended Posts

Hi I tried to create my own mario game,I created sky but if I try create ground, AutoIt just won't draw it, It draws only sky(actually It draws grounds but since it's behind the sky, you just cant see it).How I can make script that paints sky as background picture and all other things on it so that all other level objects would be in front of sky?

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Mario", 640, 480)
GUISetBkColor(0x000000)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Level()
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func Level()
    $LevelWidth = 640
    AddSky($LevelWidth)
    AddGround(0,420,320,60)
EndFunc

Func AddSky($LevelWidth)
    GUICtrlCreatePic("sky.bmp",0,0,$LevelWidth,480)
EndFunc

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

edited

Link to comment
Share on other sites

I developed it a bit but when I press right arrow to move my char my char disapears.

Images are posted as attatchments.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
Dim $char
$CharLeft = 10
$CharTop = 371
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Mario", 640, 480)
GUISetBkColor(0x000000)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$dll = DllOpen("user32.dll")
Level()
While GUIGetMsg() <> -3
    Sleep ( 25 )
    If _IsPressed("27", $dll) Then
        $CharLeft += 1
        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

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

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

Func AddChar($left,$top,$width,$height)
    $char = GUICtrlCreatePic("char.bmp",$left,$top,$width,$height,$GUI_ONTOP)
EndFunc

mario.zip

edited

Link to comment
Share on other sites

Ok but now it ower writes ground if I move on ground :S

but now the question is: Can I shoot and move at same time? At the moment my everything else freezes until missile ends.

and how to summon other missile while another is flying?

I wanna use something like this

Summon();Cast 1st missile

sleep();wait to cast 2nd missile, but keep 1st missile flying at same time

summon();keep 1st missile flying and cast 2nd one at same time.

;2 missiles fly together

;and character is walking.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#Include <WinAPI.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)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$dll = DllOpen("user32.dll")
Level()
While GUIGetMsg() <> -3
    Sleep(25)
    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("doomimpball", $CharLeft, $CharTop)
        ShootMissile($MissileID, $CharLeft, $CharTop, $w_fireball_missile_speed)
;~      Summon("darkimpball")
    EndIf
    If $CharTop > 430 Then
        GameOver()
    EndIf
    $pos = WinGetPos($Form1)
    If PixelGetColor($pos[0] + $CharLeft, $pos[1] + $CharTop + 50 + $titleBarHeitht, $Form1) = 0x99D9EA 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)
EndFunc   ;==>AddChar

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

Func Summon($sText, $iX, $iY)
    Return GUICtrlCreatePic("char.bmp", $iX, $iY, 26, 49)
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
Edited by E1M1

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...