Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

burnt_casadilla

Member Since 10 Jul 2011
Offline Last Active Today, 08:04 AM
-----

#5060188 XNA Code Help - Drawing Collision Rectangle

Posted by burnt_casadilla on 07 May 2013 - 11:20 PM

Rectangle shipBounds = new Rectangle((int)ship.shipPos.X, (int)ship.shipPos.Y, shipSprite.Width, shipSprite.Height);

 

code from my game. Pretty much you just create a rectangle object with the same dimensions as your sprite

 

for (int x = bulletBounds.Count - 1; x > -1; x-- )
            {
                for (int y = alienBounds.Count - 1; y > -1; y--)
                {
                    if (bulletBounds[x].Intersects(alienBounds[y]))
                    {
                        alienPosition.RemoveAt(y);
                        alienBounds.RemoveAt(y);
                        //bulletBounds.RemoveAt(x);
                        hit++;
                        break;
                    }
                }

 

This is my collision method. bulletBounds and alienBounds are both rectangle arrays. You can see how Intersects works also




#4995259 different way of learning

Posted by burnt_casadilla on 29 October 2012 - 08:11 PM

thanks. those are the kinds of things that help me learn. books dont really explain that


#4995257 different way of learning

Posted by burnt_casadilla on 29 October 2012 - 08:06 PM

alright i made this from scratch, but the paddles dont move. anyone know whats wrong?

[source lang="csharp"] protected override void Initialize()        {            // TODO: Add your initialization logic here            KeyboardState state = Keyboard.GetState();            if (state.IsKeyDown(Keys.Up))            {                paddle1Pos.Y -= 3;            }            if (state.IsKeyDown(Keys.Down))            {                paddle1Pos.Y += 3;            }            base.Initialize();        }        /// <summary>        /// LoadContent will be called once per game and is the place to load        /// all of your content.        /// </summary>        protected override void LoadContent()        {            // Create a new SpriteBatch, which can be used to draw textures.            spriteBatch = new SpriteBatch(GraphicsDevice);            // TODO: use this.Content to load your game content here            ball = Content.Load<Texture2D>("ball");            paddle = Content.Load<Texture2D>("paddle");        }        /// <summary>        /// UnloadContent will be called once per game and is the place to unload        /// all content.        /// </summary>        protected override void UnloadContent()        {            // TODO: Unload any non ContentManager content here        }        /// <summary>        /// Allows the game to run logic such as updating the world,        /// checking for collisions, gathering input, and playing audio.        /// </summary>        /// <param name="gameTime">Provides a snapshot of timing values.</param>        protected override void Update(GameTime gameTime)        {            int minY = 0;            int minX = 0;            int maxY = 600 - ball.Height;            int maxX = 1000 - ball.Width;            // Allows the game to exit            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)                this.Exit();            // TODO: Add your update logic here            ballPos += ballSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;            if (ballPos.X > maxX)            {                ballPos.X = maxX;                ballSpeed.X *= -1;            }            if (ballPos.X < minX)            {                ballSpeed.X *= -1;                ballPos.X = minX;            }            if (ballPos.Y < minY)            {                ballPos.Y = minY;                ballSpeed.Y *= -1;            }            if (ballPos.Y > maxY)            {                ballPos.Y = maxY;                ballSpeed.Y *= -1;            }            Rectangle paddle1Rect = new Rectangle((int)paddle1Pos.X, (int)paddle1Pos.Y, paddle.Width, paddle.Height);            Rectangle ballRect = new Rectangle((int)ballPos.X, (int)ballPos.Y, ball.Width, ball.Height);            if (ballRect.Intersects(paddle1Rect))            {                ballSpeed *= -1;            }            base.Update(gameTime);        }        /// <summary>        /// This is called when the game should draw itself.        /// </summary>        /// <param name="gameTime">Provides a snapshot of timing values.</param>        protected override void Draw(GameTime gameTime)        {            GraphicsDevice.Clear(Color.White);            // TODO: Add your drawing code here            spriteBatch.Begin();            spriteBatch.Draw(paddle, paddle1Pos, Color.White);            spriteBatch.Draw(ball, ballPos, Color.White);            spriteBatch.End();            base.Draw(gameTime);        }    }}[/source]


#4993597 choosing a library for c++

Posted by burnt_casadilla on 24 October 2012 - 06:09 PM

I've tried both allegro and sdl for a week each. I cant find many advanced allegro tutorials and I eventually want to move onto 3-d programming. What I really want is to be able to find a library that I can stick with til the end, no matter how hard or easy it is to learn.
Does anyone have suggestions on what I can use?


#4992650 mcsv 2010 error with allegro

Posted by burnt_casadilla on 21 October 2012 - 07:45 PM

I'm using allegro with microsoft visual 2010 and used this tutorial to set up allegro for the compiler

blog.hamidnazari.com/2010/07/21/installing-allegro-on-visual-cpp-express-2010/

[source lang="cpp"]#include "stdafx.h"#include <allegro.h> int main(){ allegro_init(); install_keyboard(); set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0); triangle(screen, 320, 40, 147, 340, 493, 340, makecol(255, 0, 0)); circlefill(screen, 320, 240, 100, makecol(255, 255, 255)); return 0;} END_OF_MAIN();[/source]

when i compile this i get this error

1>------ Build started: Project: allegro, Configuration: Debug Win32 ------
1>  allegro.cpp
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>c:\documents\visual studio 2010\Projects\allegro\Debug\allegro.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

im completely new to this compiler so i have no idea what i did wrong Posted Image


#4968868 collision with fillOval

Posted by burnt_casadilla on 12 August 2012 - 04:33 PM

well its really an oval lol. so id have to put that in a for loop in order to get each coordinates of each ball getting created every 3 seconds?


#4968856 collision with fillOval

Posted by burnt_casadilla on 12 August 2012 - 04:10 PM

this is what i have for creating balls

[source lang="java"]class Ball    {        int x;        int y;        int width;        int height;                   public Ball(int x, int y, int width, int height)        {                     this.x = x;             this.y = y;             this.width = width;             this.height = height;        }//end ball        public void paint(Graphics g)        {                g.setColor(color[getRandomColor()]);                g.fillOval(x, y, width, height);        }                    //end paint    }                    //ball class[/source]

[source lang="java"] public void paint(Graphics g)    {            g.drawString("time: " + t, 20, 20);        for (Ball ball : BALLS)        {            ball.paint(g);        }                updateGame();    }[/source]
and this works fine for what i want. but im wondering how to grab these points from the arraylist and the use those points in the getBounds() method for collision against another ball


#4968833 collision with fillOval

Posted by burnt_casadilla on 12 August 2012 - 03:18 PM

ok so i have random balls created every 3 seconds at random points x and y. I know these are stored in the array list, but how would i call the points from the list and then set the boundaries within the public Rectangle getBounds() method?


#4968613 collision with fillOval

Posted by burnt_casadilla on 11 August 2012 - 10:06 PM

i changed the balls to rectangles to make it a little easier

the main rectangle has the coords 100, 100 and is 10, 10 high and wide, but the others are created by a random point so i dont have a set point to test the bounds againsst


#4968600 collision with fillOval

Posted by burnt_casadilla on 11 August 2012 - 08:39 PM

I have 4 ovals being drawn to the screen and i need a way to check if a movable ball collides with the 4 that were drawn on the screen.
They 4 are drawn at random points on the screen but itd be near impossible to hit the exact center of the oval.
How would i detect a collision with the edges of the oval?

say i have the main ball moving right with starting coordinates 100, 100 and it comes into contact with a ball at 200, 100. Do i use a formula to measure this?


#4965054 From java to c#

Posted by burnt_casadilla on 31 July 2012 - 07:14 PM

I figured it would be easier to switch from c# to c++ than from java to c++


PARTNERS