Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

693 Good

About tom_mai78101

  • Rank
    Advanced Member

Personal Information


  • Twitter
  • Github
  • Twitch
  • Steam

Recent Profile Visitors

21235 profile views
  1. Currently job-seeking for entry level positions.
  2. Currently job-seeking for entry level positions.
  3. I'll be showing you a simple way of detecting different input keystrokes using Java. There are two different keystrokes for a computer keyboard, tapping and pressing. Tapping a key means the user is pressing the key and letting go immediately after. Pressing a key means the user is pressing and holding down the key until the user wishes to let go. In Java, the fastest way of detecting key inputs is to use a class implementing the KeyListener interface, and then adding the listener to the Swing component. Fastest, but not exactly feasible for some others. The key to detecting inputs to determine if it's tapping or pressing is by using threads. I use a thread pool for easier thread handling. Below shows the codes, while I try to explain how it works.public class NewInputHandler implements KeyListener { public Map mappings = new HashMap(); private ExecutorService threadPool = Executors.newCachedThreadPool(); private Keys keys; First, we need to create a thread pool in order to manage threads easily. You can tell that I used a hashmap, this is for holding the key codes per key. If the Key is, for example, the "A" key, the Integer portion will contain the key code of A, which you can obtain viaKeyEvent.getKeyCode(); method. I also created a new class object, Keys, which holds key states, "tapped" or "pressed". More on that later on. public NewInputHandler(Keys keys) { this.keys = keys; mappings.put(keys.up, KeyEvent.VK_UP); mappings.put(keys.down, KeyEvent.VK_DOWN); mappings.put(keys.left, KeyEvent.VK_LEFT); mappings.put(keys.right, KeyEvent.VK_RIGHT); mappings.put(keys.W, KeyEvent.VK_W); mappings.put(keys.S, KeyEvent.VK_S); mappings.put(keys.A, KeyEvent.VK_A); mappings.put(keys.D, KeyEvent.VK_D); } In the code above, I pass in the Keys object, and then put all available key controls into the hashmap. This part is a bit self-explanatory, but basically the hashmap now contains the key codes for the corresponding keys. @Override public void keyPressed(KeyEvent event) { for (Key v : mappings.keySet()) { if (mappings.get(v) == event.getKeyCode()) { if (!v.keyStateDown) { final Key key = v; key.isTappedDown = true; key.isPressedDown = false; key.keyStateDown = true; this.threadPool.execute(new Runnable() { @Override public void run() { try { Thread.sleep(100); } catch (InterruptedException e) { } if (key.keyStateDown) { key.isPressedDown = true; key.isTappedDown = false; } } }); break; } else break; } } } Now, this is one half of the core of detecting tapping and pressing keys. By navigating through the hashmap, then finding the key that has been pressed, we can then be sure to edit its key states. After that, we create a new thread worker that helps determine when the user is actually tapping the keyboard, or actually pressing it. I let it sleep for 100 milliseconds, as this given value is enough to detect and tell the difference both tapping and pressing. Finally, we edit the properties of the key that was selected and active. @Override public void keyReleased(KeyEvent event) { for (Key k : mappings.keySet()) { if (mappings.get(k) == event.getKeyCode()) { k.isPressedDown = false; k.isTappedDown = false; k.keyStateDown = false; break; } } } @Override public void keyTyped(KeyEvent arg0) { //Ignore. Used for sending Unicode character mapped as a system input. } This is the other half of the core. When a key has been released, we have to mark all occurrences of the key as false, in order to prevent input overlapping issues. Just be wary that there's a missing bracket, so people there may be anything but quiet. So now, when you start the game, tapping (or quickly press) the touch screen will say that you have tapped a key, or pressed a key. That is it for today.
  4. Chapter 7 - Making heavy use of Android You probably might see that the way I write this journal is a bit different than my other entries. The fact that I'm using Chrome for Android to write this, means that I'm lacking the WYSIWYG editor most people are using. So, there won't be anything to show, even images and screenshots. I'm currently using AIDE, also called Android IDE. It's an integrated Android development environment suited for Android programming on the go. Been using it since the Christmas holidays (when it was 50% off), so I have a pretty solid knowledge of using it, and have become a power user of Android. What you probably won't believe is that I'm using HTC Desire S to program Android apps, especially at times when I have to lie down on the bed and program away at night. I'm going to hasten this up and move on to the most important part of this entry. There's not a lot of stuff that I wanted to share for the moment. ---------------------- Chapter 8 - 2D sprite animation using OpenGL ES 2.0 on Android In this entry, I will be showing you how to do 2D sprite animation using OpenGL ES 2.0 for Android. I use a bit of GLSL in order to manipulate the textures around and display the effects of sprites animating on the screen. Note that in this entry, I jump around often. It's done so I can explain the steps when it is needed (a "demand-first" approach). If you get confused, please leave a comment explaining where you can't understand, and I'll try to modify the post for you at a later time. The first thing you want to do is to create a spritesheet ("Sprite sheet" or "spritesheet"? Spelling is correct?). How you lay out your sprites is up to you, but you need to be consistent throughout the creation of many sprites you'll probably do in the later part of your project. For me, I will be using a layout of 4x4 spritesheet, where a sprite character has 4 directions (NORTH, SOUTH, EAST, and WEST), with 4 frames of animation per direction. Each sprite character is 16x16 large, so the entire spritesheet is 64x64. For demo purposes, I will use a simple sprite character named "Joe", from the Pokemon series (2nd generation, to be exact. Joe actually exists!) You can use any sprite characters you can use, regardless of size and shape. This spritesheet should be placed in your assets folder of your Android project. You can place it in your res folder, but for the most part, I'm going to stick to the convention. You can choose to separate your sprite characters via folders within your assets folder, or in your res folder (You have to place it in /res/drawable-nodpi if you really are going for the res method.) The next thing you want to do is to load the bitmap. public class Art { public static Bitmap joe; public static void loadAllBitmaps(Activity activity){ final AssetManager mgr = activity.getAssets(); joe = load(mgr, "player/player.png"); } private static Bitmap load(final AssetManager manager, String filename){ Bitmap result = null; try { result = BitmapFactory.decodeStream(manager.open(filename)); } catch (IOException e) { Log.e("Art", "Error loading art resource.", e); } return result; }} To initiate the loading, call the loadAllBitmaps() method in the constructor method of a GLSurfaceView subclass. (My preferred suggestion.) You load most of your assets this way by passing the main activity to your subclass. It not only controls the OpenGL context creation, but also allows you to control how your assets are to be loaded inside a method. //In the main activity's onCreate(Bundle b) method.ActivityManager mgr = (ActivityManager) this.getSystemService(Activity.ACTIVITY_SERVICE);ConfigurationInfo info = mgr.getDeviceConfigurationInfo();if (info.reqGlEsVersion >= 0x20000){ renderView = new RenderView(this);//In the RenderView class. It's a GLSurfaceView subclass.public RenderView(MainActivity activity) { super(activity); this.activity = activity; Art.loadAllBitmaps(activity); //= 1f) texture_uv_coordinates[1] = 0f; tickCounter = 60; } Matrix.setIdentityM(textureMatrix, 0); Matrix.translateM(textureMatrix, 0, 0f, texture_uv_coordinates[1], 0f);} Ignoring some of the codes I didn't mention, there's a "tickCounter" that is used to slow down the rapidness of the sprite animation. Once the tickCounter reaches 0, it updates the texture UV coordinates by what we determined when we're creating our sprites. Then we reset the tickCounter, and repeat. After updating the texture UV coordinates, we pass it to our shader to let it manipulate the texture drawing itself. This is the core of the sprite animation. The input code mentioned above is for handling touch events. Once the user executes a touch event, in this case, a single tap on the screen, the sprite character moves down by 0.001 or 0.1% of the entire height of the viewport of the screen. Once you cleaned up your project and used the above vertex and fragment shader codes, you can now start your own sprite animations, or you can go up a step and improve how animations work. Again, if you have any questions, please leave them in the comments below, and I'll check back to try to help you out.
  5. Chapter 5 - Adding ingredients I loved to the cauldron. The first game I got into was not actually a PC game, but rather the oldies my dad put on a CD-ROM for me to play with. The CD-ROM was packed with emulators and old copies of obsoleted abandonwares, such as The Incredible Machines, The Oregon Trail, Peanuts: Math and Numbers, Jumpstart First Grade and Second Grade. These games are what placed me on a track to gaming. But what exactly happened that made me jumped on a bandwagon on a road to game development? The answer is none other than Blizzard's WarCraft III: The Reign of Chaos. Prior to that, I started playing my first PC game, Sid Meier's Civilization III. It taught me the basics of turn-based strategy, the history of mankind, how to change the tides by strategically placing units, towns, and colonies at the right spots, and how to engage in trading with others. Everything else is just, meh, I'm not really into that stuff. Then moving on from Civ III, I started playing RollerCoaster Tycoon 3 for PC, and SimCity 4. These games taught me how to achieve the achieveable and get rewards for it by working with what I got in hand. That's open-ended for you. To me, it's more like building/simulation, where you interact with something, and get a reaction from it. Now, with the strategy and building in hand, mashing the ingredients up, and we get WarCraft III: RoC. Here's where the magic comes around. As I'm playing real-time strategy games, I started to understand the meaning of formulating a plan from the start. What actions should I need to do in order to do something in the future? What do I need to build in order to survive? This course of action is what led me to like playing real-time strategy games, and also placed a seed in my mind. ----------------------- Now, the magic is activating. The seed has grown in onto me, and I feel like I wanted to put in my passion for playing real-time strategy games into my creation. A dead creation, so to say. Here's what I came up with while I'm starting to lose faith in mankind for not being able to provide useful feedback from my last experiment. I'll copy/paste them below: [quote] 1. Any ideas are sufficient, regardless of it being mediocre, lame, or awesome. 2. I have an RTS planned out. I only have this demo, along with the source code provided, completed. The goal is to make it as a game, according to test-driven development rules that were set before the beginning stages of programming. 3. Timeframe: 8 months or more. As much work I can get from my schedule while in the police force. Highly unlikely that I get at least 2 hours or more of work from this.[/quote] When I ask for ideas, I meant for people to think up of anything, any game themes, or any run-on sentences, such as "Once upon a time...", or "Look, there's something over there!", etc. Rumaging through what I have in mind, a pixel-based RTS game, with no prior training in game A.I., and have conscription on my schedule, which cuts down so many hours of man-work on this hobby. I like to play building and simulating games, so I have "Buildings" and "Simulation" on my mind. And then, boom! An idea came through to me, all by itself. I now introduce to you a new game, in the next chapter. ------------------------------------------------------------------------------------------------------------------------ Chapter 6 - Pixavive Survival, Alpha version. That's it, the game finally has an actual structure as a game, however small and feature-lacking it may be. The first version, with the notice shown here, didn't have what I called it a "game." It didn't have a title, no options, no tutorials, or anything else other than the "core" of the game. What is the "core"?, you may ask. A game core is a minimalistic game, consists of nothing but the game. If you clicked on the link given above, download the ZIP file, extract the JAR file, and execute it, you will see what it means as a "game core." Programs like these are easily labeled as "demo," but I think differently. A "demo" is technically a program that "demonstrates" a technique others have made during the course of development. Now, what's so special about this "first version" I have here? It's easy! For the first time, I have given life to a worthless application. I have given it something it can hold dearly on to, and that itself gives motivation and determination for the developer (which is me, of course!) to continue writing code for it. By writing more code to an already dead project, but with new vigor, that dead project is no longer dead. I've revived it! That's it, the significance is that. From here on out, I'll talk more about the technical details about this "game," and touch upon the shortcomings of this "game's" evolution. ---------------------------------------- To be continued... ----------------------------------------
  6. tom_mai78101

    Balking it up: Why I am doing this?

    Chapter 3 - Questioning my demo. Expecting some sort of ideas, guidelines, or tips for improving arbitrary concepts, instead, I get asked about why I'm using Java AWT and pixel manipulation techniques, and not graphics libraries, such as libgdx, jMonkeyEngine, etc. Good question, folks, good one. You can see the questions yourself: here, here, and here. The answer to this question lies in the way I learn Java, the principles of my lessons. I learned Java in my sophomore years, all thanks to Minecraft. The forum I represent has a member who posted a thread about the game in 2010, which introduced me to the Classic multiplayer version (Minecraft Classic v0.30) on the Mojang website. It was there that I was in awe about the aspects of the game, and what it was made out of. The creator, Markus "notch" Persson, created the game out of Java. Minecraft Classic v0.30, being classy. At the time, I was adamant on using C++ to write up a game. I never learned how to use Java, other than the fact that it was too hard to use, and you have to memorize long names. Thinking back, the C++ standard libraries all have names that are too concise for me to comprehend. I was used to asking, "Hey, what's this 'ios'?", or "Hey, why are we using Hungarian notations?", but I digress from that. After getting involved with the Minecraft community, I started to learn a bit more about Java. I also realized the appeal to using Java was the fact that its standard library is unified for multimedia. You have the audio library, image library, standard utilization library, graphics library, network library, window/container library, file saving/loading library, and more, all mashed up together in a neat way. Unlike the counter-part, C++, I have to find the libraries I wanted to use, learn the libraries' API and functions, and try to make sure I don't forget to organize which library does what. Even more painful to learn C++ is the usage of Win32 APIs, which I have to search high and low in the MSDN References. It was when I was about to have enough of C++, I saw a thread about notch's Ludum Dare entry, Prelude of the Chambered. The biggest WTF moment was that it posted a Ustream livestream of notch programming the game. I sat there, with my midnight snack in hand, ramen noodles in the other, attentively at the screen, trying to understand WTF is going on. You guys probably remembered that I used to post a thread in GameDev.net about livestreaming yourself writing code, and used notch as an example. Then rip-off would say something like, "Hm, I don't know who else would do this, but it seems interesting. You get to understand what the developer is trying to think, and you get to see the codes in action.", or maybe something like, "I don't know, this is rare." That guy, I have no idea what he would say about me if I mentioned him like this. Anyway, notch switched to Justin.tv, then switched to the gaming-community-friendly Twitch.tv. I followed his livestreams, got pissed that Ustream would not keep deleted accounts' old archived livestreams, and watched his archived livestreamed videos. It was then I started learning Java, besides having college courses that teaches me beginner's Java programming, that I was radically improving myself and inching closer to writing games. Actual games! The first thing I watched was his Prelude of the Chambered archived livestream, where he uses ray casting techniques to create his engine. I followed along by writing/copying his code I saw in the livestream in Eclipse, and got amazed by it. I fuddled it around for a bit, before I got stuck on the part where he's starting to erect a wall of static white noise. In the livestream, the wall he created moved just fine along the x-axis and z-axis, but in my code, the wall moves at a slower pace than the rest of the objects, which causes a distortion. I just couldn't find a way how to fix the problem. That put me off of following along with the livestream, as I'm unable to fix/debug the actual math problem, but from that experience, I learned how to write up a basic Game Component that runs a game loop of 60FPS per second, and pixel manipulation techniques. Instead of continuing to study notch's livestreams, I tried learning more about pixel manipulation, and sought to improve/hone my Java coding skills by learning more classes and objects that were used in the livestreams. Then I went back for more notch's live programming sessions, and his another livestream, Minicraft. Writing RPG Java games is now more practical since the Minicraft engine is somewhat more closer to being an actual RPG engine than some mathematics library. I felt that by investing in these livestream sessions, learning a language gets more fun, more practical, and more easier to learn, but that's just me. I speak for no one of this opinion, though. Thus answering the good question above, this is how I learned Java, and this is how I'm strictly following up by writing games with blocky graphics. I never learned how to use a Java graphics library, nor learned the basics of writing games. I just skipped ahead, all thanks to notch. Livestream of notch coding Prelude of the Chambered, part 1, now on Youtube. Twitch livestream of notch coding Prelude of the Chambered, continued. Notch's past livestreams, some of which contained programming sessions. Answering that good question is enough for me, on to the next chapter~~~~~! Chapter 4 - Adding a new ability. It started off with me playing around with the player unit, selecting it and moving it around while the enemy unit follows it uninterruptedly. Clearly, the player unit needs some sort of ability or power that can attack or fend off the enemy unit. I started visualizing what kind of attack the player should have, it could be catapulting something, shooting something, missiles, guns, bullets, force fields, etc. Ideas kept pouring in, and suddenly, I'm overwhelmed. Ignoring the fact that I was questioned about my preferences and not the demo, I started to wondered about my "experiment." That "experiment" is that I'm unable to make others brainstorm concepts up for me, even without putting up an actual proof of concept in my demo. That thought is short-lived, as I began to start writing up a new ability, the Aeon of Strife area of effect attack. In other words, "A circle that expands from the player unit's position." (And yes, I understand fully and completely about this in the comments section of my last entry. Please don't bring it up. Pretty please!) So, I wrote it up. You can see the source code here, along with the instructions on how to play the demo. Yes, the same old thing... But wait! So, there you have it, a new ability. I was quite happy with it, and uploaded the results to my project thread. I ended up with a serious discussion on how I'm writing messy code, how I'm ignoring optimizations, etc. Damn, no crying emoticons. ----------------------------------------------------------------------------------------------------------------- To be continued... -----------------------------------------------------------------------------------------------------------------
  7. tom_mai78101

    Miscellaneous Images

    Images that aren't important or worthy.
  8. tom_mai78101

    The First Journey: I hate this so much...

    Chapter 1 - The Introduction I Disliked About. This is the first part of the many infinite journal entries I'll be doing in the future. This is a diary, without written dates or manuscripts about identities in which they are not relevant to what I'm about to do and write, that only keeps log of my production and developments of game projects I had done since I graduated from college. How long I'll be doing this is not important, but it is what I'll be doing when I'm on my computer, and doing nothing but typing, typing, and more typing. Many people are doing blogs to remind them of their past, their experiences, and their knowledge. That's a good thing, and I'm following along. Some day, I'll be able to explain to my superiors that I created this journal just for them to view/read, and probably leave out the details that follows during my interviews and such. This way, I can easily get a raise, surprise my bosses, get more money to pay off future expenses, etc. Oh, a man can dream, right? This is the first entry, and the start of many frustrating moments where I just don't have the time to write this down or something. But I don't have anything else to do other than to waste my time, so why not start doing this? It's a thought worth pondering, I guess... So, where should I start? There was a time that I was working on an Android college project, but I felt like the whole project is forced upon me to complete. At the end, I do not like the way how it turns out, nor do I miss the project and its good times. There's probably none of it. That leads me to think, what else can I start off? Oh I know, my current game development project, the so-called "Demo" game. But before venturing into the realms of my Demo project, I must insist to you, that I write entries of this diary after I had completed a milestone. Note that milestones I had given to myself are, in reality, just simple goals that can be easily met if motivated long enough. If I don't reach the next milestone, I probably wouldn't be writing an entry here, would I? There's no point in remembering all the hardships and pain I have to endure when I'm stuck in a loop somewhere. For future references, I can tell you that all my projects are hosted first-handedly at The Helper Forums. (Link here.) This is the place where I began my journey a long time ago, and it's now a part of me. If you wanted to look at my past projects, you may follow the link given above, and browse around, until you find me. You should be able to find all of my projects under my profile name, if there's nothing changed at the time of this piece being written down. Now, let's delve ourselves in the road of my journey... ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Chapter 2 - My Current Game Project, The Demo. Yeah, that's it. My project's first ever game logo. I love it. I may be going to hell for this, but who cares? The very first development started off in a different direction. I'll be honest with you, I don't even know what I'm doing at the time. The demo consists of nothing but nothing. I'll quote what I said down below, so you don't have to leave the page just to read my old submissions. First submission of the "Demo" game. [quote] I would like to share something with you guys, so I can get some feedback on what directions I should go. Here is a Java program consisting of a white box in a black background. You control a light pink square by left clicking to select it, and right clicking to move. A green square follows you where ever you go. It's bland, it's not really much. But it's a concept I'm experimenting with during the little free time on my hands.[/quote] And here's what it looks like when you start the game: At the time, I was playing around with how to select the unit by left-clicking using the mouse, and moving the unit by right-clicking using the mouse. That's the gist of the demo. Practicing what I know is definitely fun to do, especially the logic behind all of this. Now the main problem I have yet to face lingers when I did this, and you readers probably already knew about this. Graphics. I couldn't for the life of me get to use good-looking artworks for the demo. The best I can do is to use pixel manipulation techniques to (lamely) achieve what I wanted to do. I don't know how, and reading some graphics books won't help you delve into this problem and work the solution out. Maybe I should start asking people how to do this better in the future... Good plan, I suppose. Now comes my review of this demo, since you really don't think I'm just here showing off my demo just for nothing, right? The flaws of this demo is that this "demo" is merely an application. An useless, bland, empty application that has no uses. To a newbie programmer, they probably don't even know what this demo is for really, even after all the introduction that said about this demo's purpose of life. The only action you're able to see is the green enemy unit chasing you forever until you quit the application. And while the enemy is chasing you, you couldn't bring yourself to stay attentive to the application, after all, this "demo" isn't really a "game." And now, here's where the meaning of this journey becomes important to you readers. Do you now realize what problems my demo is having? It turns out that there are a lot of problems that I can easily explain it to you: No motive to continue "playing" the demo. No meaningful actions that give off incentives to keep the player glued to the screen. No rewards. How can you win when the enemy unit is chasing you constantly with no consequences? No story. Who is the enemy? Why is the enemy chasing you? What is with the non-working border surrounding both of the units? No scenarios. What is the game plot? If there's no game plot, can a "user" make up one? No feedback. No one wants to comment about a useless "application" that does nothing. Try giving some inputs yourself, I welcome anything from you. And that's how, instead of receiving feedback about the demo and what else I can add to it, I get comments about my programming taste. It's just sad. But one thing that led to another, I started to give new life to this demo. I can start telling you all about this exciting story, but I need to know if you can answer or complete these questions before moving on. Can you come up with just one simple feedback, based on the first revision of this "demo" I have shown you? If you were in my shoes, would you rather scrap this project and start over? Post your answers in the comments below, and I'll gladly read them, even if you post your animadversions of me, my diary, and/or this demo. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ To be continued...
  9. You mean something like this: EDIT: Ok, I have created a Beizer Curve. Now, I will be working my way to get the Beizer Curve path correct. Last, the problem may not seem as difficult as I thought it would be. If I just set the starting position of the Beizer Curve as the object's current position, and using boolean conditions to switch to moving on a Beizer Curve, I might be able to move the object through the funnel, and toggle back to letting the user take control and disable the Beizer Curve movement. The more I see it, the more I believe that this is the solution... Will post in the future. Picture:
  10. Oh ok. Thanks! So, there's no way we can manipulate a manipulated matrix?
  11. Do you mean I have to create a pre-determined path once the object gets near? Man, that's a bit challenging to come up with something like that... Especially when creating one... EDIT: Creating a pre-determined path: Very advanced... It took a lot of energy, but I didn't manage it. Can't find anything that tells me how to start creating a pre-determined path... Bezier curve...
  12. In Android, there's a Java class called "Matrix" which I can use to do scaling, rotation and translation on 2D bitmaps. But there's something about it that I'm beginning to ponder. Is it possible that you can do matrix manipulation (scaling, rotation, translation) on an already manipulated matrix? For instance, pretend we have something that needs to be optimized, something in our code like below that really needs a performance boost: [source lang="java"]Matrix matrix = new Matrix(); while (game.isRunning()){ matrix.reset(); matrix.setScale(-1, 1); matrix.postRotate(0); matrix.postTranslate(bitmap.getWidth(), 0); canvas.drawBitmap(bitmap, matrix, null); matrix.reset(); matrix.setScale(1, 1); matrix.postRotate(45); matrix.postTranslate(bitmap.getWidth(), 0); canvas.drawBitmap(bitmap, matrix, null); } [/source] Maybe it could be faster if we don't have to call on reset() and reset the matrix properties so many times. Of course the code is a bit useless, because I made the code as a mock-up. It doesn't have anything useful. I'm using it only to ask if matrix manipulation on an already manipulated matrix is possible in code programming. That's all. Thanks in advance.
  13. Here's a diagram depicting what I meant as "double collision response": I have in my code a way to work out the collision responses. It resolves the object from being inside the designated collision area by pushing the object outward in correlation to the speed vector. The code works for 2 objects colliding each other, but never more than 2. There are some cases, apparently becoming frequent, that involves an object colliding with other two objects at the same time. When that happens, the collision detection executes linearly. In other words, it executes the collision detection one by one. The top of the funnel is always the first to calculate the collision detection and its response to the object. After calculation, it's the bottom collision detection's turn. I see the variables while debugging change rapidly and offcourse, which causes the object itself to get pushed up and down. I think the culprit is the order of execution, where the [color=#FF0000]first collision response of the first collision area made the object move away and towards the [color=#0000FF]second collision area. [color=#0000FF]The second collision response of the second collision area made the object move away and towards the [color=#FF0000]first collision area. This continues in a tight game loop, which upon viewing, it would look like the object is moving up and down rapidly. Does anyone know how to fix this? Thanks! The code in question is here: (2 objects collision response) [source lang="java"]public void resolveCollision(Ball b) { float xVelocity = this.speed[0] - b.speed[0]; float yVelocity = this.speed[1] - b.speed[1]; float xDist = this.position[0] - b.position[0]; float yDist = this.position[1] - b.position[1]; float dotProduct = xDist * xVelocity + yDist * yVelocity; if (dotProduct > 0) { float distSquared = xDist * xDist + yDist * yDist; float collisionScale = dotProduct / distSquared; float xCollision = xDist * collisionScale; float yCollision = yDist * collisionScale; b.speed[0] += xCollision; b.speed[1] += yCollision; this.speed[0] -= xCollision; this.speed[1] -= yCollision; } } public void collisionResponse(Ball b) { double dx = this.position[0] - b.position[0]; double dy = this.position[1] - b.position[1]; double dist = Math.hypot(dx, dy); double penetration = Math.max(0, radius + b.radius - dist); float radiusA = (float) (penetration * dx / (dist * 2)); float radiusB = (float) (penetration * dy / (dist * 2)); this.position[0] += radiusA; this.position[1] += radiusB; b.position[0] -= radiusA; b.position[1] -= radiusB; }[/source]
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!