Saturday, April 20, 2013

Confused About Pointers, Trying To Make Homing Missile - C And ...


Example
#{example}
"); ipb.editor_values.get('templates')['togglesource'] = new Template("
??? Cancel Source Edit
"); ipb.editor_values.get('templates')['toolbar'] = new Template(""); ipb.editor_values.get('templates')['button'] = new Template("
  • Icon
  • "); ipb.editor_values.get('templates')['menu_item'] = new Template("
  • #{title}
  • "); ipb.editor_values.get('templates')['togglesource'] = new Template("
    ??? Cancel Source Edit
    "); ipb.editor_values.get('templates')['emoticons_showall'] = new Template(""); ipb.editor_values.get('templates')['emoticon_wrapper'] = new Template("

    Emoticons

    "); // Add smilies into the mix ipb.editor_values.set( 'show_emoticon_link', false ); ipb.editor_values.set( 'bbcodes', $H({"snapback":{"id":"1","title":"Post Snap Back","desc":"This tag displays a little linked image which links back to a post - used when quoting posts from the board. Opens in same window by default.","tag":"snapback","useoption":"0","example":"[snapback]100[/snapback]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"topic":{"id":"5","title":"Topic Link","desc":"This tag provides an easy way to link to a topic","tag":"topic","useoption":"1","example":"[topic=1]Click me![/topic]","switch_option":"0","menu_option_text":"Enter the topic ID","menu_content_text":"Enter the title for this link","single_tag":"0","optional_option":"0","image":""},"post":{"id":"6","title":"Post Link","desc":"This tag provides an easy way to link to a post.","tag":"post","useoption":"1","example":"[post=1]Click me![/post]","switch_option":"0","menu_option_text":"Enter the Post ID","menu_content_text":"Enter the title for this link","single_tag":"0","optional_option":"0","image":""},"spoiler":{"id":"7","title":"Spoiler","desc":"Spoiler tag","tag":"spoiler","useoption":"0","example":"[spoiler]Some hidden text[/spoiler]","switch_option":"0","menu_option_text":"","menu_content_text":"Enter the text to be masked","single_tag":"0","optional_option":"0","image":""},"acronym":{"id":"8","title":"Acronym","desc":"Allows you to make an acronym that will display a description when moused over","tag":"acronym","useoption":"1","example":"[acronym='Laugh Out Loud']lol[/acronym]","switch_option":"0","menu_option_text":"Enter the description for this acronym (EG: Laugh Out Loud)","menu_content_text":"Enter the acronym (EG: lol)","single_tag":"0","optional_option":"0","image":""},"hr":{"id":"12","title":"Horizontal Rule","desc":"Adds a horizontal rule to separate text","tag":"hr","useoption":"0","example":"[hr]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"1","optional_option":"0","image":""},"php":{"id":"14","title":"PHP Code","desc":"Allows you to enter PHP code into a formatted/highlighted syntax box","tag":"php","useoption":"0","example":"[php]$variable = true;\n\nprint_r($variable);[/php]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"html":{"id":"15","title":"HTML Code","desc":"Allows you to enter formatted/syntax-highlighted HTML code","tag":"html","useoption":"0","example":"[html]\n \n[/html]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"sql":{"id":"16","title":"SQL Code","desc":"Allows you to enter formatted/syntax-highlighted SQL code","tag":"sql","useoption":"0","example":"[sql]SELECT p.*, t.* FROM posts p LEFT JOIN topics t ON t.tid=p.topic_id WHERE t.tid=7[/sql]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"xml":{"id":"17","title":"XML Code","desc":"Allows you to enter formatted/syntax-highlighted XML code","tag":"xml","useoption":"0","example":"[xml]\n \n Test\n \n[/xml]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"member":{"id":"31","title":"Member","desc":"Given a member name, a link is automatically generated to the member's profile","tag":"member","useoption":"1","example":"[member=skyhawk133] runs this site.","switch_option":"0","menu_option_text":"Input Username of Member","menu_content_text":"","single_tag":"1","optional_option":"0","image":"memberbbcode.png"},"extract":{"id":"33","title":"Extract Blog Entry","desc":"This will allow users to define an extract for an entry. Only this piece of the entry will be displayed on the main blog page and will show up in the RSS feed.","tag":"extract","useoption":"0","example":"[extract]This is an example![/extract]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"blog":{"id":"34","title":"Blog Link","desc":"This tag provides an easy way to link to a blog.","tag":"blog","useoption":"1","example":"[blog=100]Click me![/blog]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"entry":{"id":"35","title":"Blog Entry Link","desc":"This tag provides an easy way to link to a blog entry.","tag":"entry","useoption":"1","example":"[entry=100]Click me![/entry]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"twitter":{"id":"36","title":"Twitter","desc":"A tag to link to a user's twitter account","tag":"twitter","useoption":"0","example":"[twitter]userName[/twitter]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":"twitter.png"},"inline":{"id":"37","title":"Inline Code","desc":"Formats code inline instead of in a seperate code box. ","tag":"inline","useoption":"0","example":"[inline]style=\"font-size: 12px;\"[/inline]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"il":{"id":"38","title":"Abbreviated Inline (IL)","desc":"Abbreviated version of the [inline] tag. ","tag":"il","useoption":"0","example":"[il]Code Here[/il]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":"il2.png"},"code":{"id":"41","title":"Code","desc":"Allows you to enter general code","tag":"code","useoption":"1","example":"[code]$text = 'Some long code here';[/code]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"1","image":""}}) ); ipb.vars['emoticon_url'] = "http://cdn.dreamincode.net/forums/public/style_emoticons/default"; //Search Setup ipb.vars['search_type'] = 'forum'; ipb.vars['search_type_id'] = 15; ipb.vars['search_type_2'] = 'topic'; ipb.vars['search_type_id_2'] = 318863; //]]>

    8 Replies - 75 Views - Last Post: Today, 09:11 AM Rate Topic: -----

    #1 Nano511 ?Icon User is offline

    Reputation: 1

    • Posts: 92
    • Joined: 07-October 12

    Posted Today, 07:15 AM

    I need a way for the bullet to have the coordinates of its target, so i thought i could use a pointer. But it isnt exactly working out.

    Here is the code i attempted:

    
 //class Bullet_TrackingMissile Bullet_TrackingMissile (sf::Texture& spriteSheet, Enemy& target, int x, int y,int range) { 	this->target = target;  	//other code cut because it is irrelevant }  void Update() {         //check if target is null(if null that means it has died) 	target->//no members available  	float deltaX = target->GetX() - xPos; 	float deltaY = target->GetY() - yPos; 	float angle = std::atan(deltaY/deltaX)/DEGTORAD;  	if( deltaX < 0 ){ angle += 180;} 	if( deltaX >= 0 && deltaY < 0 ){ angle+= 360;} } 

    pls respond


    Is This A Good Question/Topic? 0

    Replies To: Confused about pointers, trying to make homing missile

    #2 jimblumberg ?Icon User is offline

    Reputation: 2946

    • Posts: 8,952
    • Joined: 25-December 09

    Re: Confused about pointers, trying to make homing missile

    Posted Today, 07:19 AM

    Quote

    But it isnt exactly working out.

    So would you mind telling exactly why it's not "working out"?

    You need to ask specific questions based on the code you provided.

    Jim


    #3 Nano511 ?Icon User is offline

    Reputation: 1

    • Posts: 92
    • Joined: 07-October 12

    Re: Confused about pointers, trying to make homing missile

    Posted Today, 07:37 AM

    Oops sorry. The problem was that target has no available members in line 12


    #4 jimblumberg ?Icon User is offline

    Reputation: 2946

    • Posts: 8,952
    • Joined: 25-December 09

    Re: Confused about pointers, trying to make homing missile

    Posted Today, 07:41 AM

    So how can we help? You haven't told us anything about this "target" or really any relevant data. In your snippets "target" seems to be uninitialized but I really can't tell with the paltry amount of code you've shown.

    You need to post the smallest complete program that illustrates your problem.

    Jim


    #5 Nano511 ?Icon User is offline

    Reputation: 1

    • Posts: 92
    • Joined: 07-October 12

    Re: Confused about pointers, trying to make homing missile

    Posted Today, 07:53 AM

    
 #pragma once  #include "Bullet.h"  class Bullet_TrackingMissile : public Bullet { private: 	Enemy* target; public: 	Bullet_TrackingMissile (sf::Texture& spriteSheet, Enemy* target, int x, int y,int range) 	{ 		this->target = target;  		s_Sprite.setTexture(spriteSheet);  		xPos = x; 		yPos = y;  		speed = 4; 		this->range = range/speed; 		rangeCnt = 0;  		damage = 10; 		s_Sprite.setTextureRect(sf::IntRect(22, 8, 5, 5)); 		s_Sprite.setOrigin(2,2);  	}  	void Update() 	{ 		target->//no members 	} }; 


    #6 jimblumberg ?Icon User is offline

    Reputation: 2946

    • Posts: 8,952
    • Joined: 25-December 09

    Re: Confused about pointers, trying to make homing missile

    Posted Today, 08:01 AM

    So like I said it looks, from the paltry code you provided, that target is not initialized. What is an Enemy? Where and how are you initializing this pointer? Either show all the relevant code or I can't help you.

    Jim

    This post has been edited by jimblumberg: Today, 08:02 AM


    #7 Nano511 ?Icon User is offline

    Reputation: 1

    • Posts: 92
    • Joined: 07-October 12

    Re: Confused about pointers, trying to make homing missile

    Posted Today, 08:03 AM

    okay i changed it to this:
    
 Bullet_TrackingMissile (sf::Texture& spriteSheet, Enemy* target, int x, int y,int range) 	{ 		this->target = new Enemy(); 		this->target = target; 

    but this->target still doesnt have any available members.

    edit: should have been this->target = new Enemy();

    This post has been edited by Nano511: Today, 08:15 AM


    #8 jimblumberg ?Icon User is offline

    Reputation: 2946

    • Posts: 8,952
    • Joined: 25-December 09

    Re: Confused about pointers, trying to make homing missile

    Posted Today, 08:29 AM

    Since you won't provide the necessary information I can be of no further help. Good luck with your project.

    By the way your last snippet probably generates a memory leak when you reassign the pointer you allocated with new to point to something else.

    Jim


    #9 Nano511 ?Icon User is offline

    Reputation: 1

    • Posts: 92
    • Joined: 07-October 12

    Re: Confused about pointers, trying to make homing missile

    Posted Today, 09:11 AM

    My problem was that Enemy wasnt included. Thanks for the help though


    Page 1 of 1


    Source: http://www.dreamincode.net/forums/topic/318863-confused-about-pointers-trying-to-make-homing-missile/

    jenny mccarthy auld lang syne dick clark Happy new year fiscal cliff Pitbull Hannah Storm

    No comments:

    Post a Comment

    Note: Only a member of this blog may post a comment.