AGK Keyboard input

Started by Steve Elliott, August 18, 2017, 18:43:36

Previous topic - Next topic

Steve Elliott

I'm not sure why this keyboard check for the Esc Key isn't working?  Any ideas?


do
{

..

} while(xPos < RightEdge && agk::GetRawKeyPressed(27) != 1);
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

MikeHart

I am one update behind and on Tier one, but it works for me with GetRawKeyPressed.

Steve Elliott

#2
Yeah, it seems to work on tier 1 for some reason.

On the plus side I see there's a nicer font available for printing your FPS and what have you lol  UseNewDefaultFonts(1)

This works in BASIC


// set window properties
SetWindowTitle( "TestKeyBug" )
SetWindowSize( 1024, 768, 1 )

// set display properties
SetVirtualResolution( 1024, 768 )
SetScissor( 0,0,0,0 )
UseNewDefaultFonts( 1 )

repeat

    Print( ScreenFPS() )
    Sync()
   
until GetRawKeyPressed(27) = 1  // Esc


But the loop won't work in C++


do
{
agk::Print(ScreenFPS());
agk::Sync();

} while (agk::GetRawKeyPressed(27) != 1 );
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

Qube

Looks like a bug to me. But I don't code in c++.

Does it still ignore the keypress if you change the line to


do
{
agk::Print(ScreenFPS());
agk::Sync();

} while (agk::GetRawKeyPressed(27) <> 1 );

Mac Studio M1 Max ( 10 core CPU - 24 core GPU ), 32GB LPDDR5, 512GB SSD,
Beelink SER7 Mini Gaming PC, Ryzen 7 7840HS 8-Core 16-Thread 5.1GHz Processor, 32G DDR5 RAM 1T PCIe 4.0 SSD
MSI MEG 342C 34" QD-OLED Monitor

Until the next time.

Steve Elliott

Aw come on guys (AGK) I've been there 5 minutes and I'm finding bugs already.

That's not correct C++ mate, that's a BASIC <>, it's ! in C++.
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

Steve Elliott

#5
To be honest I think AGK is seeming great if you want to use AGK BASIC for creating apps for mobile devices.

For C++ and desktop - with the odd conversion to a mobile device, not so good.
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

Qube

QuoteThat's not correct C++ mate, that's a BASIC <>, it's ! in C++.
Is you dissing my ninja C++ skills? :o

Quite few people use Tier2 with AGK so perhaps slap up a post on the AGK forums with your little example code.
Mac Studio M1 Max ( 10 core CPU - 24 core GPU ), 32GB LPDDR5, 512GB SSD,
Beelink SER7 Mini Gaming PC, Ryzen 7 7840HS 8-Core 16-Thread 5.1GHz Processor, 32G DDR5 RAM 1T PCIe 4.0 SSD
MSI MEG 342C 34" QD-OLED Monitor

Until the next time.

Steve Elliott

Quote
Is you dissing my ninja C++ skills? :o

Hehe  ;D
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

MikeHart

Quote from: Steve Elliott on August 18, 2017, 21:15:04
Aw come on guys (AGK) I've been there 5 minutes and I'm finding bugs already.


For a  comment like this, Xaron got banned on the MonkeyCoder board. :D You love to exterage!


No seriously, I can't imagine it is a bug as I think the Player is calling the same commands. But maybe it is?

Steve Elliott

#9
Quote
Aw come on guys (AGK) I've been there 5 minutes and I'm finding bugs already.

For a  comment like this, Xaron got banned on the MonkeyCoder board. :D

lol I wouldn't post it on the official site.   :P

Quote
I can't imagine it is a bug as I think the Player is calling the same commands.

Maybe NA can try it and see if he can get it working - because he's tried the C++ version.
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

Steve Elliott

#10
Here's the full test program:


// includes
#include "MoveShips.h"

// namespace
using namespace AGK;

app App;

void app::Begin(void)
{
agk::SetWindowTitle("Move Ship");
agk::SetWindowSize(1024, 768, 1);
agk::SetDisplayAspect(1024 / 768);
agk::SetVirtualResolution(1024, 768);
agk::SetClearColor(150, 170, 204); // light blue
agk::SetVSync(1);
agk::SetScissor(0, 0, 0, 0);
agk::UseNewDefaultFonts(1); // nicer font
agk::SetRawMouseVisible(0); // hide mouse pointer

// create sprites
agk::LoadImage(1, "ship.png");

agk::CreateSprite(1, 1);
agk::CreateSprite(2, 1);
agk::CreateSprite(3, 1);

agk::SetSpriteOffset(1, 0.0f, 0.0f);
agk::SetSpriteOffset(2, 0.0f, 0.0f);
agk::SetSpriteOffset(3, 0.0f, 0.0f);
}

int app::Loop (void)
{
// get bounds for full screen
float LeftEdge  = agk::GetScreenBoundsLeft();
float RightEdge = agk::GetScreenBoundsRight();
float xPos = LeftEdge - 64.0f;
int Key = 0;

bool Looping = true;
do
{
agk::Print(agk::ScreenFPS());
// position sprites
agk::SetSpritePosition(1, xPos, 152.0);
agk::SetSpritePosition(2, xPos, 352.0);
agk::SetSpritePosition(3, xPos, 552.0);
agk::Sync();
xPos += 2.0;

if(agk::GetRawKeyPressed(27) == 1) Looping = false;
if (xPos > RightEdge) Looping = false;

} while (Looping);

return 1;
}

void app::End(void)
{
// free resources
if(agk::GetImageExists(1)  == 1) agk::DeleteImage(1);
if(agk::GetSpriteExists(1) == 1) agk::DeleteSprite(1);
if(agk::GetSpriteExists(2) == 1) agk::DeleteSprite(2);
if(agk::GetSpriteExists(3) == 1) agk::DeleteSprite(3);
}


MoveShips.h

#ifndef _H_AGK_TEMPLATE_
#define _H_AGK_TEMPLATE_

// Link to GDK libraries
#include "AGK.h"

#define DEVICE_WIDTH 1024
#define DEVICE_HEIGHT 768
#define DEVICE_POS_X 32
#define DEVICE_POS_Y 32
#define FULLSCREEN false

// used to make a more unique folder for the write path
#define COMPANY_NAME "My Company"

// Global values for the app
class app
{
public:

// constructor
app() { memset ( this, 0, sizeof(app)); }

// main app functions - mike to experiment with a derived class for this..
void Begin( void );
int Loop( void );
void End( void );
};

extern app App;

#endif

// Allow us to use the LoadImage function name
#ifdef LoadImage
#undef LoadImage
#endif
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

Steve Elliott

#11
Ook, I've sorted the problem in my code.  Basically the built-in AGK Loop Function doesn't require you to add another one lol.

With that in mind I had to re-write my code now I understand how C++ differs from BASIC in AGK.

Either let the ships go off screen and the program ends, or press escape.


// includes
#include "MoveShips.h"

// namespace
using namespace AGK;

app App;

void app::Begin(void)
{
agk::SetWindowTitle( "Move Ship" );
agk::SetWindowSize( 1024, 768, 1 );
agk::SetDisplayAspect( 1024 / 768 );
agk::SetVirtualResolution( 1024, 768 );
agk::SetClearColor( 150, 170, 204 ); // light blue
agk::SetVSync(1);
agk::SetScissor( 0, 0, 0, 0 );
agk::UseNewDefaultFonts(1); // nicer font
agk::SetRawMouseVisible(0); // hide mouse pointer

// create sprites
agk::LoadImage( 1, "ship.png" );

agk::CreateSprite( 1, 1 );
agk::CreateSprite( 2, 1 );
agk::CreateSprite( 3, 1 );

agk::SetSpriteOffset( 1, 0.0f, 0.0f );
agk::SetSpriteOffset( 2, 0.0f, 0.0f );
agk::SetSpriteOffset( 3, 0.0f, 0.0f );

float LeftEdge = agk::GetScreenBoundsLeft(); // get bounds for full screen

// position sprites
float xPos = LeftEdge - 64.0f;
agk::SetSpritePosition( 1, xPos, 152.0 );
agk::SetSpritePosition( 2, xPos, 352.0 );
agk::SetSpritePosition( 3, xPos, 552.0 );
}

int app::Loop(void)
{
float RightEdge = agk::GetScreenBoundsRight(); // get bounds for full screen
float xPos      = agk::GetSpriteX(1);
int KeyEsc      = agk::GetRawKeyState(27);

//agk::Print(agk::ScreenFPS());
agk::Sync();

// re-position sprites
xPos += 2.0;
agk::SetSpritePosition( 1, xPos, 152.0 );
agk::SetSpritePosition( 2, xPos, 352.0 );
agk::SetSpritePosition( 3, xPos, 552.0 );

// break from program
if ( xPos > RightEdge ) PostQuitMessage(0);
if ( KeyEsc )           PostQuitMessage(0);

return 0;
}

void app::End(void)
{
// free resources
if (agk::GetImageExists(1) == 1) agk::DeleteImage(1);
if (agk::GetSpriteExists(1) == 1) agk::DeleteSprite(1);
if (agk::GetSpriteExists(2) == 1) agk::DeleteSprite(2);
if (agk::GetSpriteExists(3) == 1) agk::DeleteSprite(3);
}
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

Steve Elliott

Sorted my bug (see above)   :D
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb