Page 1 of 1
movement direction
Posted: Wed Dec 14, 2016 5:12 pm
by peceha
Hi there
I'm just starting my adventure with programming and with Hollywood.
Have been reading included help (for few hours) and only found that:
Code: Select all
While quit = False
dir = p_QueryInput()
If dir = "Left" Then p_MoveSpriteLeft()
If dir = "Right" Then p_MoveSpriteRight()
....
Wend
now i'm trying to figure out what could be inside
p_QueryInput function to get directions.
What I found so far are these
isKeyDown and
waitKeyDown.
Do I have to built IF statement like this:
Code: Select all
down= IsKeyDown("DOWN")
up = IsKeyDown("UP")
left = IsKeyDown("LEFT")
right = IsKeyDown("RIGHT")
if down = 1 then return({0,1})
if up = 1 then return({0,-1})
if left= 1 then return({-1,0})
if right= 1 then return({1,0})
How can I know what key is pressed ?
Thanks
Re: movement direction
Posted: Wed Dec 14, 2016 6:12 pm
by peceha
I figured out something in the meantime
Code: Select all
Function p_queryInput()
If IsKeyDown("UP") Then Return("up")
If IsKeyDown("DOWN") Then Return("down")
If IsKeyDown("LEFT") Then Return("left")
If IsKeyDown("RIGHT") Then Return("right")
EndFunction
Function p_moveMeUp()
If player_y > 0
player_y = player_y - 1
EndIf
EndFunction
...
Function p_mainLoop()
dir = p_queryInput()
If dir = "up" Then p_moveMeUp()
If dir = "right" Then p_moveMeRight()
If dir = "down" Then p_moveMeDown()
If dir = "left" Then p_moveMeLeft()
DisplaySprite(1, player_x*16, player_y*16)
EndFunction
Re: movement direction
Posted: Wed Dec 14, 2016 6:28 pm
by peceha
ok, I'm getting somewhere - maybe other newbies will find it usefull
Code: Select all
Function p_HandlerFunc(msg)
If msg.key = "UP" Then p_moveMeUp()
If msg.key = "RIGHT" Then p_moveMeRight()
If msg.key = "DOWN" Then p_moveMeDown()
If msg.key = "LEFT" Then p_moveMeLeft()
DisplaySprite(1, player_x*16, player_y*16)
EndFunction
InstallEventHandler({OnKeyDown = p_HandlerFunc})
While quit = False
WaitEvent()
Wend
Re: movement direction
Posted: Tue Dec 27, 2016 9:47 pm
by peceha
Hello,
I'm coming back to this thread since have another question about movement.
Below you can find all files to run my project
- just start MYGAME.HWS and then use <arrows> to walk around, <space> to generate another map or funtion keys <F1..F6> to set some basic parameters for creation algorytm. Please note that i'm starting my adventure with programming and the code itself is a one big mess - I'm aware of that - but it works
.
Back to my question - when I press arrow (and KEEP IT PRESSED) to move my "hero" around, the guy moves one tile then pauses and then moves again as long as I keep arrow pressed - how can I eliminate that pause after first move? That is my question.
Thank you.
ps.
I cannot find a way to attach a file so here is the link to a hosting site with my zip file.
http://s000.tinyupload.com/?file_id=019 ... 8379597788
Re: movement direction
Posted: Thu Dec 29, 2016 9:19 am
by Allanon
Hi @peceha
First of all you prototype is really nice, the fov map is very interesting
About your problem, I had a quick look at your code and I think that the issue is caused by the key autorepeat, in fact hitting the arrows quickly the movement is smooth and continuos.
To avoid this I think the best way is to re-define your input detecting routines, you need to monitor both OnKeyDown and OnKeyUp events with some flags, something like this (code not checked):
Code: Select all
Local go_up, go_down, go_left, go_right = False, False, False, False
InstallEventHandler({ OnKeyDown = handleKeyDown, OnKeyUp = handleKeyUp })
Function handleKeyDown(msg)
Switch msg.key
Case "UP"
go_up = True
Case "DOWN"
go_down = True
Case "LEFT"
go_left = True
Case "RIGHT"
go_right = True
EndSwitch
EndFunction
Function handleKeyUp(msg)
Switch msg.key
Case "UP"
go_up = False
Case "DOWN"
go_down = False
Case "LEFT"
go_left = False
Case "RIGHT"
go_right = False
EndSwitch
EndFunction
Then you need a update/render function that checks in where direction the player should be moved checking go_up, go_down, go_left and go_right flags.
It is not perfect but should resolve your problem.
Re: movement direction
Posted: Thu Dec 29, 2016 11:03 am
by peceha
Hi Allanon
I do appreciate that you even looked into this mess
I really do.
I think I understand what you mean so I start implementing your idea right away.
About my FOV
, well... there are so many IFs becuse the maze is build differently - the explanation about FOV that I found was only for "standard" dungeon where a tile can have wall or floor (nothing else) like this:
I decided to build the tile consisting walls and/or floors so in my case it may look like this:
To say more I'm trying to make this program run on amiga 1200 with 030 and I had to speed up something so finally I decided that wall = NIL so I could avoid many additional assignments.
Unfortunately that approach was good only during maze creation - but during FOV calculations it makes things complicated and I need more Ifs (so I will change it probably)
I think there should be a chapter "Speeding up" in HOLLYWOOD manual - it really took me about one week to find (accidentally) DisableLineHook() command
Anyway, thank You again for looking into this.
Re: movement direction
Posted: Thu Dec 29, 2016 12:12 pm
by Allanon
No problem
Feel free to ask if you need further help