Page 1 of 1

Creating a Tetris-style game.

Posted: Wed Oct 25, 2006 2:09 pm
by pete5990
Same shapes and everything. I have some basic stuff done so far.

I'm looking for suggestions on tutorials. I'm pretty new to writing programs that require user-input (as in pressing left or right, not talking about inputting variables). I've done some decent animations as well.

For example, this is the best that I've been able to figure out on my own.

Code: Select all

CLS
SCREEN 12
LET x = 320
LET y = 240
PSET (x, y), 15
DO UNTIL INKEY$ = CHR$(27)
  DO WHILE INKEY$ = "a"
    PSET (x, y), 0
    LET x = x - 15
    PSET (x, y), 15
  LOOP
  DO WHILE INKEY$ = "s"
    PSET (x, y), 0
    LET y = y + 15
    PSET (x, y), 15
  LOOP
  DO WHILE INKEY$ = "d"
    PSET (x, y), 0
    LET x = x + 15
    PSET (x, y), 15
  LOOP
  DO WHILE INKEY$ = "w"
    PSET (x, y), 0
    LET y = y - 15
    PSET (x, y), 15
  LOOP
LOOP
It's slow, jerky, and a pain in the ass.

Posted: Wed Oct 25, 2006 3:11 pm
by bungytheworm
It is a start. Dont underestimate yourself :wink:

Code: Select all

CLS
SCREEN 12
x = 320 : y = 240
PSET (x, y), 15

DO UNTIL INKEY$ = CHR$(27) 
     Press$ = INKEY$

     SELECT CASE Press$

         CASE "w"
         ' do stuff
 
        CASE "a"
        ' do stuff

' after directions handled with CASE (END CASE declared) add Press$ = ""
LOOP
END
I think it could work better. Correct me if im wrong. Too lazy to hope my dosbox would work this time.
Only one loop, and it's fast enough if user keeps "w" or some other used button down. Press$ = "" clears pressing.

Does
CASE UBOUND("w")
work in QB btw? Anyone?

Posted: Wed Oct 25, 2006 3:13 pm
by MystikShadows
that would be CASE UCASE("w")

Posted: Thu Oct 26, 2006 5:15 pm
by pete5990
That is better, but if you tap any of the wasd keys to make a small change, it usually fails to register that they're hitting a key about 2 out of 3 times.

Posted: Thu Oct 26, 2006 5:52 pm
by bungytheworm
pete5990 wrote:That is better, but if you tap any of the wasd keys to make a small change, it usually fails to register that they're hitting a key about 2 out of 3 times.
Ah, that might be true.
But then you could try something like this.

Code: Select all

DO UNTIL INKEY$ = CHR$(27)
     Press$ = INKEY$

     SELECT CASE Press$

         CASE UCASE("w") ' this way W and w are same. 
         ' do stuff
         Press$ = ""

        CASE UCASE("a")
        ' do stuff 
        Press$ = ""
Your original code is workable so there is not any "must to" things to change it. Just presented alternative way. IMO: is nicer, but thats opinion matter.

Posted: Tue Oct 31, 2006 3:40 pm
by pete5990
Got it.

Code: Select all

CLS
SCREEN 12
LET x = 15
LET y = 15
DO UNTIL x > 41 OR y > 30
  PSET (15 * x, 15 * y), 15
  LET p$ = INKEY$
  IF p$ = "a" THEN LET x2 = x: x = x - 1
  IF p$ = "d" THEN LET x2 = x: x = x + 1
  IF p$ = "s" THEN LET y2 = y: y = y + 1
  IF p$ = "w" THEN LET y2 = y: y = y - 1
LOOP
For whatever reason, it picks up every keystroke.[/quote]