Recent

Author Topic: [SOLVED] increase of a variable by holding a key  (Read 5552 times)

DiCri

  • Full Member
  • ***
  • Posts: 151
  • My goal : Build a game
    • http://manueldicriscito.altervista.org/DinoLand.zip
[SOLVED] increase of a variable by holding a key
« on: July 19, 2016, 08:32:26 pm »
hi guys, now i'd like to know another thing.. Please note this code:
Code: Pascal  [Select][+][-]
  1. uses crt;
  2. var n:integer;
  3. begin
  4. clrscr;
  5. repeat
  6. if keypressed then n:=n+1;
  7. writeln(n);
  8. until n=100;
  9. end.
  10.  
as you can see in this program you should press any key for increase the integer N. but when i press (e.g. "K") the number N increases with some delays between. How to remove this delays? with delays the number N took much time to reach number 100. without delays, program will end as soon as i press a key because N reaches 100. But as i know and as my teacher told me, this isn't possible. The thing i want is not to remove all delays and reach high numbers on 1 millisecond: but to change this predefined delays. If you don't understand what i mean, then i don't know what to say, i am not english so maybe i'm wrong at something. Reply me please
« Last Edit: July 22, 2016, 03:49:26 pm by Manu12x »
I'm a game developer.. Now studying..
Go download my game:
http://manueldicriscito.altervista.org/DinoLand.zip

lainz

  • Hero Member
  • *****
  • Posts: 4468
    • https://lainz.github.io/
you should store the key somewhere, you need keydown and keyup
https://github.com/bgrabitmap/bgragames/blob/master/test/leveloid/leveloid/umain.pas#L135
https://github.com/bgrabitmap/bgragames/blob/master/test/leveloid/leveloid/umain.pas#L140

OnKeyDown
Keys.Values[IntToStr(Key)] := 'True';

OnKeyUp
Keys.Values[IntToStr(Key)] := 'False';

and use as is

repeat
if Keys.Values[IntToStr(VK_K)] = 'True' then n:=n+1
...

Edit: I don't thing repeat is usefull, you need in fact a Timer.
« Last Edit: July 19, 2016, 09:06:59 pm by lainz »

Handoko

  • Hero Member
  • *****
  • Posts: 5151
  • My goal: build my own game engine using Lazarus
Edit: I don't thing repeat is usefull, you need in fact a Timer.

He tried to use repeat as game main loop.

Hello Manuel Di Criscito. Other than trapping keys, you now should learn what is game main loop. Try to google for more information.

DiCri

  • Full Member
  • ***
  • Posts: 151
  • My goal : Build a game
    • http://manueldicriscito.altervista.org/DinoLand.zip
do you know the game Geometry Dash? if you don't know go searching on google, search "wave mode Geometry Dash" and there is a mode in this game in which "while" i keep holding a key, the charachter goes up, if i don't press anything, the player goes down. I mean this function. because with readkey, and "if keypressed" there are some hiding delays... I am Manuel Di Criscito, i only changed my name
I'm a game developer.. Now studying..
Go download my game:
http://manueldicriscito.altervista.org/DinoLand.zip

Handoko

  • Hero Member
  • *****
  • Posts: 5151
  • My goal: build my own game engine using Lazarus
Although I don't play Geometry Dash, but I know what you mean. In the old DOS days, I wrote many simple games using CRT unit and direct screen memory mapping (I don't use Graph). To make keyboard trapping easier to use in my games, I even wrote my own keyboard module.

But that was many years ago. Now I use Linux, unit CRT can't run my Linux 64-bit. And I now busy learning and writing my cross platform (Windows, Linux, Android) graphics library.

Things related with CRT unit means old things to me. Memories are nostalgic, but I live in now and future.

I will leave this question to someone else more capable to answer.

But if I'm not wrong, SDL already include keyboard/mouse trapping functions.

Handoko

  • Hero Member
  • *****
  • Posts: 5151
  • My goal: build my own game engine using Lazarus
I had already noticed Manuel Di Criscito = Manu12x. And I know you're very eager to learn game programming, just as who I was many years ago. (oh ... i see a duplicate of me some decades ago)

Eagerness isn't much help in programming. What will make you to become a better programmer are hardwork, open to suggestions/critics, patient and time.

Wish you luck!

molly

  • Hero Member
  • *****
  • Posts: 2330
But if I'm not wrong, SDL already include keyboard/mouse trapping functions.
That is correct. Buffered and all, working out of the box for you.

Eagerness isn't much help in programming. What will make you to become a better programmer are hardwork, open to suggestions/critics, patient and time.
I agree.

And to add to that, many many practice and experimenting.

Back in the day there wasn't much to look at (e.g. not many people with a modem and or internet) but, in this day and age there are many nice game projects that you could take a look at to see how certain things are being solved/approached. There are many tutorials around as well, even though that sometimes means you have to understand a little of c.

Handoko

  • Hero Member
  • *****
  • Posts: 5151
  • My goal: build my own game engine using Lazarus
So, Manuel Di Criscito. Are you ready now to convert your eagerness to something more useful?

If your answer is yes, then there is home work for you.

Follow the instruction I wrote in this thread:
http://forum.lazarus.freepascal.org/index.php?topic=30799.0
               ;D

Read it and follow the links. Study them, try all the tools there. After then, there is no doubt you really are a game programmer/developer. 8-)

DiCri

  • Full Member
  • ***
  • Posts: 151
  • My goal : Build a game
    • http://manueldicriscito.altervista.org/DinoLand.zip
So, Manuel Di Criscito. Are you ready now to convert your eagerness to something more useful?

If your answer is yes, then there is home work for you.

Follow the instruction I wrote in this thread:
http://forum.lazarus.freepascal.org/index.php?topic=30799.0
               ;D

Read it and follow the links. Study them, try all the tools there. After then, there is no doubt you really are a game programmer/developer. 8-)
The cause is that i love creating and programming, so this is a lot of curiosity.. And i'm 14 years old.. At school we learn only simple basics of crt unit on Turbo Pascal.. This is my dream. Sorry at all!
I'm a game developer.. Now studying..
Go download my game:
http://manueldicriscito.altervista.org/DinoLand.zip

Handoko

  • Hero Member
  • *****
  • Posts: 5151
  • My goal: build my own game engine using Lazarus
Nothing wrong with you, young developer. Curiosity is the motivation that makes one becomes a programmer.

Also, there is nothing wrong with CRT and Graph units. The simplicity makes them easy to learn, so they're often used for class teaching. Unfortunately, both of them aren't actively maintained. Which also mean, they're lack of many features modern alternatives can offer.

Grab any programming topics you can find. Maybe some years later, you'll be back here to announce your new game Angel Bird or Mineclub which can run on Android phones even iPhones.

Wish your dream comes true!

DiCri

  • Full Member
  • ***
  • Posts: 151
  • My goal : Build a game
    • http://manueldicriscito.altervista.org/DinoLand.zip
Nothing wrong with you, young developer. Curiosity is the motivation that makes one becomes a programmer.

Also, there is nothing wrong with CRT and Graph units. The simplicity makes them easy to learn, so they're often used for class teaching. Unfortunately, both of them aren't actively maintained. Which also mean, they're lack of many features modern alternatives can offer.

Grab any programming topics you can find. Maybe some years later, you'll be back here to announce your new game Angel Bird or Mineclub which can run on Android phones even iPhones.

Wish your dream comes true!
At school we don't do graph.. we 've not done arrays yet :D thanks!
I'm a game developer.. Now studying..
Go download my game:
http://manueldicriscito.altervista.org/DinoLand.zip

 

TinyPortal © 2005-2018