[Abandoned Game] Just learning - Code and GFX free to do with as you please :)

Previous topic - Next topic

Amon

Press T to test the level. Select the S tile and place it on the map to set starting position for Wizz. Code has jumping, colliding with tiles etc and falling - the basic platform goodness. :) Rest of GFX in second post. :)

By the way, GLBasic is the bizniz :D

Code (glbasic) Select
// --------------------------------- //
// Project: WizMicro
// Start: Sunday, January 10, 2010
// IDE Version: 7.230


SETCURRENTDIR("Media") // seperate media and binaries?

SETSCREEN 800,600,0

LIMITFPS 60

GLOBAL WizFaceLeft = 0
GLOBAL WizFaceRight = 1
GLOBAL Plats = 2
GLOBAL ArrowCursor = 3
GLOBAL s_start_button = 4
GLOBAL embul = 5
GLOBAL embur = 6


SETTRANSPARENCY RGB(255,0,255)
LOADANIM "wizzmicrofl.png",WizFaceLeft,16,16
LOADANIM "wizzmicrofr.png",WizFaceRight,16,16
LOADANIM "plats.png",Plats,16,16
LOADSPRITE "arrow.png",ArrowCursor
LOADSPRITE "s.png",s_start_button

LOADANIM "embul.png",embul,16,16
LOADANIM "embur.png",embur,16,16

DIM maparray[50][31]
DIM maparray1[50][31]

GLOBAL WLeftA = 0  //wizz anim frame storage
GLOBAL WRightA = 0 //wizz anim frame storage
GLOBAL WizzDir = RND(1) // Wizz Start Direction - 0 = right 1 = left
GLOBAL wlocx = 400
GLOBAL wlocy = 400 // x + y location of wiz micro
GLOBAL jh = 11 //wizz jumpheight
GLOBAL gr = 1.0 // gravity
GLOBAL dojump = 0 // whether to jump
GLOBAL falling = 1 // whether falling
GLOBAL fallspeed = 4.4
GLOBAL canjump = 1

GLOBAL GameStart = 1 // 0 for title screen, 1 for game, 2 for mapeditor

GLOBAL Currenttile = 0
GLOBAL MouseX, MouseY,MB1,MB2
GLOBAL tilesize = 16
GLOBAL ti = 0 // tile increment for mapeditor
GLOBAL ti2 = 0 // increment for tile image

GLOBAL sx = 144 +16 // the s start button for where Wiz Starts - Xlocation
GLOBAL sy = 600 - 16 // y location of s start button
GLOBAL samount = 0 // only 1 s start position is allowed
GLOBAL canplaces = 1 // if can place an s (start Position)
GLOBAL TestLevel = 0 // Test the mapeditor current level

////////////// Map Editor Tiles to pick ///////////////

GLOBAL gKeys AS KEYCODES   // Copy/move to your main file!

TYPE TilesToPick
x
y
f
ENDTYPE

GLOBAL tplist[] AS TilesToPick
FOR xiter = 0 TO 9
GLOBAL t AS TilesToPick
t.x = ti
t.y = 600-16
ti = ti + 16
t.f = ti2
ti2 = ti2 + 1
DIMPUSH tplist[],t
NEXT

//FOR xiter2 = 0 TO 49
// FOR yiter2 = 0 TO 30
// maparray[xiter2][yiter2] = RND(9)
// NEXT
//NEXT


/////////////////////////////////////////////////////


WHILE KEY(01) = FALSE

KeyHitUpdate()

IF GameStart = 1
//mapeditor
MDrawPlats()
MPlacePlats()
SelectPlat()

IF KeyHit(20) = 2
TestLevel = 1
ENDIF

IF TestLevel = 1
BLACKSCREEN
FOR x = 0 TO 49
FOR y = 0 TO 30
maparray1[x][y] = maparray[x][y]
IF maparray[x][y] = 10
wlocx = GetX(x)
wlocy = GetY(y)
ENDIF
NEXT
NEXT

WHILE TestLevel = 1

FOR xiter3 = 0 TO 49
FOR yiter3 = 0 TO 30
IF maparray1[xiter3][yiter3] = 0 THEN DRAWANIM Plats, 0,xiter3 * tilesize, yiter3 * tilesize
IF maparray1[xiter3][yiter3] = 1 THEN DRAWANIM Plats, 1,xiter3 * tilesize, yiter3 * tilesize
IF maparray1[xiter3][yiter3] = 2 THEN DRAWANIM Plats, 2,xiter3 * tilesize, yiter3 * tilesize
IF maparray1[xiter3][yiter3] = 3 THEN DRAWANIM Plats, 3,xiter3 * tilesize, yiter3 * tilesize
IF maparray1[xiter3][yiter3] = 4 THEN DRAWANIM Plats, 4,xiter3 * tilesize, yiter3 * tilesize
IF maparray1[xiter3][yiter3] = 5 THEN DRAWANIM Plats, 5,xiter3 * tilesize, yiter3 * tilesize
IF maparray1[xiter3][yiter3] = 6 THEN DRAWANIM Plats, 6,xiter3 * tilesize, yiter3 * tilesize
IF maparray1[xiter3][yiter3] = 7 THEN DRAWANIM Plats, 7,xiter3 * tilesize, yiter3 * tilesize
IF maparray1[xiter3][yiter3] = 8 THEN DRAWANIM Plats, 8,xiter3 * tilesize, yiter3 * tilesize
IF maparray1[xiter3][yiter3] = 9 THEN DRAWANIM Plats, 9,xiter3 * tilesize, yiter3 * tilesize
NEXT
NEXT

DrawWiz()
MoveWiz()
PlatWizCollisions()

IF KeyHit(16)
TestLevel = 0
FOR x = 0 TO 49
FOR y = 0 TO 30
maparray1[x][y] = 0
NEXT
NEXT
ENDIF

SHOWSCREEN
WEND
ENDIF


ENDIF

SHOWSCREEN
WEND

FUNCTION DrawWiz:

IF WizzDir = 0
DRAWANIM WizFaceRight,WRightA,wlocx,wlocy
ELSEIF WizzDir = 1
DRAWANIM WizFaceLeft,WLeftA,wlocx,wlocy
ENDIF

ENDFUNCTION

FUNCTION MoveWiz:

IF KEY(203) = TRUE
WizzDir = 1
wlocx = wlocx - 5
WLeftA = WLeftA + 1
IF WLeftA >4 THEN WLeftA = 0
ELSEIF KEY(205) = TRUE
WizzDir = 0
wlocx = wlocx + 5
WRightA = WRightA + 1
IF WRightA >4 THEN WRightA = 0
ELSE
WRightA = 0
WLeftA = 0
ENDIF

ENDFUNCTION



FUNCTION PlatWizCollisions:

IF KEY(29) = TRUE AND canjump = 1
dojump = 1
ENDIF

IF dojump = 1
wlocy = wlocy - jh
jh = jh - gr
IF jh <= 0
jh = 0
falling = 1
ENDIF
ENDIF

IF wlocy >=16*30-5 THEN wlocy = 0
IF wlocx <=0 THEN wlocx = 0
IF wlocx >=800-16 THEN wlocx = 800-16

IF falling = 1
canjump = 0
wlocy = wlocy + fallspeed
IF maparray1[wlocx / 16][wlocy/ 16+1] >0 AND maparray1[wlocx / 16][wlocy / 16+1] <10
IF MOD(wlocy,16) <8.0
wlocy = wlocy - (MOD(wlocy,16))
falling = 0
jh = 11
dojump = 0
canjump = 1
ENDIF
ENDIF
ENDIF

IF WizzDir = 0
IF maparray1[(wlocx + 16)/ 16][wlocy/ 16+1] = 0 OR maparray1[(wlocx + 16)/ 16][wlocy / 16+1] =10
IF dojump = 0
falling = 1
ENDIF
ENDIF
ELSEIF WizzDir = 1
IF maparray1[(wlocx / 16) ][wlocy/ 16+1] = 0 OR maparray1[(wlocx / 16)][wlocy / 16+1] =10
IF dojump = 0
falling = 1
ENDIF
ENDIF
ENDIF

ENDFUNCTION


FUNCTION MDrawPlats:
FOREACH t IN tplist[]
DRAWANIM Plats, t.f,t.x,t.y
NEXT

FOR xiter3 = 0 TO 49
FOR yiter3 = 0 TO 30
IF maparray[xiter3][yiter3] = 0 THEN DRAWANIM Plats, 0,xiter3 * tilesize, yiter3 * tilesize
IF maparray[xiter3][yiter3] = 1 THEN DRAWANIM Plats, 1,xiter3 * tilesize, yiter3 * tilesize
IF maparray[xiter3][yiter3] = 2 THEN DRAWANIM Plats, 2,xiter3 * tilesize, yiter3 * tilesize
IF maparray[xiter3][yiter3] = 3 THEN DRAWANIM Plats, 3,xiter3 * tilesize, yiter3 * tilesize
IF maparray[xiter3][yiter3] = 4 THEN DRAWANIM Plats, 4,xiter3 * tilesize, yiter3 * tilesize
IF maparray[xiter3][yiter3] = 5 THEN DRAWANIM Plats, 5,xiter3 * tilesize, yiter3 * tilesize
IF maparray[xiter3][yiter3] = 6 THEN DRAWANIM Plats, 6,xiter3 * tilesize, yiter3 * tilesize
IF maparray[xiter3][yiter3] = 7 THEN DRAWANIM Plats, 7,xiter3 * tilesize, yiter3 * tilesize
IF maparray[xiter3][yiter3] = 8 THEN DRAWANIM Plats, 8,xiter3 * tilesize, yiter3 * tilesize
IF maparray[xiter3][yiter3] = 9 THEN DRAWANIM Plats, 9,xiter3 * tilesize, yiter3 * tilesize
IF maparray[xiter3][yiter3] = 10
DRAWSPRITE s_start_button,xiter3 * tilesize, yiter3 * tilesize
ENDIF
NEXT
NEXT

DRAWSPRITE s_start_button,sx,sy

DRAWANIM Plats, currenttile,800-16,600-16
IF currenttile = 10
DRAWSPRITE s_start_button,800-16,600-16
ENDIF

ENDFUNCTION

// ------------------------------------------------------------- //
// ---  MPLACEPLATS  ---
// ------------------------------------------------------------- //
FUNCTION MPlacePlats:


MOUSESTATE MouseX, MouseY, MB1, MB2


IF MouseX <=800 AND MouseX >=0
IF MouseY < 31*16 AND MouseY >=0
IF MB1 = TRUE AND currenttile <>10
maparray[MouseX/tilesize][MouseY/tilesize] = currenttile
ENDIF
IF MB1 = TRUE AND currenttile = 10
IF canplaces = 1
maparray[MouseX/tilesize][MouseY/tilesize] = 10
canplaces = 0
ENDIF
ENDIF
ENDIF
ENDIF

IF MouseX <=800 AND MouseX >=0
IF MouseY < 31*16 AND MouseY >=0
IF MB1 = TRUE AND canplaces = 0 AND currenttile <> 10
canplaces = 1
ENDIF
ENDIF
ENDIF

DRAWSPRITE ArrowCursor, MouseX, MouseY

PRINT canplaces, 10,500
//PRINT samount,10,520
IF MouseX <=800 AND MouseX >=0
IF MouseY < 31*16 AND MouseY >=0
PRINT maparray[MouseX/tilesize][MouseY/tilesize],10,527
ENDIF
ENDIF

ENDFUNCTION // MPLACEPLATS



// ------------------------------------------------------------- //
// ---  SELECTPLAT  ---
// ------------------------------------------------------------- //
FUNCTION SelectPlat:

FOREACH t IN tplist[]
IF MB1 = TRUE
IF MouseX - t.x >0 AND MouseX - t.x < 16
IF MouseY - t.y >0 AND MouseY - t.y < 16
currenttile = t.f
ENDIF
ENDIF
ENDIF
NEXT

IF MB1 = TRUE
IF MouseX - sx >0 AND MouseX - sx <16
IF MouseY - sy > 0 AND MouseY - sy <16
currenttile = 10
ENDIF
ENDIF
ENDIF


ENDFUNCTION // SELECTPLAT

FUNCTION GetX: x
RETURN x * 16
ENDFUNCTION

FUNCTION GetY: y
RETURN y * 16
ENDFUNCTION




[attachment deleted by admin]
- http://www.amon.co | Dev Tools - BlitzMax - Shiva Unlimited - Unity Pro - Carrara 8 Pro - Hexagon 2.2.5 - Blacksmith 3D Paint - FuturePaint Pro - Bryce 7 Pro.
I'm never wrong at all; I just discover 1000 ways that don't work!

Amon

Here are the rest of the gfx. put them in the standard media folder. :)

[attachment deleted by admin]
- http://www.amon.co | Dev Tools - BlitzMax - Shiva Unlimited - Unity Pro - Carrara 8 Pro - Hexagon 2.2.5 - Blacksmith 3D Paint - FuturePaint Pro - Bryce 7 Pro.
I'm never wrong at all; I just discover 1000 ways that don't work!

Ian Price

The  "KeyHit" and "KeyHitUpdate" functions are missing, so this doesn't work. There is also no KeyCodes Type :(

I am aware that a keyhit function was provided by Moru for you recently - did you use this lock stock and barrel?

Can you update your code to include this please :)
I came. I saw. I played.

Amon

Quote from: Ian Price on 2010-Jan-11
The  "KeyHit" and "KeyHitUpdate" functions are missing, so this doesn't work. There is also no KeyCodes Type :(

I am aware that a keyhit function was provided by Moru for you recently - did you use this lock stock and barrel?

Can you update your code to include this please :)

Arghhh! Totally forgot about that. Here is the code. :) Save as keyhitc.gbas :)

Code (glbasic) Select
// --------------------------------- //
// Project: WizMicro
// Start: Monday, January 11, 2010
// IDE Version: 7.230


// SETCURRENTDIR("Media") // seperate media and binaries?

/////////////KEYCODE INCLUDE///////////////////////////

// --------------------------------- //
// Project: KeyHit
// Start: Saturday, September 22, 2007
// IDE Version: 5.022


// Example:
//GLOBAL gKeys AS KEYCODES
//
//WHILE TRUE
//    KeyHitUpdate()
//
//    PRINT "SpaceBar-State:" + KeyHit(57), 100,100
//    IF KeyHit(57)=2
//        INC tips, 1
//        PRINT "*BING*", 100, 120
//    ENDIF
//    IF KeyHit(57)=-1
//        PRINT "*BONG*", 100, 120
//    ENDIF
//
//    IF KEY(gKeys.space) THEN PRINT "Space", 100, 100
//
//    PRINT "Tipps"+tips, 100, 140
//
//    HIBERNATE
//    SHOWSCREEN
//WEND

//
TYPE KEYCODES
   vk_escape          = 0x01
   vk_1               = 0x02
   vk_2               = 0x03
   vk_3               = 0x04
   vk_4               = 0x05
   vk_5               = 0x06
   vk_6               = 0x07
   vk_7               = 0x08
   vk_8               = 0x09
   vk_9               = 0x0A
   vk_0               = 0x0B
   vk_minus           = 0x0C    // - on main keyboard
   vk_equals          = 0x0D
   vk_back            = 0x0E    // backspace
   vk_tab             = 0x0F
   vk_q               = 0x10
   vk_w               = 0x11
   vk_e               = 0x12
   vk_r               = 0x13
   vk_t               = 0x14
   vk_y               = 0x15
   vk_u               = 0x16
   vk_i               = 0x17
   vk_o               = 0x18
   vk_p               = 0x19
   vk_lbracket        = 0x1A
   vk_rbracket        = 0x1B
   vk_return          = 0x1C    // Enter on main keyboard
   vk_lcontrol        = 0x1D
   vk_a               = 0x1E
   vk_s               = 0x1F
   vk_d               = 0x20
   vk_f               = 0x21
   vk_g               = 0x22
   vk_h               = 0x23
   vk_j               = 0x24
   vk_k               = 0x25
   vk_l               = 0x26
   vk_semicolon       = 0x27
   vk_apostrophe      = 0x28
   vk_grave           = 0x29    // accent grave
   vk_lshift          = 0x2A
   vk_backslash       = 0x2B
   vk_z               = 0x2C
   vk_x               = 0x2D
   vk_c               = 0x2E
   vk_v               = 0x2F
   vk_b               = 0x30
   vk_n               = 0x31
   vk_m               = 0x32
   vk_comma           = 0x33
   vk_period          = 0x34    // . on main keyboard
   vk_slash           = 0x35    // / on main keyboard
   vk_rshift          = 0x36
   vk_multiply        = 0x37    // * on numeric keypad
   vk_lmenu           = 0x38    // left Alt
   vk_space           = 0x39
   vk_capital         = 0x3A
   vk_f1              = 0x3B
   vk_f2              = 0x3C
   vk_f3              = 0x3D
   vk_f4              = 0x3E
   vk_f5              = 0x3F
   vk_f6              = 0x40
   vk_f7              = 0x41
   vk_f8              = 0x42
   vk_f9              = 0x43
   vk_f10             = 0x44
   vk_numlock         = 0x45
   vk_scroll          = 0x46    // Scroll Lock
   vk_numpad7         = 0x47
   vk_numpad8         = 0x48
   vk_numpad9         = 0x49
   vk_subtract        = 0x4A    // - on numeric keypad
   vk_numpad4         = 0x4B
   vk_numpad5         = 0x4C
   vk_numpad6         = 0x4D
   vk_add             = 0x4E    // + on numeric keypad
   vk_numpad1         = 0x4F
   vk_numpad2         = 0x50
   vk_numpad3         = 0x51
   vk_numpad0         = 0x52
   vk_decimal         = 0x53    // . on numeric keypad
   vk_oem_102         = 0x56    // < > | on UK/Germany keyboards
   vk_f11             = 0x57
   vk_f12             = 0x58
   vk_f13             = 0x64    //                     (NEC PC98)
   vk_f14             = 0x65    //                     (NEC PC98)
   vk_f15             = 0x66    //                     (NEC PC98)
   vk_kana            = 0x70    // (Japanese keyboard)
   vk_abnt_c1         = 0x73    // / ? on Portugese (Brazilian) keyboards
   vk_convert         = 0x79    // (Japanese keyboard)
   vk_noconvert       = 0x7B    // (Japanese keyboard)
   vk_yen             = 0x7D    // (Japanese keyboard)
   vk_abnt_c2         = 0x7E    // Numpad . on Portugese (Brazilian) keyboards
   vk_numpadequals    = 0x8D    // = on numeric keypad (NEC PC98)
   vk_prevtrack       = 0x90    // Previous Track (vk_CIRCUMFLEX on Japanese keyboard)
   vk_at              = 0x91    //                     (NEC PC98)
   vk_colon           = 0x92    //                     (NEC PC98)
   vk_underline       = 0x93    //                     (NEC PC98)
   vk_kanji           = 0x94    // (Japanese keyboard)
   vk_stop            = 0x95    //                     (NEC PC98)
   vk_ax              = 0x96    //                     (Japan AX)
   vk_unlabeled       = 0x97    //                        (J3100)
   vk_nexttrack       = 0x99    // Next Track
   vk_numpadenter     = 0x9C    // Enter on numeric keypad
   vk_rcontrol        = 0x9D
   vk_mute            = 0xA0    // Mute
   vk_calculator      = 0xA1    // Calculator
   vk_playpause       = 0xA2    // Play / Pause
   vk_mediastop       = 0xA4    // Media Stop
   vk_volumedown      = 0xAE    // Volume -
   vk_volumeup        = 0xB0    // Volume +
   vk_webhome         = 0xB2    // Web home
   vk_numpadcomma     = 0xB3    // , on numeric keypad (NEC PC98)
   vk_divide          = 0xB5    // / on numeric keypad
   vk_sysrq           = 0xB7
   vk_rmenu           = 0xB8    // right Alt
   vk_pause           = 0xC5    // Pause
   vk_home            = 0xC7    // Home on arrow keypad
   vk_up              = 0xC8    // UpArrow on arrow keypad
   vk_prior           = 0xC9    // PgUp on arrow keypad
   vk_left            = 0xCB    // LeftArrow on arrow keypad
   vk_right           = 0xCD    // RightArrow on arrow keypad
   vk_end             = 0xCF    // End on arrow keypad
   vk_down            = 0xD0    // DownArrow on arrow keypad
   vk_next            = 0xD1    // PgDn on arrow keypad
   vk_insert          = 0xD2    // Insert on arrow keypad
   vk_delete          = 0xD3    // Delete on arrow keypad
   vk_lwin            = 0xDB    // Left Windows key
   vk_rwin            = 0xDC    // Right Windows key
   vk_apps            = 0xDD    // AppMenu key
   vk_power           = 0xDE    // System Power
   vk_sleep           = 0xDF    // System Sleep
   vk_wake            = 0xE3    // System Wake
   vk_websearch       = 0xE5    // Web Search
   vk_webfavorites    = 0xE6    // Web Favorites
   vk_webrefresh      = 0xE7    // Web Refresh
   vk_webstop         = 0xE8    // Web Stop
   vk_webforward      = 0xE9    // Web Forward
   vk_webback         = 0xEA    // Web Back
   vk_mycomputer      = 0xEB    // My Computer
   vk_mail            = 0xEC    // Mail
   vk_mediaselect     = 0xED    // Media Select
ENDTYPE

//
// Update keyboard state
FUNCTION KeyHitUpdate:
GLOBAL gKeyDown[], gKeyState[]
LOCAL  k, i
    // First Time call
    IF BOUNDS(gKeyDown[],0)=0
        DIM gKeyDown[256]
        DIM gKeyState[256]
    ENDIF

    // For each key
    FOR i=0 TO 255
        k = KEY(i)
        // Key is pressed
        IF k
            IF gKeyDown[i]
                gKeyState[i]=1
            ELSE
                gKeyDown[i]=1
                gKeyState[i]=2
            ENDIF
        ELSE
            // Key is not pressed

            // Has key been pressed before?
            IF gKeyDown[i]
                gKeyDown[i] = 0
                gKeyState[i] = -1
            ELSE
                gKeyState[i]=0
            ENDIF
        ENDIF
    NEXT
ENDFUNCTION

//  0 = not pressed
//  2 = just pressed
//  1 = pressed
// -1 = release event
FUNCTION KeyHit: nkey
    RETURN gKeyState[nkey]
ENDFUNCTION

///////////END KEYCODE FUNCTION//////////////////////////////////////////
- http://www.amon.co | Dev Tools - BlitzMax - Shiva Unlimited - Unity Pro - Carrara 8 Pro - Hexagon 2.2.5 - Blacksmith 3D Paint - FuturePaint Pro - Bryce 7 Pro.
I'm never wrong at all; I just discover 1000 ways that don't work!

Ian Price

It's a nice start. Could help beginners to grasp basic concepts. :)
I came. I saw. I played.