This site requires JavaScript, please enable it in your browser!
Greenfoot back
Telko
Telko wrote ...

2017/3/23

Different types of movement

Telko Telko

2017/3/23

#
Peace, Im working on a race car game where the player just moves up and down. To make it more interesting I want to implement several types of movement. Currently I have the basic "press button to move in the direction you want" and "press button to change the direction the car moves (it moves permanent)". At the moment im trying to make a movement like in the asteroids szenario, but i cant figure it out, because i only have an Up- and Down movement. I know that I have to use a SmartMover support class but setLocation(getX(), getY()+"something") does not work in this term I think. Also I want to ask if you have other ideas for different type of movement?
danpost danpost

2017/3/23

#
You might want to check out my Asteroids w/improved QActor SuperClass scenario which has a smooth moving and rotation superclass for the actor.
Telko Telko

2017/3/23

#
Thanks for youre response! When I open youre scenario there are errors in 4 classes because the color declaration is not fat and this java.awt.color. does not work in this version. I exchangend every color with fat letters and deleted the java.awt, it compiles but reports a NullPointerExeption.
java.lang.NullPointerException
	at greenfoot.GreenfootImage.<init>(GreenfootImage.java:171)
	at Space.adjustScore(Space.java:71)
	at Space.<init>(Space.java:20)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at greenfoot.core.Simulation.newInstance(Simulation.java:617)
	at greenfoot.platforms.ide.WorldHandlerDelegateIDE.lambda$instantiateNewWorld$7(WorldHandlerDelegateIDE.java:430)
	at greenfoot.core.Simulation.runQueuedTasks(Simulation.java:502)
	at greenfoot.core.Simulation.maybePause(Simulation.java:305)
	at greenfoot.core.Simulation.runContent(Simulation.java:218)
	at greenfoot.core.Simulation.run(Simulation.java:211)
Telko Telko

2017/3/23

#
From what I can understand im not sure how to make it so the actor can only move vertically in a Smooth, kinda slidy way.
Super_Hippo Super_Hippo

2017/3/23

#
I am not sure how "setLocation(getX(), getY()+"something")" does not work for you. To make danpost's scenario work: Class Stats: Line 118 Class Space Lines 50, 71 and 78 In these lines, change the 'null' to 'new Color(0,0,0,0)' (or wait for the next Greenfoot version). @danpost: To make your scenarios easier to use with the newer versions, it would be good if you could name all color names in uppercase letters and instead of using 'java.awt.Color...', import it at the beginning. Then it should work without changing everything manually.
You need to login to post a reply.