Creating a Tetris-style game.

Announce and discuss the progress of your various programming-related projects...programs, games, websites, tutorials, libraries...anything!

Moderators: Pete, Mods

Post Reply
pete5990
Newbie
Posts: 3
Joined: Wed Oct 25, 2006 2:07 pm

Creating a Tetris-style game.

Post 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.
bungytheworm
Veteran
Posts: 288
Joined: Sat Feb 18, 2006 4:02 pm

Post 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?
MystikShadows
Veteran
Posts: 703
Joined: Sun Nov 14, 2004 7:36 am
Contact:

Post by MystikShadows »

that would be CASE UCASE("w")
When God created light, so too was born, the first Shadow!

MystikShadows

Need hosting? http://www.jc-hosting.net

Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
pete5990
Newbie
Posts: 3
Joined: Wed Oct 25, 2006 2:07 pm

Post 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.
bungytheworm
Veteran
Posts: 288
Joined: Sat Feb 18, 2006 4:02 pm

Post 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.
pete5990
Newbie
Posts: 3
Joined: Wed Oct 25, 2006 2:07 pm

Post 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]
Post Reply