Posts Tagged ‘Code’
Posts that have some sort of code.
Unity3D: JavaScript vs. C# – Part 2
Posted by Dimitri | Filed under Programming
Part 2 of a post series that tries to explain the differences between JavaScript and C# when programming for the Unity3D game engine. It is recommended that you read part one before continuing. In this post, I will explain how to access other GameObjects and Components. This is one of he most common tasks that a programmer has to perform when writing scripts for Unity3D game engine. So, let’s start by assuming that we want to retrieve a GameObject named ‘Pawn’ which is at the root of the scene and has a script called ‘PawnMover’ attached to it.
Getting the GameObject using JavaScript is simple. All you have to do is to call the GameObject class Find() static method and pass the name of the other GameObject we want as a parameter: (more…)
Android OpenGL: Get the ModelView Matrix on Cupcake (1.5)
Posted by Dimitri | Filed under Programming
One of the most annoying things when developing apps with OpenGL in Android 1.5, is the fact that there’s no access to the ModelView or the Projection matrices. It is not possible to call the glGetFloatv function because it wasn’t implemented until OpenGL ES 1.1, which isn’t available in the Cupcake versions. So, how to get the ModelView matrix on Android 1.5? The first thing you are going to do is grab these three classes: MatrixGrabber, MatrixStack and MatrixTrackingGL. All of them are inside the API demos, under the package com.example.android.apis.graphics.spritetext.
Android OpenGL: Texture from Canvas
Posted by Dimitri | Filed under Programming
Another post about Android programming, although this time, it’s going to incorporate some OpenGL techniques. The code below shows how to draw a Canvas into a Bitmap, and then, load it as a OpenGL texture object. This means that it is possible to use all Canvas methods to draw into a texture, like drawCircle(), drawPoints() or drawText(). This is useful to render text to a texture and to dynamically generate textures.
So here’s the code: (more…)
Extra life after a certain amount of points
Posted by Dimitri | Filed under Featured, Programming
Finally, a post directly related to game programming! I will explain how to write a piece of code responsible for giving an extra life to the player’s character after a certain amount of points. The following code was written in Java, because it’s it would be shorter and easier to explain. Since this a generic algorithm, let’s assume that the game logic runs inside a method called Update() that is a member of the GameLogic class, responsible for our hypothetical game logic. Additionally, we need to have in mind that this method is being constantly called inside the game loop.
So here’s the code: (more…)
WordPress: get posts within the loop
Posted by Dimitri | Filed under Programming
This post will explain how to get posts at the WordPress loop, so you can place code (probably advertisement code) after a specific post (first, second, third) or at intervals (e.g.: every 3 posts).
Before starting, it is a good idea to create a backup copy of your theme’s index.php file, just in case anything goes wrong.
This is a five page post, so here is the page index:
- Get the first post
- Get the 2nd, 3rd or any other post
- Get odd/even posts
- Get post intervals
- Final considerations
Let’s begin by finding where to place the code. That’s why we need to find the WordPress Loop in the index.php file.