473,396 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Moving an object by user input

9
I'm looking for a tutorial (preferably with livewires) or some sort of documentation on how to control an object with user input.

Basically what i want to do is move an object with the arrow keys.

Any suggestions?
Mar 10 '09 #1
2 2579
boxfish
469 Expert 256MB
In the book I have, Python for the Absolute Beginner, it's done something like this. The object has a member named screen, which is a reference to the main Screen object.
Expand|Select|Wrap|Line Numbers
  1. def moved(self):
  2.     x, y = self.get_pos()
  3.     if self.screen.is_pressed(games.K_LEFT):
  4.         x -= 1
  5.     if self.screen.is_pressed(games.K_UP):
  6.         y -= 1
  7.     if self.screen.is_pressed(games.K_RIGHT):
  8.         x += 1
  9.     if self.screen.is_pressed(games.K_DOWN):
  10.         y += 1
  11.     self.move_to(x, y)
  12.  
I hope this helps.
Mar 10 '09 #2
GKRAFT
9
Used that code and added

self.init_mover(dx=0, dy=0)

and it works perfectly.

Thanks man!
Mar 11 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Kirok | last post by:
Hey Everyone, Thanks for reading, heres what I'm trying to do I have an array of say 10 items each item contains the text / description for a room. Now I would like to create a class (lets...
4
by: Woody Splawn | last post by:
I have a grid with, lets say, 3 fields in it, Debit, Credit and Comments, in that order. When the user moves to the debit field, if he enters data in it, I would like for the cursor to skip past...
1
by: Raja | last post by:
Hi everybody I am converting my pages to use ObjectDataSource instead of SqlDataSource and want to keep the same user interface but have a small problem. In a page using SqlDataSource I have a...
3
by: Chris S | last post by:
We are moving from ASP.Net 1.1 to ASP.Net 2.0. As we do not have the luxury of spending weeks trying out different techniques, I'd like to rely on some tried and true methods, but need some...
1
by: =?Utf-8?B?UmljaA==?= | last post by:
In a database search application (vb2005), the user wants to be able to scroll through records using the mousewheel. The data display form contains textboxes for the main data and a datagridview...
8
by: palani12kumar | last post by:
hi. i want to draw an object in C, and then i want to move the object according to the user's input. That is if the user presses the left arrow, the object should move left from its current position...
15
by: mcjason | last post by:
I saw something interesting about a grid pair puzzle problem that it looks like a machine when you find each that work out the way it does and say with all the others that work out the way they...
5
by: quirk | last post by:
I am trying to write a script where a page is populated with some maths questions, user answers them (it's timed but I've left this bit out), gets results on same page and ajax takes their score,...
5
by: adarshyam | last post by:
Hi friends, I have an interesting problem in vb.net. And I am struggling to get a solution for this..m trying for the past 3days.. It’s to calculate moving average for the inputs given by the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.