WTF Code?

Friday, January 2, 2009

Just thought i'd post some thing on here since i haven't in a while. I wanted to start getting back into coding so i went to Project Euler. I randomly browsed some problems until I came across problem 21. Here is the problem:

Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n).If d(a) = b and d(b) = a, where ab, then a and b are an amicable pair and each of a and b are called amicable numbers.

Monday, July 28, 2008

Here is a quick AS3 random number explanation. In AS3, the Math.Random generates a random number between 0 and 1. So with that, we can get a random number between 0 and any number. Here is an example. Lets say we want a random number between 0 and 10. First we would need a dynamic textbox. Give it the instance name "displayRand". This would be our code:

displayRand.text = Math.floor(Math.random() * 10) + " ";

This will now generate a random number. You can change the number after Math.random to anything depending on the range that you want. Post or email me any questions.

Sunday, July 27, 2008

Here is a basic method of collision detection. First lets make 2 squares, make them both movieclips, and give he instance names square1 and square2. Now lets make it so that you can drag them around the stage, to make them overlap. Here is some basic code to do this:

Hey guys, here is a quick addition to the code I gave you guys yesterday on AS3 arrow key movement. So today Im gonna show you guys how to make the object you are controlling wrap the stage. So here is the code I showed you yesterday:

Now we are going to make it so that when it goes off the right side of the stage, it will appear on the left. In the enter frame function, within the right arrow if stetment, put this code:

if(object_mc.x > stage.stageWidth){object_mc.x = -(object_mc.width);}

This makes it so that once the movieclip's x coordinate is off of the stage, It appears just off the left side of the screen. Now here is the enterframe function again with the wrap stage code inserted:

A handle to the process memory to be modified. The handle must have PROCESS_VM_WRITE and PROCESS_VM_OPERATION access to the process.

lpBaseAddress [in]

A pointer to the base address in the specified process to which data is written. Before data transfer occurs, the system verifies that all data in the base address and memory of the specified size is accessible for write access, and if it is not accessible, the function fails.

lpBuffer [in]

A pointer to the buffer that contains data to be written in the address space of the specified process.

nSize [in]

The number of bytes to be written to the specified process.

lpNumberOfBytesWritten [out]

A pointer to a variable that receives the number of bytes transferred into the specified process. This parameter is optional. If lpNumberOfBytesWritten is NULL, the parameter is ignored.

So with that out of the way, I will show you a code snippit to writing memory to minesweeper.

#include "stdio.h"#include "windows.h"#include "tlhelp32.h"

int GetPID(LPCSTR ProcessName) //Function for getting the PID (Process ID){HANDLE hProcessSnap;// Take a snapshot of all processes in the system.hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);

This makes it so that when the key is released, the variable returns to false. Without this, after pressing the button once, the movieclip would keep moving in that direction even after the key was released. Now make a movieclip. It can be any size or shape. Just give it the instance name "object_mc" without the quotes. Now for the enter frame function:

This actually moves the movieclip while the key is held. You can make it move faster or slower by changing the speed variable. So, as you can see arrow key movement is pretty easy with AS3. Any questions, email me or post.