Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - Lord_TNK

#1
I really tried tweaking this one, but I need your help. I was trying to figure out a way to make the player's sprite move less as you held down the keys. Specifically it was to try to make the sprite move only a certain amount when you held down a key, but stop until you released it and pressed it again, instead of doing it continuously as you held down the key (this would be for stuff like moving a character like on a grid, the way some old school CRPGs did).

I couldn't find a way to make it work. This is the code so far, that didn't accidentally stop the sprite from moving at all, or in two directions only (at least I figured out that THEN limits results from an IF statement to one, so I need ENDIF for more).

Code (glbasic) Select
SETCURRENTDIR("Media") // go to media files

SETTRANSPARENCY RGB (244, 124, 0)

LIMITFPS 60

LOADSPRITE "whatever.bmp", 5 //any picture will do; the code here works with a 32x32 one
GLOBAL shield% = 5

GLOBAL spritex = 128
GLOBAL spritey = 128
GLOBAL spritespeed = 1
GLOBAL KeyHit = 0

WHILE KEY (01) = FALSE

MovePlayer()
DrawScreen()

WEND

FUNCTION MovePlayer:

LOCAL dirx, diry

IF KeyHit = 0
IF KEY (17)
diry = -1
KeyHit = 1
ENDIF
ELSE
diry = 0
KeyHit = 0
ENDIF

IF KeyHit = 0
IF KEY (30)
dirx = -1
KeyHit = 1
ENDIF
ELSE
dirx = 0
KeyHit = 0
ENDIF

IF KeyHit = 0
IF KEY (31)
diry = 1
KeyHit = 1
ENDIF
ELSE
diry = 0
KeyHit = 0
ENDIF

IF KeyHit = 0
IF KEY (32)
dirx = 1
KeyHit = 1
ENDIF
ELSE
dirx = 0
KeyHit = 0
ENDIF

spritex = spritex + (spritespeed * dirx)
spritey = spritey + (spritespeed * diry)

IF KEY (57) THEN spritespeed=3
IF NOT KEY (57) THEN spritespeed=1

IF spritex < 0 THEN spritex = 0
IF spritex > 608 THEN spritex = 608
IF spritey < 0 THEN spritey = 0
IF spritey > 448 THEN spritey = 448

ENDFUNCTION

FUNCTION DrawScreen:

DRAWSPRITE shield, spritex, spritey

SHOWSCREEN

ENDFUNCTION
#2
I find I prefer to use the WASD setup for moving around in games*, but I'd like to actually type "W", "A", "S", and "D" on the function code instead of "30", "31", and "32", and... I keep forgetting what the code for "W" is.

Yeah, there is a way to look up the codes in the GLBasic SDK, which is convenient, but it would be even more convenient not to have to use those numbers (preferably not even set up pointers for them).

* Well I prefer gamepads even more, but I have to first learn how to set up ways for the player to map controls in the options.

EDIT: I have a program to help with listed on this post.
#3
Not sure if there is a different term for this (as C language uses "pointer" for giving alternate names to variables), but does GLBasic allow assigning an alternate name for images loaded? So far, I have to use number strings for every sprite and animation loaded, and that could get very confusing fast. I'd prefer a code to be able to use something like "DRAWSPRITE yellow_rat, ..." rather than "DRAWSPRITE 374, ...".
#4
I'm running the very basic background and sprite programs provided on the tutorials for both this site's main page and the GKBasic SDK (version 10.202), and I'm just getting a blank screen. I've tried using the SETCURRENTDIR command. I've put the image names with and without the "media/" link. I tried running the exe on a different computer (both running on Windows XP SP3).

These are some of the codes I've tried:

//
SETCURRENTDIR("Media") // go to media files
// My game
start:
  LOADBMP "Background.bmp"
  // Load further graphics as sprites...
  // load level, setup (lives=3, time=100...)
maingame:
  //Keyboard input
  //Move and draw player
  //Move and draw enemies
  SHOWSCREEN
GOTO maingame
//

//
SETCURRENTDIR("Media") // go to media files
////////////////
// SPRITES
////////////////
// load sprite image from file "Bubble.bmp" and assign it to ID 0
LOADSPRITE "Bubble.bmp" ,0
// show sprite image with ID 0 at position x=300, y=150
DRAWSPRITE 0, 300, 150
SHOWSCREEN
END
//

//
SETCURRENTDIR("Media") // go to media files
LOADBMP "sky.png"
LOADSPRITE "box.png", 4
DRAWSPRITE 4, 300, 150
SHOWSCREEN
MOUSEWAIT
END
//

Neither shows anything but a black screen.