Objects not moving

Monkey Forums/Monkey Beginners/Objects not moving

probson(Posted 2017) [#1]
Hi,

I have a year 13(17/18) year old young lad who has made a game in Monkey_X. He has made it so that the menu is made up of 4 backgrounds so that when he presses down key it changes image. This works but have to go onto new table in Chrome and back on to see this happen.

The same happens in his main game. He has a zombie on the screen and the X and Y is updating as if you print them out can see them moving. Again the zombie even though told to move isn't. So you go off tab and back on and it does move.

How can I fix this? Tried loads to try and move this forward but not sure how.

Import zombie
Import barricade 'Libraries and globals
Import mojo
'This loads a set of commands to be used throughout the development of the program
Global Game:apocdefence 'This assigns the name "apocdefence" to the variable Game

'Main program starts here
Function Main ()
Game = New apocdefence 'This declares the New Game as apocdefence
End 'This marks the End of the function Main

'Main game class
Class apocdefence Extends App 'Indicates that apocdefence App can be edited
Field menu:Image
Field arrow:Image 'This states that variable menu is an Image
Global GameState:String = "MENU" 'GameState is the current state of the game
Global menu_number:Int
Global options_numberx:Int
Global options_numbery:Int 'Defines the menu_number as an integer so it can be counted for different images
Field zombie_test:Zombie
Field barricade:Barricade
Field background:Image
Field options:Image
Field instructions:Image


Method OnCreate () 'Every variable is defined here such as menu and menu_number
'All the game initialisation goes in here
SetUpdateRate 60 'How often the program checks for change in the game such as object intersection 'This loads the image saved in the pink font colour
menu_number = 0
options_numberx = 0
options_numbery = 0
'This sets the menu_number to 0 displaying the play game image
zombie_test = New Zombie()
barricade = New Barricade()
menu = LoadImage ("APOCALYPSETITLE-Play Game.png")
options = LoadImage ("apocdefenceoptions.png")
background = LoadImage("apocbackground.png")
instructions = LoadImage("apocinstructions.png")
End

Method OnUpdate ()
'All the game logic goes in here:
Select GameState
Case "MENU" 'This shows the case as menu so it can be updated


If menu_number <3 'Sets a limit so menu_number cannot be greater than 3
If KeyHit (KEY_DOWN) Then menu_number = menu_number + 1 'When down key is pressed then the menu_number will add one
End If
If menu_number >0 'Menu number cannot be lower than 0
If KeyHit (KEY_UP) Then menu_number = menu_number - 1 'If key is up then the menu_number is changed to menu_number -1
End If







If menu_number = 0 And KeyHit (KEY_SPACE) Then 'Sets case to Playing when space is pressed over "play game"
GameState = "PLAYING"

Elseif menu_number = 1 And KeyHit (KEY_SPACE) Then 'Sets Case to options if space is hit over "options"
GameState = "OPTIONS"

Elseif menu_number = 2 And KeyHit (KEY_SPACE) Then 'Sets case to instructions changing
GameState = "INSTRUCTIONS"

Elseif menu_number = 3 And KeyHit (KEY_SPACE) Then
GameState = "EXIT"
Endif



Case "OPTIONS"
'When the case is options, options image is loaded

'arrow = LoadImage ("apocdefarrow.png")

'Loads arrow when case is options and menu is loade
If options_numberx <2 'Sets a limit so options_number cannot be greater than 3
If KeyHit (KEY_DOWN) Then options_numberx = options_numberx + 1 'When down key is pressed then the options_number will add one
End If
If options_numberx >0 'Options number cannot be lower than 0
If KeyHit (KEY_UP) Then options_numberx = options_numberx - 1 'If key is up then the options_number is changed to options_number -1
End If


If options_numbery <1 'Sets a limit so options_number cannot be greater than 3
If KeyHit (KEY_RIGHT) Then options_numbery = options_numbery + 1 'When down key is pressed then the options_number will add one
End If
If options_numbery >0 'Options number cannot be lower than 0
If KeyHit (KEY_LEFT) Then options_numbery = options_numbery - 1 'If key is up then the options_number is changed to options_number -1
End If





If options_numberx = 0 And options_numbery = 0 Then

End If

If options_numberx = 1 And options_numbery = 0 Then

End If

If options_numberx = 0 And options_numbery = 1 Then

End If

If options_numberx = 1 And options_numbery = 1 Then

End If

If options_numberx = 0 And options_numbery = 2 Then

End If

If options_numberx = 1 And options_numbery = 2 Then

End If

Print(options_numberx)
Print(options_numbery)





Case "INSTRUCTIONS" 'When the case is instructions, the user can return by pressing space


If KeyHit(KEY_SPACE) Then GameState = "MENU"



Case "PLAYING"

zombie_test.move()
barricade.barricadeimage()


Case "EXIT"




End
End

Method OnRender ()
'All the graphics drawing goes in here
Select GameState
Case "MENU"
Cls 0,0,0
DrawImage menu, 0,0
Case "INSTRUCTIONS"
Cls 0,0,0
DrawImage instructions, 0,0
Case "OPTIONS"
Cls 0,0,0
DrawImage options, 0,0
DrawImage arrow, 210,106 'Draws arrows at certain position on screen around word "on" or "off"
DrawImage arrow, 210,178
DrawImage arrow, 210,250
Case "PLAYING"
Cls 0,0,0
DrawImage background, 0,0
DrawImage zombie_test.sprite, zombie_test.zombie_x , zombie_test.zombie_y
Print(zombie_test.zombie_x)
'DrawImage barricade.wall, barricade.barricade_x , barricade.barricade_y





End
End
End


probson(Posted 2017) [#2]
Just to add to this if you put in the print command in playing it only updates when click on and off. Put this in the on update it works no problem. So it's if this part of code only executes when click on and off in on playing state. I just can't work it out at all.


dubbsta(Posted 2017) [#3]
.


probson(Posted 2017) [#4]
Confused is the full stop meant to mean something?


probson(Posted 2017) [#5]
Yes I see what mean with print command. So can see the X been updated BUT the zombie is still static on screen until you click off window and go back on. Surely someone else has had this issue before and found a solution?


Gerry Quinn(Posted 2017) [#6]
I created a stripped down version. It works okay, Press SPACE at start to go to PLAYING, and the zombie moves. But if you go to OPTIONS, there's no way back! Maybe you intend to test for SPACE during options case to get back and do whatever the options do.



PS. Check use of 'codebox' so you can copy in code and see it properly formatted as above!


probson(Posted 2017) [#7]
Thanks Gerry that is great. I found it in the end. It was because he had on update a reference to a method in his class which was using same identifier for a barrier image. As it was swapping the image there it doesn't update on screen until that has updated.

So will need to get back to drawing board with that part of his game. Yeah he hadn't implemented that part of the game.