• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Thomas Wiborg

Target bounce away from wall

10 posts in this topic

Im very newbie and making a 2d spaceship game, similar to Stargunner.
I have target(enemies) coming from right side of screen and heading left, where my ship is at.
My targets are circles who randomly chooses Y coords from 0, 640.
The thing is. When one of my targets hit the upper "wall" i want them to bounce down.
And my problem is that i cant modify the value of Points. What can i do, is it even possible to modify Points values?

 

I have my properties in GameItem class.

 

"Cannot modify the return value of 'SpaceAttack.GameItem.Position' because it is not a variable"


 

 if (target.Position.Y < 0)
            {
                target.Position = new Point(this.target.Position.X, this.target.Position.Y = 0);

                target.Velocity = new Point(this.target.Velocity.X, this.target.Velocity.Y *= -1);
            }

 

 

0

Share this post


Link to post
Share on other sites

You don't need to bounce enemies off walls.

 

If the enemies must appear within the range [0 - 640], then all you have to do is get a random value between 0 + enemyHeight/2 and 640 - enemyHeight/2 (the enemyHeight/2 in a circle is the radius).

This makes the enemy spawn inside the screen.

 

If what your asking is that you have an enemy that can move in the Y axis (up/down), and when it would go outside the screen you want to bounce it off on the walls, then a simple way to do it, is if you have a variable for the enemy's velocity(acceleration), when the enemy hits the wall, you change the velocity's sign. This will make the enemy suddenly move in the other direction, therefore bouncing it off on the wall.

 

I don't know what language you're working on, but to me it seems it is ActionScript.

 

If it is so, then perhaps you can go to http://asgamer.com/2009/flash-game-design-basics-adding-library-objects-to-stage-with-as3 to get a good tutorial on how to make spaceship game (although this is a vertical shooter) in AS3. It presents various concepts such as ship movement, the bouncing on walls, enemies, and even a star filled background.

This tutorials are separated into articles, so search them in the site.

 

If you're not using AS3, then perhaps you could show some more code, to see if i can help you more.

1

Share this post


Link to post
Share on other sites

If your enemy is less than the screen min or greater than the screen max you would reverse the speed of x and/or y.

 

[code]xSpeed = 1; ySpeed = 1; If (target.x < screenMinX || target.x > screenMaxX)     xSpeed = -xSpeed; //reverse if(target.y < screenMinY || target.y > screenMaxX)     ySpeed = -ySpeed; //reverse</pre> target.x += xSpeed; target.y += ySpeed;[/code]

 

you mean that?

Edited by 0Circle0
1

Share this post


Link to post
Share on other sites
Correct. But the problem is that i cant modify the value of point. Is there a way to modify point?
Im using C# XNA :)
0

Share this post


Link to post
Share on other sites

Why can you not modify the point?

 

The code you posted in the OP was trying to replace the point, which could be no good for any number of reasons depending on the class. Can't you just

 

if(target.Position.Y < 0) {
  target.Position.Y = 0;
  target.Velocity.Y = -target.Velocity.Y;
}
Edited by Khatharr
1

Share this post


Link to post
Share on other sites

If target.Velocity is a C# Property then you won't be able to modify its members, since a Point in C# is of the struct data type. What this means is that target.velocity returns a temporary copy of your data, so modifying that has little meaning. The solution is to either just make velocity public, without any get:ers and set:ers, or create a method that allow you to set velocity, like so

 

public void SetVelocity(int velX, int velY)
{
      velocity.X = velX;
      velocity.Y = velY;
}

 

Why are you using Points by the way? I would suggest using Vector2 for things like speed and velocity. It's better suited for that kind of stuff

 

 

Hope that helps smile.png

1

Share this post


Link to post
Share on other sites
If target.Velocity is a C# Property then you won't be able to modify its members, since a Point in C# is of the struct data type. What this means is that target.velocity returns a temporary copy of your data, so modifying that has little meaning. The solution is to either just make velocity public, without any get:ers and set:ers, or create a method that allow you to set velocity, like so

 

public void SetVelocity(int velX, int velY)
{
      velocity.X = velX;
      velocity.Y = velY;
}

 

Why are you using Points by the way? I would suggest using Vector2 for things like speed and velocity. It's better suited for that kind of stuff

 

 

Hope that helps smile.png

 

Well, Vector2 aint possible to modify like variables either?

0

Share this post


Link to post
Share on other sites
That's right. Vector2 are also a struct, so the solution is the same as those a suggested in my previous post smile.png Edited by Mizu
0

Share this post


Link to post
Share on other sites

Yeah, but what you say, is that Vector2 is better to use than Point in games? Well I fixed it. And here is my new code. Thanks alot for the help guys! Realy amazing community here on gamedev!

 


            if (target.Position.Y < 0)
            {
                Vector2 vv;
                Vector2 vp;
                vv = target.Velocity;
                vv.Y *= -1;
                target.Velocity = vv;
                
                vp = target.Position;
                vp.Y = 0;
                target.Position = vp;            
            }
            else if (target.Position.Y > SCREEN_HEIGHT - target.Origin.Y)
            {
                Vector2 v2v;
                Vector2 v2p;
                v2v = target.Velocity;
                v2v.Y *= -1;
                target.Velocity = v2v;

                v2p = target.Position;
                v2p.Y = SCREEN_HEIGHT - target.Origin.Y;
                target.Position = v2p;      
            }

 

Edited by Thomas Wiborg
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0