3 Replies - 644 Views - Last Post: 31 May 2012 - 01:44 PM Rate Topic: -----

#1 Tom_Leonardsson  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 67
  • Joined: 07-August 11

SDL Shoot em' up enemy movment.

Posted 29 May 2012 - 09:32 AM

Hi. Im tyring to make a game and the ene my is suppose to go up and down like this -> http://imgur.com/AMI8m
But how do I loop a movment because I've got the enemy to move but how do I loop the code? How is the code suppose to look?

Thanks!
(Sorry if my spelling was awful I have dyslexi.)

mod: added direct img embedding..
Posted Image

This post has been edited by modi123_1: 29 May 2012 - 09:44 AM
Reason for edit:: added embedded image directly


Is This A Good Question/Topic? 0
  • +

Replies To: SDL Shoot em' up enemy movment.

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 6466
  • View blog
  • Posts: 23,511
  • Joined: 12-June 08

Re: SDL Shoot em' up enemy movment.

Posted 29 May 2012 - 09:45 AM

How is your code currently set up? You should have a look that is constantly repeating and in that loop have an "enemy update" method call to make the enemy's location or actions do what they need to.
Was This Post Helpful? 0
  • +
  • -

#3 stayscrisp  Icon User is online

  • フカユ
  • member icon

Reputation: 928
  • View blog
  • Posts: 3,998
  • Joined: 14-February 08

Re: SDL Shoot em' up enemy movment.

Posted 30 May 2012 - 01:40 AM

Please post what you have so far.
Was This Post Helpful? 0
  • +
  • -

#4 TheGDeveloper  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 93
  • Joined: 22-September 09

Re: SDL Shoot em' up enemy movment.

Posted 31 May 2012 - 01:44 PM

you need to calculate the Y position of your character by using some cosine function. For example if your character walks from x=0 to x = 100 with move 5 on the update you should do something like that


void updatePos(){
    x += 5;
    y = ybase + cos(x);
}




ybase is just the line that your character will move over and below. Play with the cosine by adding,multiplying and dividing to get the results that you want
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1