Weekly Qbasic and Qb64 Lesson Topics
March 29, 2024, 02:08:18 am
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Want to see a specific Tutorial? ASK!
 
  Home Help Search Arcade Links Staff List Login Register  

Duke Nukem Game Rewrite.

Pages: [1] 2 3
  Print  
Author Topic: Duke Nukem Game Rewrite.  (Read 2116 times)
Unseen Machine
Post Demos
*
Posts: 46


« on: May 31, 2011, 03:28:54 pm »

Ok cool.

I need you to finish the keyboard input and merge that with the code we have allready. What do you need from me?

Here's what i have done so far, just loading the tile loacations into an array. It accounts for the lump on the bottom right of the tilesheet and ignores it. That was a little head scratcher in it's self.

Put this in your DukeNukem folder...http://dl.dropbox.com/u/8822351/TileSheet.png

Code:
'// Animated Duke Nukem

'// Set up a screen for animation

SCREEN _NEWIMAGE(800, 600, 32)

CHDIR "dukenukem\" '// Maybe we should all make this folder?

'// The Rect TYPE has two main uses, the first is for sprite animation, the second for bounding
'// RECT collision detection but it alos used for tilesheets! Useful Eh?

TYPE Rect
    X AS INTEGER
    Y AS INTEGER
    Width AS INTEGER
    Height AS INTEGER
END TYPE

'// The Sprite TYPE contains variables common to all sprites

TYPE Sprite
    X AS INTEGER
    Y AS INTEGER
    AnimFrame AS INTEGER
    AnimTime AS DOUBLE
    IsMoving AS INTEGER
    Direction AS INTEGER
    Exists AS INTEGER
END TYPE


DIM DukeImage AS LONG '// Duke character sprite

'// TO BE RE_CODED TO FIT NEW ANIMATION!!!
DIM SHARED DukeFrame(1 TO 10) AS Rect '// Hold animation frame co-ordinates
DIM Duke AS Sprite, DukeRect AS Rect

DukeImage = _LOADIMAGE("Duke.png", 32) '// Load the image
_CLEARCOLOR _RGB32(255, 0, 255), DukeImage '// Set pink as the transparent colour

'// Load the animation RECTs into memory.
'// The duke image has 10 frames, equally spaced on a single line, so this is easy.
FrameCount% = 1
FOR X% = 0 TO _WIDTH(DukeImage) - (_WIDTH(DukeImage) / 10) STEP (_WIDTH(DukeImage) / 10)
    DukeFrame(FrameCount%).X = X%
    DukeFrame(FrameCount%).Height = _HEIGHT(DukeImage)
    DukeFrame(FrameCount%).Width = _WIDTH(DukeImage) / 10
    FrameCount% = FrameCount% + 1
NEXT
'// END OF NEEDED RE_CODE

'// TileSheet loading, sheet has 30 columns 15 rows = 450 tiles (but some are empty)
'// After tile 300, tiles are only 20 columns wide - this acounts for that.
TileSheet& = _LOADIMAGE("Tilesheet.png")
DIM Tile(1 TO 400) AS Rect
X% = 0
Y% = 0
XStep% = _WIDTH(TileSheet&) / 30
YStep% = _HEIGHT(TileSheet&) / 15
FOR i% = 1 TO 400
    Tile(i%).X = X%
    Tile(i%).Y = Y%
    Tile(i%).Width = XStep%
    Tile(i%).Height = YStep%
    X% = X% + XStep%
    IF i% > 300 THEN
        IF X% >= _WIDTH(TileSheet&) - (XStep% * 11) THEN
            X% = 0
            Y% = Y% + YStep%
        END IF
    ELSE
        IF X% >= _WIDTH(TileSheet&) - XStep% THEN
            X% = 0
            Y% = Y% + YStep%
        END IF
    END IF
    '// DEBUG CODE _ REMOVE FROM FINAL
    _PUTIMAGE (X%, Y%)-(X% + XStep%, Y% + YStep%), TileSheet&, , (X%, Y%)-(X% + XStep%, Y% + YStep%)
NEXT
_DISPLAY
SLEEP


'// Duke Initial Position Animation and direction Variables
Duke.X = 0
Duke.Y = 500
Duke.AnimFrame = 1 '// Current Animation Frame
Duke.Direction = 1 '// 1 = Right, 2 = left
Duke.IsMoving% = 0
Duke.AnimTime = .07 '// Time between animation frames
DukeRect.Height = _HEIGHT(DukeImage)
DukeRect.Width = _WIDTH(DukeImage) / 10

DukeAnimTimer# = TIMER(.001) '// Animation timer

DO
    _LIMIT 30
    CLS

    '// Duke Collision RECT
    DukeRect.X = DukeX%
    DukeRect.Y = DukeY%

    '// Duke Movement, Collisions and animation control...
    IF Duke.Direction = 1 THEN
        IF Duke.AnimFrame >= 5 THEN
            Duke.AnimFrame = 1
            Duke.IsMoving = 0 '// RESET Movement
        ELSE
            IF Duke.IsMoving THEN
                IF TIMER(.001) - DukeAnimTimer# >= Duke.AnimTime# THEN
                    IF Duke.AnimFrame < 5 THEN Duke.AnimFrame = Duke.AnimFrame + 1 ELSE Duke.AnimFrame = 1
                    DukeAnimTimer# = TIMER(.001) '// Animation timer
                    '// Move DUKE - check for collisions first though!!!
                    IF Duke.X + DukeRect.Width < 800 THEN Duke.X = Duke.X + 3
                END IF
            END IF
        END IF
    ELSEIF Duke.Direction = 2 THEN
        IF Duke.AnimFrame < 5 OR Duke.AnimFrame = 10 THEN
            Duke.AnimFrame = 6
            Duke.IsMoving = 0 '// RESET Movement
        ELSE
            IF Duke.IsMoving THEN
                IF TIMER(.001) - DukeAnimTimer# >= Duke.AnimTime THEN
                    IF Duke.AnimFrame < 10 THEN Duke.AnimFrame = Duke.AnimFrame + 1 ELSE Duke.AnimFrame = 6
                    DukeAnimTimer# = TIMER(.001) '// Animation timer
                    '// Move DUKE - check for collisions first though!!!
                    IF Duke.X > 0 THEN Duke.X = Duke.X - 3
                END IF
            END IF
        END IF
    END IF


    '// Input - Keyboard

    KB$ = INKEY$

    SELECT CASE KB$
        CASE CHR$(0) + CHR$(75) '// LEFT ARROW
            IF Duke.IsMoving THEN
                '// Increase speed??? Do nothing???
            ELSE
                Duke.IsMoving = -1
                Duke.Direction = 2
                Duke.AnimFrame = 6
            END IF
        CASE CHR$(0) + CHR$(77) '// RIGHT ARROW
            IF Duke.IsMoving THEN
                '// Increase speed??? Do nothing???
            ELSE
                Duke.IsMoving = -1
                Duke.Direction = 1
                Duke.AnimFrame = 1
            END IF

    END SELECT

    '// Drawing Duke
    _PUTIMAGE (Duke.X, Duke.Y)-(Duke.X + DukeRect.Width, Duke.Y + DukeRect.Height), DukeImage, , (DukeFrame(Duke.AnimFrame).X, 0)-(DukeFrame(Duke.AnimFrame).X + DukeFrame(Duke.AnimFrame).Width, _HEIGHT(DukeImage))

    _DISPLAY
LOOP


'// Determines if any part of two rectangles intersect. returns -1 for true, 0 for false
FUNCTION RECT_Intersect (RECTRef1 AS Rect, RECTRef2 AS Rect)
IF RECTRef1.X <= RECTRef2.X + RECTRef2.Width THEN
    IF RECTRef1.X + RECTRef1.Width >= RECTRef2.X THEN
        IF RECTRef1.Y <= RECTRef2.Y + RECTRef2.Height THEN
            IF RECTRef1.Y + RECTRef1.Height >= RECTRef2.Y THEN
                RECT_Intersect = -1
            END IF
        END IF
    END IF
ELSE
    RECT_Intersect = 0
END IF
END FUNCTION

It pauses the code after drawing the tiles (i only got it to draw them for debugging), but i just want you to look over the method to see if you have a better way.

John

Report Spam   Logged

Pages: [1] 2 3
  Print  
 
Jump to:  

Powered by EzPortal
Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum


Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy