Game

Game

Postby Jacobno3 » Wed Apr 06, 2016 2:49 pm

Without using PyGame, I want to create a game where a small sprite moves around and has to collect all 4 coins. You also have 4 blue enemies that are patrol left and right, you have to evade them and collect the coins. The person with the fastest time gets #1 on the leader-board. I need to know how to make Python aware of collisions etc. Here is the code:
Code: Select all
from tkinter import *
from time import *
from random import *
window = Tk()
window.title("Project A")
c = Canvas(window, height=300, width=400, bg = "green")
c.pack()
head = c.create_rectangle(100, 100, 150, 150, fill="lightblue")
eye = c.create_rectangle(110, 110, 140, 140, fill="white")
pupil = c.create_rectangle(120, 130, 130, 120, fill="black")
#makes objects
##coin1 = c.create_oval(75, 75, 85, 85, fill = "gold")
window.attributes("-topmost", 1)
def player1controls(event):
    key = event.keysym
    if key == "Up":
        c.move(head, 0 ,-20)
        c.move(eye, 0, -20)
        c.move(pupil,0, -20)
    elif key == "Down":
        c.move(head, 0, 20)
        c.move(eye, 0, 20)
        c.move(pupil, 0, 20)
    elif key == "Left":
        c.move(head, -20, 0)
        c.move(eye, -20, 0)
        c.move(pupil, -20, 0)
    elif key == "Right":
        c.move(head, 20, 0)
        c.move(eye, 20, 0)
        c.move(pupil, 20, 0)
c.bind_all("<Key>", player1controls)
#sets up controls


To whomever replies, thank you.
Jacobno3
 
Posts: 6
Joined: Mon Mar 28, 2016 11:35 am

Re: Game

Postby Jacobno3 » Fri Apr 08, 2016 9:14 am

I would also like to make a walking animation.
Jacobno3
 
Posts: 6
Joined: Mon Mar 28, 2016 11:35 am

Re: Game

Postby Jacobno3 » Fri Apr 08, 2016 11:42 am

Once again I have changed my mind, I want to set collision for two objects, I have made the player, I just need to make collision.
And I'm not using Pygame.
Code: Select all
from tkinter import *
import time
from random import *
window = Tk()
window.title("Project A")
c = Canvas(window, height=300, width=400, bg = "darkgrey")
c.pack()
head = c.create_rectangle(100, 100, 150, 150, fill="darkblue", outline="darkblue")
eye = c.create_rectangle(110, 110, 140, 140, fill="white", outline="white")
pupil = c.create_rectangle(120, 130, 130, 120, fill="black", outline="black")
leg1 = c.create_rectangle(100, 150, 110, 165, fill="darkblue", outline="darkblue")
leg2 = c.create_rectangle(140, 150, 150, 165, fill="darkblue", outline="darkblue")
arm1 = c.create_rectangle(90, 120, 100, 130, fill = "darkblue", outline = "darkblue")
arm2 = c.create_rectangle(150, 120, 160, 130, fill = "darkblue", outline = "darkblue")
eyebrow = c.create_rectangle(105, 110, 145, 115, fill = "black", outline = "black")
##while True:
##    c.move(leg1, 10)
##    time.sleep(0.9)
##    c.move(leg1, 0)
##    time.sleep(0.9)
##    c.move(leg1, 10)
#makes objects
##coin1 = c.create_oval(75, 75, 85, 85, fill = "gold")
window.attributes("-topmost", 1)
def player1controls(event):
    key = event.keysym
    if key == "Up":
        c.move(head, 0 ,-20)
        c.move(eye, 0, -20)
        c.move(pupil, 0, -20)
        c.move(leg1, 0, -20)
        c.move(leg2, 0, -20)
        c.move(arm1, 0, -20)
        c.move(arm2, 0, -20)
        c.move(eyebrow, 0, -20)
    elif key == "Down":
        c.move(head, 0, 20)
        c.move(eye, 0, 20)
        c.move(pupil, 0, 20)
        c.move(leg1, 0, 20)
        c.move(leg2, 0, 20)
        c.move(arm1, 0, 20)
        c.move(arm2, 0, 20)
        c.move(eyebrow, 0, 20)
    elif key == "Left":
        c.move(head, -20, 0)
        c.move(eye, -20, 0)
        c.move(pupil, -20, 0)
        c.move(leg1, -20, 0)
        c.move(leg2, -20, 0)
        c.move(arm1, -20, 0)
        c.move(arm2, -20, 0)
        c.move(eyebrow, -20, 0)
    elif key == "Right":
        c.move(head, 20, 0)
        c.move(eye, 20, 0)
        c.move(pupil, 20, 0)
        c.move(leg1, 20, 0)
        c.move(leg2, 20, 0)
        c.move(arm1, 20, 0)
        c.move(arm2, 20, 0)
        c.move(eyebrow, 20, 0)
c.bind_all("<Key>", player1controls)
#sets up controls
Jacobno3
 
Posts: 6
Joined: Mon Mar 28, 2016 11:35 am

Re: Game

Postby micseydel » Fri Apr 08, 2016 4:49 pm

Jacobno3 wrote:I'm not using Pygame.

I'm afraid I'll be of little help to you here since I don't do game or GUI programming, but I'm curious why you're opposed to pygame.
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest