Search Results

Search found 3423 results on 137 pages for 'tom daniel'.

Page 119/137 | < Previous Page | 115 116 117 118 119 120 121 122 123 124 125 126  | Next Page >

  • Restrict sprite movement to vertical and horizontal

    - by Daniel Granger
    I have been battling with this for some time and my noob brain can't quite work it out. I have a standard tile map and currently use the following code to move my enemy sprite around the map -(void) movePlayer:(ccTime)deltaTime { if (CGPointEqualToPoint(self.position, requestedPosition)) return; float step = kPlayerSpeed * deltaTime; float dist = ccpDistance(self.position, requestedPosition); CGPoint vectorBetweenAB = ccpSub(self.position, requestedPosition); if (dist <= step) { self.position = requestedPosition; [self popPosition]; } else { CGPoint normVectorBetweenAB = ccpNormalize(vectorBetweenAB); CGPoint movementVectorForThisFrame = ccpMult(normVectorBetweenAB, step); if (abs(vectorBetweenAB.x) > abs(vectorBetweenAB.y)) { if (vectorBetweenAB.x > 0) { [self runAnimation:walkLeft]; } else { [self runAnimation:walkRight]; } } else { if (vectorBetweenAB.y > 0) { [self runAnimation:walkDown]; } else { [self runAnimation:walkUp]; } } if (self.position.x > movementVectorForThisFrame.x) { movementVectorForThisFrame.x = -movementVectorForThisFrame.x; } if (self.position.y > movementVectorForThisFrame.y) { movementVectorForThisFrame.y = -movementVectorForThisFrame.y; } self.position = ccpAdd(self.position, movementVectorForThisFrame); } } movePlayer: is called by the classes updateWithDeltaTime: method. the ivar requestedPosition is set in the updateWithDeltaTime method as well, it basically gets the next point out of a queue to move to. These points can be anywhere on the map, so if they are in a diagonal direction from the enemy the enemy sprite will move directly to that point. But how do I change the above code to restrict the movement to vertical and horizontal movement only so that the enemies movement 'staircases' its way along a diagonal path, taking the manhattan distance (I think its called). As shown by my crude drawing below... S being the start point F being the finish and the numbers being each intermediate point along its path to create a staircase type diagonal movement. Finally I intend to be able to toggle this behaviour on and off, so that I can choose whether or not I want the enemy to move free around the map or be restricted to this horizontal / vertical movement only. | | | | | | | | | | | | | | | | | | | | | |F| | | | | | | | | |5|4| | | | | | | | | |3|2| | | | | | | | | |1|S| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |

    Read the article

  • Overload the behavior of count() when called on certain objects

    - by Tom
    In PHP 5, you can use magic methods, overload some classes, etc. In C++, you can implement functions that exist is STL as long as the argument types are different. Is there a way to do this in PHP? An example of what I'd like to do is this: class a { function a() { $this->list = array("1", "2"); } } $blah = new a(); count($blah); I would like blah to return 2. IE count the values of a specific array in the class. So in C++, the way I would do this might look like this: int count(a varName) { return count(varName->list); } Basically, I am trying to simplify data calls for a large application so I can call do this: count($object); rather than count($object->list); The list is going to be potentially a list of objects so depending on how it's used, it could be really nasty statement if someone has to do it the current way: count($object->list[0]->list[0]->list); So, can I make something similar to this: function count(a $object) { count($object->list); } I know PHP's count accepts a mixed var, so I don't know if I can override an individual type.

    Read the article

  • Copying a file with PHP Command

    - by Tom
    Hi, I'm having a problem using the copy function in PHP, what is wrong with it? I get the error; Parse error: syntax error, unexpected T_VARIABLE On the bottom line; $targetDir = 'file.txt'; $targetDir2 = 'file2.txt'; copy($targetDir, $targetDir2); Thanks The entire file is; <?PHP $targetDir = 'file.txt'; $targetDir2 = 'file2.txt'; copy($targetDir, $targetDir2); ?> copy and pasted from the doc.

    Read the article

  • Create Macro With Several Variables

    - by Daniel
    I have several worksheets with similar code, so I'd like to turn it into a macro. My only problem is that there are several variables. So at certain points the code looks like this: Dim Msg_1 As String Dim Msg_2 As String Public Sub ListBox1_LostFocus() ListBox1.Height = 15 With ListBox1 Msg1 = "'" For i = 0 To .ListCount - 1 If .Selected(i) Then Msg1 = Msg1 & .List(i) & "','" End If Next i End With Msg1 = Left(Msg1, Len(Msg1) - 2) Sheets("Sheet1").Range("R3", "R3") = Msg1 End Sub and so on. How can I pass in a new value for Msg1, Msg2, Msg3 for each worksheet?

    Read the article

  • Limit output of all Linux commands

    - by daniel
    I'm looking for a way to limit the amount of output produced by all command line programs in Linux, and preferably tell me when it is limited. I'm working over a server which has a lag on the display. Occasionally I will accidentally run a command which outputs a large amount of text to the terminal, such as cat on a large file or ls on a directory with many files. I then have to wait a while for all the output to be printed to the terminal. So is there a way to automatically pipe all output into a command like head or wc to prevent too much output having to be printed to terminal?

    Read the article

  • How to return a string from char[] array using recursion loop.(java)

    - by Daniel
    I am very bed in recursion... I need to convert a char[] array by using recursion loop only, into string. Without using for(),while()... loops. For example if i have char array: a[0]='H', a[1]='e', a[2]='l',a[3]= 'l',a[4]= 'o', it returns H e l l o. What I doing wrong? public String toFormattedString(char[] a) { int temp =a.length; if (a == null) return "null"; if (a.length == 0) return "0"; if( a.length == 1 ) else if( a[0] == a[a.length] ) return toFormattedString (a[a.length -1])+a[a.length];

    Read the article

  • Nested/Sub data types in haskell

    - by Tom Carstens
    So what would be nice is if you could do something like the following (not necessarily with this format, just the general idea): data Minor = MinorA | MinorB data Major = Minor | MajorB isMinor :: Major -> Bool isMinor Minor = True isMinor _ = False So isMinor MinorA would report True (instead of an error.) At the moment you might do something like: data Major = MinorA | MinorB | MajorB isMinor :: Major -> Bool isMinor MinorA = True isMinor MinorB = True isMinor _ = False It's not terrible or anything, but it doesn't expand nicely (as in if Minor when up to MinorZ this would be terribly clunky). To avoid that problem you can wrap Minor: data Minor = MinorA | MinorB data Major = MajorA Minor | MajorB isMinor :: Major -> Bool isMinor (MajorA _) = True isMinor _ = False But now you have to make sure to wrap your Minors to use them as a Major... again not terrible; just doesn't really express the semantics I'd like very well (i.e. Major can be any Minor or MajorB). The first (legal) example is "Major can be MinorA..." but doesn't have any knowledge of Minor and the second is "Major can be MajorA that takes a Minor..." p.s. No, this isn't really about anything concrete.

    Read the article

  • Error reading file with accented vowels

    - by Daniel Dcs
    The following statement to fill a list from a file : action = [] with open (os.getcwd() + "/files/" + "actions.txt") as temp:          action = list (temp) gives me the following error: (result, consumed) = self._buffer_decode (data, self.errors, end) UnicodeDecodeError: 'utf-8' codec can not decode byte 0xf1 in position 67: invalid continuation byte if I add errors = 'ignore': action = [] with open (os.getcwd () + "/ files /" + "actions.txt", errors = 'ignore') as temp:          action = list (temp) Is read the file but not the ñ and vowels accented á-é-í-ó-ú being that python 3 works, as I have understood, default to 'utf-8' I'm looking for a solution for two or more days, and I'm getting more confused. In advance thank you very much for any suggestions.

    Read the article

  • Should I focus on java or on C#

    - by Daniel
    My friend started his computer engineering studies this semester, and wants to know if he should focus on Java or C#? While I am more on the Java side of life, I don't know what to answer him unbiased, so If you can give some unbiased statements on this, this would be great.

    Read the article

  • Calculate needed size for a TLabel

    - by Tom
    Ok, here's the problem. I have a label component in a panel. The label is aligned as alClient and has wordwrap enabled. The text can vary from one line to several lines. I would like to re-size the height of the the panel (and the label) to fit all the text. How do I get the necessary height of a label when I know the text and the width of the panel?

    Read the article

  • What does this Java generics paradigm do and what is it called?

    - by Tom
    I'm looking at some Java classes that have the following form: public abstract class A <E extends A<E>> implements Comparable <E> { public final int compareTo( E other ) { // etc } } public class B extends A <B> { // etc } public class C extends A <C> { // etc } My usage of "Comparable" here is just to illustrate a possible use of the generic parameter "E". Does this usage of generics/inheritance have a name? What is it used for? My impression is that this allows the abstract class to provide a common implementation of a method (such as compareTo) without having to provide it in the subclasses. However, in this example, unlike an inherited method it would restrict subclasses to invoking compareTo on other instances of the same subclass, rather than any "A" subclass. Does this sound right? Anyway, just curious if any gurus out there have seen this before and know what it does. Thanks!

    Read the article

  • Protecting from crashes (beyond bounds) with [object objectAtIndex:]

    - by Tom
    Hi! I'd like to know if there's a way to verify if an index exists before getting it. So it'd be way to protect my code against: *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray objectAtIndex:]: index (2) beyond bounds (0)' Like in PHP you can do: isset($object[10]); and it'll return true if it exists. Is there such a method in Objective-C/Cocoa? Thanks!

    Read the article

  • Problem using IIS 7 and SQL SERVER 2008

    - by Daniel
    I have problem using IIS 7 and SQL Server 2008. When I trying to show my website using IIS as webserver I get the message "[SqlException (0x80131904): Login failed for user..." When I using the webserver included in Visual Studio 2010 to show same website there is no problem to access the database. Why is it working with VS2010 webserver but not with IIS?

    Read the article

  • DB Strategy for inserting into a high read table (Sql Server)

    - by Tom
    Looking for strategies for a very large table with data maintained for reporting and historical purposes, a very small subset of that data is used in daily operations. Background: We have Visitor and Visits tables which are continuously updated by our consumer facing site. These tables contain information on every visit and visitor, including bots and crawlers, direct traffic that does not result in a conversion, etc. Our back end site allows management of the visitor's (leads) from the front end site. Most of the management occurs on a small subset of our visitors (visitors that become leads). The vast majority of the data in our visitor and visit tables is maintained only for a much smaller subset of user activity (basically reporting type functionality). This is NOT an indexing problem, we have done all we can with indexing and keeping our indexes clean, small, and not fragmented. ps: We do not currently have the budget or expertise for a data warehouse. The problem: We would like the system to be more responsive to our end users when they are querying, for instance, the list of their assigned leads. Currently the query is against a huge data set of mostly irrelevant data. I am pondering a few ideas. One involves new tables and a fairly major re-architecture, I'm not asking for help on that. The other involves creating redundant data, (for instance a Visitor_Archive and a Visitor_Small table) where the larger visitor and visit tables exist for inserts and history/reporting, the smaller visitor1 table would exist for managing leads, sending lead an email, need leads phone number, need my list of leads, etc.. The reason I am reaching out is that I would love opinions on the best way to keep the Visitor_Archive and the Visitor_Small tables in sync... Replication? Can I use replication to replicate only data with a certain column value (FooID = x) Any other strategies?

    Read the article

  • Creating a good search solution

    - by Daniel
    I have an app where users have a role,a username,faculty and so on.When I'm looking for a list of users by their role or faculty or anything they have in common I can call (among others possible) @users = User.find_by_role(params[:role]) #or @users = User.find_by_shift(params[:shift]) So it keeps the system Class.find_by_property So the question is: What if at different points users lists should be generated based on different properties.I mean: I'm passing from different links params[:role] or params[:faculty] or params[:department] to my list action in my users controller.As I see it all has to be in that action,but which parameter should the search be made by?

    Read the article

< Previous Page | 115 116 117 118 119 120 121 122 123 124 125 126  | Next Page >